我正在尝试创建一个新命令,以便简化 Beamer 下的参考放置。这是一个示例文件:
\documentclass[bigger]{beamer}
\usepackage[absolute,overlay]{textpos}
\tolerance=1000
\newcommand{\myref}[3]{
\begin{textblock*}{100mm}(0.07\textwidth,.93\textheight)
{\footnotesize #1, {\emph #2}, #3}
\end{textblock*}}
\begin{document}
\begin{frame}
\myref{must, write, something}
\end{frame}
\end{document}
当我尝试运行它时,pdflatex
我得到:
tionary/translator-theorem-dictionary-English.dict) (./error.nav)
! Argument of \end has an extra }.
<inserted text>
\par
l.14 \end{frame}
Runaway argument?
! Paragraph ended before \end was complete.
<to be read again>
\par
l.14 \end{frame}
! LaTeX Error: \begin{beamer@framepauses} on input line 14 ended by \end{docume
nt}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.17 \end{document}
(./error.aux)
! You can't use `\end' in internal vertical mode.
\enddocument ... \endgroup \deadcycles \z@ \@@end
l.17 \end{document}
! LaTeX Error: \begin{beamer@framepauses} on input line 14 ended by \end{docume
nt}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.17 \end{document}
)
! Emergency stop.
<*> \nonstopmode\input error.tex
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on error.log.
[yotam@myhost Res.Prop.Exam]$
我找不到我丢失的文件,}
你能吗? *请注意,我的 tex 文件名为Error.tex
答案1
这里的问题是,命令定义了三个参数,但只给出了一个。有两种可能的解决方案:使用三个参数或使用一个参数并解析逗号分隔的输入。第一种情况只是
\myref{must}{write}{something}
对于第二种情况,我会使用xparse
\documentclass[bigger]{beamer}
\usepackage{xparse}
\usepackage[absolute,overlay]{textpos}
\tolerance=1000
\NewDocumentCommand{\myref}{>{\SplitArgument{2}{,}}m}{%
\myrefaux#1%
}
\newcommand{\myrefaux}[3]{%
\begin{textblock*}{100mm}(0.07\textwidth,.93\textheight)
{\footnotesize #1, {\em #2}, #3}
\end{textblock*}
}
\begin{document}
\begin{frame}
\myref{must, write, something}
\end{frame}
\end{document}
设置逗号分隔列表解析器的方法有很多,但这个方法非常简单。辅助函数在所有情况下都会获得三个参数,即使你搞砸了,忘记了逗号或类似的东西。
答案2
正如 Andrew Stacey 在他的评论中提到的那样,你必须写\myref{must}{write}{something}
。如果您想要语法:\myref{must, write, something}
您可以执行以下操作:
\newcommand{\myref}[1]{\myrefI#1\nil}
\def\myrefI#1,#2,#3\nil{%
\begin{textblock*}{100mm}(0.07\textwidth,.93\textheight)
{\footnotesize #1, {\emph #2}, #3}
\end{textblock*}%
}
完整的 MWE:
\documentclass[bigger]{beamer}
\usepackage[absolute,overlay]{textpos}
\tolerance=1000
\newcommand{\myref}[1]{\myrefI#1\nil}
\def\myrefI#1,#2,#3\nil{%
\begin{textblock*}{100mm}(0.07\textwidth,.93\textheight)
{\footnotesize #1, {\emph #2}, #3}
\end{textblock*}%
}
\begin{document}
\begin{frame}
\myref{must, write, something}
\end{frame}
\end{document}