latex 定义带有方括号的command

时间: 2023-08-18 admin IT培训

latex 定义带有方括号的command

latex 定义带有方括号的command

来源:

方括号中的参数其实就是默认参数。
使用方法:

\newcommand{name}[num][default]{definition}

例子:

\newcommand{\wbalTwo}[2][Wikimedia]{This is the Wikibook about LaTeXsupported by {#1} and {#2}!}
% in the document body:
\begin{itemize}
\item \wbalTwo{John Doe}
\item \wbalTwo[lots of users]{John Doe}
\end{itemize}

输出:

    This is the Wikibook about LaTeX supported by Wikimedia and John Doe!This is the Wikibook about LaTeX supported by lots of users and John Doe!