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




















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