如何用逐字记录环境创建新的Beamer环境? [英] How do I create a new Beamer environment with a verbatim environment?
问题描述
我正在创建一个Beamer演示文稿,其中包含很多LaTeX示例,必须在逐字记录环境中使用.我已经厌倦了输入
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.
我不能仅使用\ begin {verbatim}来创建新的环境或命令,因为它会切断其余的命令.因此,我切换到使用fancyvrb软件包,并尝试了以下操作:
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}}
这给了我\ makeexample {Example Text}命令和\ begin {VerbExample} ... \ end {VerbExample}环境,但是它们在编译时仍然会引发错误.我要在其中使用它们的框架看起来像这样(框架上有[易碎]选项,所以不是那样).
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}
推荐答案
环境定义:
\newenvironment{VerbExample}
{\example\semiverbatim}
{\endsemiverbatim\endexample}
框架定义:
\begin{frame}[fragile]
\frametitle{Title}
\begin{VerbExample}
test test test $t$ $\\omega$
test test
\end{VerbExample}
\end{frame}
逐字记录不能进入\newcommand
.半动词由Beamer定义,并且可以很好地工作. 必须将三个字符\
{
}
转义为\\
\{
\}
.
Verbatim cannot go inside \newcommand
. Semiverbatim is defined by Beamer and works well with it. The three characters \
{
}
must be escaped as \\
\{
\}
.
来源:Beamer用户指南,第119-120页 http://www.ctan.org/tex-archive/macros/latex/contrib/beamer/doc/beameruserguide.pdf
Source: Beamer user guide, pp. 119-120 http://www.ctan.org/tex-archive/macros/latex/contrib/beamer/doc/beameruserguide.pdf
这篇关于如何用逐字记录环境创建新的Beamer环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!