
아래 MWE를 컴파일할 때 첫 번째 MWE는 \@ifnextchar,
항상 false로 평가되는데, 마지막 경우에는 분명히 잘못된 것입니다. 그러나 두 번째 것(내부 \punctuationcheck
)은 잘 작동합니다. 동일한 조건이 False로 평가된 다음 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}
컴파일할 때 생성되는 결과는 다음과 같습니다.
즉, 쉼표가 보이지 않고 괄호가 보입니다) 테스트
즉, 쉼표가 보이지 않고 대괄호가 보입니다.] 테스트
즉, 쉼표가 보이지 않고 마침표가 보입니다. 시험
즉 쉼표가 안 보이네, 쉼표가 보이네, 테스트
답변1
구문은 다음과 같습니다 \@ifnextchar
.
\@ifnextchar<test-token>{<true>}{<false>}<token>
<test-token>
와 동일하면 코드 <token>
가 <true>
삽입되고, 그렇지 않으면 <false>
삽입되고 입력 스트림은 다음 중 하나가 됩니다.
<true><token>
또는
<false><token>
<token>
이 단계에서는 제거되지 않습니다 . 이를 사용하는 올바른 방법은 \@ifnextchar<test-token>{<true>}{<false>}
매크로 코드의 후행 부분을 사용하여 <token>
매크로 다음에 오는 부분이 되도록 하는 것입니다.
대신 귀하의 코드에는 가 <token>
이미 지정되어 있으므로 \punctuationcheck
TeX는 항상 코드를 사용하는 것이 옳습니다 <false>
.
해결책:
\newcommand{\ie}{%
\textit{i.e.}%
\@ifnextchar,%
{I saw a comma}%
{I didn't see a comma,\punctuationcheck}%
}