如何创建具有逐字环境的新 Beamer 环境?
我正在创建一个 Beamer 演示文稿,其中包含大量 LaTeX 示例,并且必须在逐字环境中进行。我厌倦了打字,
\begin{example}
\begin{verbatim}
Verbatim Text
\end{verbatim}
\end{example}
我希望创建一个新的命令或环境来为我速记此内容。我还需要它来处理块和定理,因为我也经常使用它们。但如果我能弄清楚示例,那么应该很容易转换为另一个示例。
我无法仅使用 \begin{verbatim} 创建新环境或命令,因为它会切断命令的其余部分。所以我改用 fancyvrb 包,并尝试了以下操作:
\DefineVerbatimEnvironment
{MyVerbatim}{Verbatim}{}
\newcommand{\makeexample}[1]{
\begin{example}
\begin{MyVerbatim}
#1
\end{MyVerbatim}
\end{example}
}
\makeenvironment{VerbExample}{\begin{example}
\begin{MyVerbatim}}{\end{MyVerbatim}\end{example}}
这给了我 \makeexample{Example Text} 命令和 \begin{VerbExample}...\end{VerbExample} 环境,但它们仍然会抛出错误编译。我尝试使用它们的框架看起来像这样(我在框架上有[脆弱]选项,所以不是那样)。
\begin{frame}[fragile]
\frametitle{Why Doesn't Verbatim Work?}
\makeexample{Verbatim Text}
\begin{VerbExample}
Verbatim Text
\end{VerbExample}
\end{frame}
I'm creating a Beamer presentation that has a lot of example LaTeX in it, which has to go in a verbatim environment. I'm getting tired of typing
\begin{example}
\begin{verbatim}
Verbatim Text
\end{verbatim}
\end{example}
I wish to create a new command or environment that will shorthand this for me. I also need this for blocks and theorems, since I'm using those frequently as well. But if I can figure it out for examples, it should be easy to translate to another example.
I can't create a new environment or command using just \begin{verbatim}, since it cuts off the rest of the command. So I switched to using the fancyvrb package, and tried the following:
\DefineVerbatimEnvironment
{MyVerbatim}{Verbatim}{}
\newcommand{\makeexample}[1]{
\begin{example}
\begin{MyVerbatim}
#1
\end{MyVerbatim}
\end{example}
}
\makeenvironment{VerbExample}{\begin{example}
\begin{MyVerbatim}}{\end{MyVerbatim}\end{example}}
That gives me the \makeexample{Example Text} command, and the \begin{VerbExample}...\end{VerbExample} environment, but they both still throw errors on compile. The frame I'm trying to use them in looks like this (I've got the [fragile] option on the frame, so it's not that).
\begin{frame}[fragile]
\frametitle{Why Doesn't Verbatim Work?}
\makeexample{Verbatim Text}
\begin{VerbExample}
Verbatim Text
\end{VerbExample}
\end{frame}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
环境定义:
框架定义:
Verbatim 不能进入
\newcommand
内部。 Semiverbatim 由 Beamer 定义并且可以很好地配合使用。三个字符\
{
}
必须转义为\\
\{
<代码>\}。来源:Beamer 用户指南,第 119-120 页
http://www.ctan.org/ tex-archive/macros/latex/contrib/beamer/doc/beameruserguide.pdf
Environment definition:
Frame definition:
Verbatim cannot go inside
\newcommand
. Semiverbatim is defined by Beamer and works well with it. The three characters\
{
}
must be escaped as\\
\{
\}
.Source: Beamer user guide, pp. 119-120
http://www.ctan.org/tex-archive/macros/latex/contrib/beamer/doc/beameruserguide.pdf