我写了这段代码
\documentclass{article}
% make a command called \insertfoo{..} for the user to insert foo
\newcommand{\insertfoo}[1]{%
\savebox{\boxthatcontainsfoo}{#1}%
}
% make a command called \showfoo that shows the value for foo
\newcommand{\showfoo}{%
\usebox{\boxthatcontainsfoo}%
}
\insertfoo{somefoo}
\begin{document}
The foo you choose was \showfoo .
end{document}
\end{document}
为什么我会收到编译错误?
答案1
这是一个有效的 MWE:
\documentclass{article}
% make a command called \insertfoo{..} for the user to insert foo
\newsavebox{\boxthatcontainsfoo}
\newcommand{\insertfoo}[1]{%
\savebox{\boxthatcontainsfoo}{#1}%
}
% make a command called \showfoo that shows the value for foo
\newcommand{\showfoo}{%
\usebox{\boxthatcontainsfoo}%
}
\begin{document}
\insertfoo{somefoo}
The foo you chose was \showfoo.
\insertfoo{some other foo}
The foo you chose was \showfoo.
\end{document}
您需要定义用于存储内容的框(\boxthatcontainsfoo
),但\insertfoo{...}
在向宏传递参数时也需要使用,而不是\insertfoo(...)
。
如果需要的话,可以修改\insertfoo
为使用(圆)括号来运行。