
다음과 같은 최소한의 예를 고려하십시오.
\documentclass{article}
\tracingrestores=1
\def\foo{\bar\foobar}
\def\bar{\gdef\testA{blabb}}
\def\foobar{\expandafter\gdef\csname testB\endcsname{blubb}}
\begin{document}
{\foo}
\testA
\testB
\end{document}
결과 로그 파일에는 항목이 포함되어 있지만 {retaining \testB=macro:->blubb}
에 해당하는 항목은 없습니다 \testA
. 내가 TeX을 이해하는 한, 이는 \csname...\endcsname
매크로를 로컬로 정의하고 \testA
" \relax
blubb"으로 전역적으로 재할당한 직후에 내 save_stack에 유지 항목을 추가한다는 의미입니다.
실제 응용 프로그램에서는 csname-construction을 사용하여 개별적으로 명명된 매크로를 잠재적으로 무한하게 정의할 수 있어야 하는데 이로 인해 스택 오버플로가 발생합니다. (글쎄, 아마도 무한하지는 않지만 확실히 80000보다 더 많을 것입니다…)
\csname…\endcsname
지금 내 질문은: -construct가 저장 스택에 쌓이는 것을 방지하기 위해 전역적으로 초기화하는 방법이 있습니까 ? 아니면 저장 스택을 깨끗하게 유지하는 일종의 해결 방법이 있습니까?
답변1
할당을 전역으로 만드는 대신 \csname
더욱 지역적으로 만들 수 있습니다.
\documentclass{article}
\tracingrestores=1
\def\foo{\bar\foobar}
\def\bar{\gdef\testA{blabb}}
\def\foobar{\begingroup\expandafter\endgroup\expandafter\gdef\csname testB\endcsname{blubb}}
\begin{document}
{\foo}
\testA
\testB
\end{document}
이제 \expandafter
그룹에서 실행되므로 시작하기 전에 끝나는 그룹에 정의 \csname
됩니다 . 따라서 유지 항목을 피해야 하는 전역 정의가 발생할 때 정의되지 않습니다.\testB
\relax
\gdef
\testB
답변2
나는 (La)TeX 스택(LOL 제외)에 대해 쪼그리고 앉는 것을 모르지만 목표가 내부를 stackengine
피하는 것이라면 ...\csname
\def
\csname
외부를 실행하기 전에 확장하십시오 \def
.
\documentclass{article}
\tracingrestores=1
\def\foo{\bar\foobar}
\def\bar{\gdef\testA{blabb}}
\expandafter\def\expandafter\foobar\expandafter{\expandafter\gdef\csname testB\endcsname{blubb}}
\begin{document}
{\foo}
\testA
\testB
\end{document}