
어떻게 해야 하나요? 사용이 \@ifnextchar^{command1}{command2}
작동하지 않습니다. ^를 감지하려면 대신 어떻게 해야 합니까?
업데이트.명령에는 문제가 없는 것으로 나타났습니다. 단지 매크로 정의의 다른 곳에서 이름이 충돌하는 것뿐이었습니다. 빠른 반응에 감사드립니다!
답변1
^
다음 명령과 함께 작동합니다 \sp
.
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\foo}{%
\@ifnextchar\sp{\cmdone}{\cmdtwo}
}
\newcommand{\cmdone}{\text{Is superscripted!}}
\newcommand{\cmdtwo}{\text{Is not superscripted!}}
\makeatother
\begin{document}
$\foo^2$
$\foo E=mc^2$
\end{document}
답변2
다음 라텍스 파일은 다음의 터미널 출력을 생성합니다.
yes
no
다음에 대해 참 과 거짓을 \@ifnextchar
테스트했음을 보여줍니다 .^
!
\makeatletter
\@ifnextchar^{\typeout{yes}\@gobble}{\typeout{no}\@gobble}^
\@ifnextchar^{\typeout{yes}\@gobble}{\typeout{no}\@gobble}!
\stop