
我在原始碼中定義了一個新命令:
\newcommand{\IN}{interface}
列印出介面,但有時我想列印它介面(大寫 I)或介面相反,如果不定義另外 2 個新命令,我該如何做到這一點?
答案1
像這樣的東西嗎?
程式碼
\documentclass{article}
\newcommand*{\IN}[1][0]{%
\ifnum#1=0 interface\fi
\ifnum#1=1 Interface\fi
\ifnum#1=2 interfaces\fi
}
\begin{document}
\IN, \IN[1], \IN[2]
\end{document}
輸出
然而,正如 Egreg 所說,輸入“interface”很簡單。 :)
答案2
您也可以為大寫定義帶有星號的命令,並簡單地附加s
複數:
\documentclass{article}
\makeatletter
\DeclareRobustCommand*{\IN}{%
\@ifstar{Interface}{interface}}
\makeatother
\begin{document}
Singular: \IN, \IN*
\par Ways to write plurals: \IN s, \IN{s}, \IN{}s, \IN*s
\end{document}
\DeclareRobustCommand
需要使命令不脆弱,因此您不需要\protect
在標題等中使用它。