출처를 알 수 없는 재귀: 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}%
}

관련 정보