
다음 MWE를 고려하십시오.
\documentclass[11pt]{book}
\def\entrytest{WORD}
\def\entrycurrent{NOWORD}
% \def\entrycurrent{WORD}
\ifx\entrytest\entrycurrent
\newif\ifsomething
\somethingfalse
\fi
\ifx\entrytest\entrycurrent
\ifsomething\typeout{Yes}\else\typeout{No}\fi
\fi
\begin{document}
\end{document}
현재의 경우에는 그것을 감싸는 \ifsomething\typeout...
에 의해 "보호"되었을 것이라고 예상했을 것입니다 . \ifx
하지만 코드가 다음과 같이 중단되기 때문에 뭔가 옳지 않습니다.
...
No
! Extra \fi.
l.15 \fi
?
물론 \def\entrycurrent{WORD}
모든 \ifx
s가 "true" 분기에서 실행된다면 모든 것이 예상대로 작동합니다.
\newif
그렇다면 조건부로 정의된 s 의 사용을 어떻게 처리해야 할까요 ?
답변1
두 번째에서는 \ifx\entrytest\entrycurrent
가 \ifsomething
정의되지 않았으므로첫 번째 \fi
일치 \ifx
하고 두 번째는 \fi
제자리에 없습니다.
어떤 것을 조건부로 만드는 것은 매크로 이름이 아닙니다. 유일한 토큰은한정된기본 조건 수 중 하나와 동일합니다.
무엇 \newif\ifsomething
입니까?
\let\ifsomething\iffalse
\def\somethingtrue{\let\ifsomething\iftrue}
\def\somethingfalse{\let\ifsomething\iffalse}
당신은 아마도 다음과 같은 것을 원할 것입니다
\newif\ifsomething
\somethingtrue
\ifx\entrytest\entrycurrent
\somethingfalse
\fi
\ifx\entrytest\entrycurrent
\ifsomething\typeout{Yes}\else\typeout{No}\fi
\fi
하지만 처음부터 왜 이런 일을 하려는지는 불분명합니다.