如何使用“listings”在 LaTeX 文档中嵌入 LaTeX 关键字
我想在文档中引用 LaTeX 代码,但如何正确嵌入关键字“\begin{lstlisting}”和“\end{lstlisting}”?
下面的代码不起作用(显然):
\lstset{language=TeX, basicstyle=\footnotesize, numbers=left, numberstyle=\tiny, frame=single}
\begin{lstlisting}
\begin{lstlisting} % this is code
place your source code here % this is code
\end{lstlisting} % this is code
\end{lstlisting}
I want to cite LaTeX code into my document but how do I embed the keywords "\begin{lstlisting}" and "\end{lstlisting}" correctly?
CODE BELOW DOES NOT WORK (obviously):
\lstset{language=TeX, basicstyle=\footnotesize, numbers=left, numberstyle=\tiny, frame=single}
\begin{lstlisting}
\begin{lstlisting} % this is code
place your source code here % this is code
\end{lstlisting} % this is code
\end{lstlisting}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的序言中有
\usepackage{listings}
吗?如果是这样,它应该可以工作。TeX
是受支持的语言。这是一个最小的示例:
编译为
编辑
引用列表中的命令包(实际上,仅适用于
\end{lstlisting}
),转义到乳胶以打印\
字符,然后一切就完成了。下面,我将@
定义为转义字符,并且两个@
符号内的所有内容都在 LaTeX 中排版。所以在这里,我使用 LaTeX 输入了\
,其余部分在lstlisting
中输入,并且\end{...}
序列不被解释作为一个封闭的环境。输出为
Do you have
\usepackage{listings}
in your preamble? If so, it should work.TeX
is a supported language.Here's a minimal example:
which compiles to
EDIT
To quote commands from the listings package (actually, only for
\end{lstlisting}
), escape to latex to print the\
character and you're all set. In the following, I've defined@
as the escape character and everything within two@
symbols is typeset in LaTeX. So here, I've input the\
using LaTeX and the rest withinlstlisting
and the\end{...}
sequence is not interpreted as a closing the environment.The output is
你可以使用逐字块吗?
\begin{verbatim}
\begin{lstlisting} % 这是代码
将源代码放在这里 % 这是代码
\end{lstlisting} % 这是代码
\end{verbatim}
can you use a verbatim block?
\begin{verbatim}
\begin{lstlisting} % this is code
place your source code here % this is code
\end{lstlisting} % this is code
\end{verbatim}
您可以使用它
来创建一个仅具有列表
lstlisting
行为的新环境,并且不应在其中禁止\end{lstlisting}
。You can use
to create a new envirnment that behaves just list
lstlisting
, and\end{lstlisting}
should not be forbidden in it.