When I compile the below MWE the first \@ifnextchar, always evaluates to false, which is clearly wrong in the last case. However, the second one (within \punctuationcheck) works just fine. Why would the same conditional evaluate to False and then True?
\documentclass{article}
\makeatletter
\newcommand{\punctuationcheck}{%
@ifnextchar){I see a parens\relax}{%
@ifnextchar]{I see a square bracket\relax}{%
@ifnextchar.{I see a period\relax}{%
@ifnextchar,{I see a comma\relax}{I didn' t see anything\ }}}}%
}
\newcommand{\ie}{\textit{i.e.}@ifnextchar,{I saw a comma\relax}{I didn't see a comma,}\punctuationcheck}
\makeatother
\begin{document}
\ie) test
\ie] test
\ie. test
\ie, test
\end{document}
What this produces when I compile it:
i.e.I didn’t see a comma,I see a parens) test
i.e.I didn’t see a comma,I see a square bracket] test
i.e.I didn’t see a comma,I see a period. test
i.e.I didn’t see a comma,I see a comma, test
\@ifnextcharin\iealways sees\punctuationcheck; it has three arguments: (1) the character to check for; (2) the code to execute if the character is found; (3) the code to execute if the character is not found. The token immediately following the arguments is what's checked. – egreg Sep 22 '14 at 14:20\punctuationcheckmacro as the last token in both branches of the first\@ifnextchar, i.e.:\def\ie{\textit{i.e.}\@ifnextchar,{I saw a comma,\punctuationcheck}{I didn't see a comma,\punctuationcheck}}. – wipet Sep 22 '14 at 15:48