来源不明的递归:TeX 容量超出,抱歉

来源不明的递归:TeX 容量超出,抱歉

由于某种原因,此 MWE 中存在递归定义。谁能找出问题所在?

\documentclass{article}

\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{tcolorbox}
\usepackage{refcount}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{titletoc}
\usepackage{tikzpagenodes}
\newcounter{chapmark}
\newcommand\StartMark{%
\addtocontents{toc}{\protect\label{st\thechapmark}%
\par\protect\begin{tikzpicture}[overlay,remember picture,baseline]   
  \protect\node [anchor=base] (s\thechapmark) {};%
  \ifnum\getpagerefnumber{st\thechapmark}=\getpagerefnumber{en\thechapmark}   
  \else
    \protect\draw[mycolor,line width=3pt] 
      let \protect\p3= (s\thechapmark),%
            \protect\p4 = (current page text area.south) in %
      ( $ (0em,\protect\y3) + (-20pt,-5ex) $ ) -- 
      ( $ (0em,\protect\y4) + (-20pt,5pt) $ );
  \fi
\protect\end{tikzpicture}\par}%
}
\newcommand\EndMark{%
\addtocontents{toc}{\protect\label{en\thechapmark}%
\par\protect\begin{tikzpicture}[overlay,remember picture,baseline]   
  \protect\node [anchor=base] (e\thechapmark) {};
  \ifnum\getpagerefnumber{st\thechapmark}=\getpagerefnumber{en\thechapmark} 
    \protect\draw[mycolor,line width=3pt] 
    let \protect\p1= (s\thechapmark), 
          \protect\p2=(e\thechapmark) in %
    ( $ (0em,\protect\y1) + (-20pt,-5ex) $ ) -- 
    ( $ (0em,\protect\y2) + (-20pt,2ex) $ );
  \else%
  \protect\draw[mycolor,line width=3pt] 
  let \protect\p1= (e\thechapmark), 
        \protect\p2=(current page text area.north) in 
  ( $ (0em,\protect\y2) + (-20pt,5pt) $ ) -- 
  ( $ (0em,\protect\y1) + (-20pt,2ex) $ );
  \fi
\protect\end{tikzpicture}\par}%
\stepcounter{chapmark}%
}
\definecolor{mycolor}{RGB}{123,123,123}
\begin{document}
\tableofcontents
\StartMark
\begin{flushleft}% comment out these lines to compile
\begin{tcolorbox}[hbox]

\end{tcolorbox}
\end{flushleft}% comment out these lines to compile
\EndMark

\end{document}

答案1

您可以简单地保护。如果我在的\par定义中的两个地方都这样做,错误就会消失:\EndMark

\addtocontents{toc}{\protect\label{en\thechapmark}%
\protect\par\protect\begin{tikzpicture}[overlay,remember picture,baseline]   
  \protect\node [anchor=base] (e\thechapmark) {};
  \ifnum\getpagerefnumber{st\thechapmark}=\getpagerefnumber{en\thechapmark} 
    \protect\draw[mycolor,line width=3pt] 
    let \protect\p1= (s\thechapmark), 
          \protect\p2=(e\thechapmark) in %
    ( $ (0em,\protect\y1) + (-20pt,-5ex) $ ) -- 
    ( $ (0em,\protect\y2) + (-20pt,2ex) $ );
  \else%
  \protect\draw[mycolor,line width=3pt] 
  let \protect\p1= (e\thechapmark), 
        \protect\p2=(current page text area.north) in 
  ( $ (0em,\protect\y2) + (-20pt,5pt) $ ) -- 
  ( $ (0em,\protect\y1) + (-20pt,2ex) $ );
  \fi
\protect\end{tikzpicture}\protect\par}%
\stepcounter{chapmark}%
}

相关内容