在投影機框架內使用 \newcommand 時出錯

在投影機框架內使用 \newcommand 時出錯

由於某些原因我的beamer\newcommand簡報放置在環境中時不會編譯frame。這是一個最小的工作範例:

\documentclass{beamer}

\begin{document}

\begin{frame}{First slide}
  \newcommand{\asdf}[1]{What is the #1 problem?}
\end{frame}

\end{document}

我收到以下錯誤:

\test 定義中的參數編號非法。

請注意,\asdf巨集在定義後甚至不會被使用。奇怪的是,當我將定義放在環境之外時frame,一切正常。這種奇怪行為的原因是什麼?

答案1

添加fragile應該可以解決問題:

\documentclass{beamer}

\begin{document}

\begin{frame}[fragile]{First slide}
  \newcommand{\asdf}[1]{What is the #1 problem?}
\end{frame}

\end{document}

相關內容