
これをどうやって行うのですか? を使用すると\@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
次のLaTeXファイルは、次のような端末出力を生成します。
yes
no
\@ifnextchar
は真であり^
、は偽であるとテストされたことを示す!
\makeatletter
\@ifnextchar^{\typeout{yes}\@gobble}{\typeout{no}\@gobble}^
\@ifnextchar^{\typeout{yes}\@gobble}{\typeout{no}\@gobble}!
\stop