
次の 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
「true」ブランチで実行される場合、すべてが期待どおりに動作します。
\newif
では、条件付きで定義されている可能性のある sの使用をどのように処理すればよいのでしょうか?
答え1
2番目の では\ifx\entrytest\entrycurrent
、\ifsomething
は定義されていないので、初め \fi
一致しており\ifx
、2番目は\fi
場違いです。
マクロ名が条件文になるのではなく、トークンが条件文になるだけです。定義されたこれは、プリミティブ条件カウントの 1 つに相当します。
それ\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
しかし、そもそもなぜこれをやるのかは不明です。