我在本论坛下载了这个高中数学讲义模板:
https://www.latexstudio.net/index/details/index/mid/4699.html
改字体后一切编译正常,但是,我加了一句 \tableofcontents 想要生成讲义目录,就会报错:
presentation.tex: 错误: 8: TeX capacity exceeded, sorry [input stack size=10000]. \tableofcontents. 问了模板作者,目前还没有答复,
相请教一下其他大佬有没有人下载后成功生成了目录,怎么样才能生成目录?
以下的分析来自 codex-5.5-xhigh:
原因是book.cls的\tableofcontents把\@mkboth放进了\chapter*{...}标题参数里;你的\titleformat又把该标题交给\myroundedbox',其中xstring' 的\StrLeft/\StrGobbleLeft会拆解整个 token list,触发\@mkboth递归,最终报TeX capacity exceeded [input stack size=10000]。
我已采用最佳修正:重定义\tableofcontents,把\@mkboth移到\chapter*{\contentsname}之后执行。这样目录标题装饰宏只处理可见文字“目录”,不再处理页眉标记命令。
\documentclass[fontset=fandol]{ctexbook}
\RequirePackage{titlesec}
\RequirePackage{fancyhdr}
\RequirePackage{xstring}
\RequirePackage{tikz}
\newcommand{\myroundedbox}[1]{%
\begin{tikzpicture}[baseline=(mbox.base), overlay, remember picture]
\StrLeft{#1}{1}[\firstchar]
\StrGobbleLeft{#1}{1}[\restchars]
\node[anchor=west,draw=cyan,line width=2pt,fill=white,inner xsep=3pt,inner ysep=3pt,font=\bfseries] (mbox) {\firstchar\hskip 0.3em\restchars};
\end{tikzpicture}%
}
\titleformat{\chapter}[display]
{%
\sffamily%
\thispagestyle{empty}
}
{}
{-1.1em}
{\myroundedbox}
\titlespacing{\chapter}{0pt}{-1.5\baselineskip}{0\baselineskip}
% book.cls puts \@mkboth inside the TOC chapter title; keep it outside
% because \myroundedbox uses xstring to split only visible title text.
\makeatletter
\renewcommand\tableofcontents{%
\if@twocolumn
\@restonecoltrue\onecolumn
\else
\@restonecolfalse
\fi
\chapter*{\contentsname}%
\@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}%
\@starttoc{toc}%
\if@restonecol\twocolumn\fi
}
\makeatother
\begin{document}
\tableofcontents %
\chapter{课节导引}
\section{引导点公式速记速记}
\end{document}如上的 patch 可以似乎可以解决问题...

该问题的一个简化版本等价于:
\documentclass[fontset=fandol]{ctexbook}
\RequirePackage{titlesec}
\RequirePackage{fancyhdr}
\RequirePackage{xstring}
\RequirePackage{tikz}
\newcommand{\myroundedbox}[1]{%
\begin{tikzpicture}[baseline=(mbox.base), overlay, remember picture]
\StrLeft{#1}{1}[\firstchar]
\StrGobbleLeft{#1}{1}[\restchars]
\node[anchor=west,draw=cyan,line width=2pt,fill=white,inner xsep=3pt,inner ysep=3pt,font=\bfseries] (mbox) {\firstchar\hskip 0.3em\restchars};
\end{tikzpicture}%
}
\titleformat{\chapter}[display]
{%
\sffamily%
\thispagestyle{empty}
}
{}
{-1.1em}
{\myroundedbox}
\titlespacing{\chapter}{0pt}{-1.5\baselineskip}{0\baselineskip}
\begin{document}
% \tableofcontents %
\chapter{课节导引}
\section{引导点公式速记速记}
\end{document}如果加上\tableofcontents,将导致如下报错:
! TeX capacity exceeded, sorry [input stack size=10000].
\@mkboth ...rotect \ttl@gmk {\protect \@mkboth {#1
}{#2}}
l.25 \tableofcontents另外,对于这种站内的链接,不建议不贴文件。否则这隐含着让其他人都要付费下载一次。
能否请 @u122987 关注一下。
谢谢大佬的帮助,现在已经生成目录了