在论坛下载了一个模板,生成不了目录

发布于 2026-04-29 09:25:00

我在本论坛下载了这个高中数学讲义模板:

https://www.latexstudio.net/index/details/index/mid/4699.html

改字体后一切编译正常,但是,我加了一句 \tableofcontents 想要生成讲义目录,就会报错:

presentation.tex: 错误: 8: TeX capacity exceeded, sorry [input stack size=10000]. \tableofcontents. 

问了模板作者,目前还没有答复,

相请教一下其他大佬有没有人下载后成功生成了目录,怎么样才能生成目录?

查看更多

关注者
0
被浏览
92
Sagittarius Rover
Sagittarius Rover 19小时前
这家伙很懒,什么也没写!

以下的分析来自 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 可以似乎可以解决问题...

image.png

3 个回答
Sagittarius Rover
Sagittarius Rover 20小时前
这家伙很懒,什么也没写!

Claim:这不是一个回答,只是必要的简化。

该问题的一个简化版本等价于:

\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 关注一下。

Balance
Balance 18小时前
这家伙很懒,什么也没写!

这页眉怪好看的。

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览