dtx 프리앰블의 위험한 \if@

dtx 프리앰블의 위험한 \if@

.dtx다음 파일은 컴파일되지 않는데 해당 파일은 컴파일되는 이유는 무엇입니까 .tex? (파일 이름을 로 지정해야 합니다 . error.dtx여기에 \DocInput포함됩니다.)

DTX:

% \iffalse meta-comment
%<*driver>
\documentclass{ltxdoc}
\input pgfutil-common
\makeatletter
\def\myitem#1{%
  \pgfutil@in@{,}{#1}%
  \ifpgfutil@in@
    \myitem@#1\@end
  \else
    \myitem@#1,\@end
  \fi
}
\def\myitem@#1,#2\@end{\item\texttt{#1}\quad\marginpar{\small\it#2}}
\makeatother
\begin{document}
  \DocInput{error.dtx}
\end{document}
%</driver>
% \fi
% \begin{description}
%   \myitem{align,key} This is documentation for key \emph{align}.
% \end{description}
% \endinput

유액:

\documentclass{ltxdoc}
\input pgfutil-common
\makeatletter
\def\myitem#1{%
  \pgfutil@in@{,}{#1}%
  \ifpgfutil@in@
    \myitem@#1\@end
  \else
    \myitem@#1,\@end
  \fi
}
\def\myitem@#1,#2\@end{\item\texttt{#1}\quad\marginpar{\small\it#2}}
\makeatother
\begin{document}
  \begin{description}
    \myitem{align,key} This is documentation for key \emph{align}.
  \end{description}
\end{document}

답변1

이에 따른 진단은 \else정확하다. 이를 해결하는 또 다른 방법은 Docstrip '문서' 부분에 새 코드를 넣는 것입니다. 그렇게 하려면 정의의 주석 문자를 다음으로 변환해야 합니다.^^A

% \iffalse meta-comment
%<*driver>
\documentclass{ltxdoc}
\input pgfutil-common %
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%\makeatletter
%\def\myitem#1{^^A
%  \pgfutil@in@{,}{#1}^^A
%  \ifpgfutil@in@
%    \myitem@#1\@end
%  \else
%    \myitem@#1,\@end
%  \fi
%}
%\def\myitem@#1,#2\@end{\item\texttt{#1}\quad\marginpar{\small\it#2}}
%\makeatother
% \show\myitem
% \begin{description}
%   \myitem{align,key} This is documentation for key \emph{align}.
% \end{description}
% \endinput

답변2

문서가 두 번째로 처리되면( 에 의해 입력됨 \DocInput) TeX는 \iffalse파일의 맨 위에서 찾습니다. 이는 다음 주석 기호와 \iffalse일치하여 서문을 건너뛰도록 하는 것입니다 . \fi하지만 그렇지 않습니다. \else의 정의에 갇히게 됩니다 \myitem.

일반적으로 \ifpgfutil@in@중첩된 조건문에 사용하는 것이 안전합니다. 그런데 왜 이런 일이 발생합니까?

대답은 TeX가 \ifpgfutil@in@두 번째 패스에서 no를 찾았다는 것입니다. 왜냐하면 의 catcode는 @is other, not letter ---가 's 에 붙어 있는 \makeatletter바로 그 문자로 건너뛰었 기 때문 입니다.\iffalse\ifpgfutil@in@\else

빠르고 더러운 해결책은 \if두 번째 단계에서 TeX에만 표시되는 주석을 제공하는 것입니다.

% \iffalse meta-comment
%<*driver>
\documentclass{ltxdoc}
\input pgfutil-common
\makeatletter
\def\myitem#1{%
  \pgfutil@in@{,}{#1}%
  \ifpgfutil@in@          %\if
    \myitem@#1\@end
  \else
    \myitem@#1,\@end
  \fi
}
\def\myitem@#1,#2\@end{\item\texttt{#1}\quad\marginpar{\small\it#2}}
\makeatother
\begin{document}
  \DocInput{error.dtx}
\end{document}
%</driver>
% \fi
% \begin{description}
%   \myitem{align,key} This is documentation for key \emph{align}.
% \end{description}
% \endinput

아니면 잠재적으로 문제가 되는 모든 코드를 별도의 파일에 넣는 것이 더 나을 수도 있습니다.

관련 정보