忽略所有格式的环境

时间:2015-07-27 10:15:45

标签: latex

LaTeX中是否存在命令,以便我在该环境中编写的所有内容都按原样显示?

例如,当我想制作如何在LaTeX中使用命令的指南时,我有兴趣编写类似的东西:

In order to write $\cap$, you use the command \cap.

但这会返回错误,因为(最后一个)\cap不在正确的环境中。那么我该怎么做才能让LaTeX忽略命令并只显示文本?

我尝试使用\mbox{\cap},这不起作用,我也知道我可以$\backslash$cap,但这是一个特定问题的解决方案。

2 个答案:

答案 0 :(得分:2)

您可以使用默认的LaTeX \verb(可选择配对分隔符)或listings(使用\lstinline支持括号中的参数):

enter image description here

\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}

\begin{document}

In order to write~$\cap$, you use the command~\verb|\cap|.

In order to write~$\cap$, you use the command~\lstinline{\cap}.

\end{document}

还有其他选择,但这似乎符合您的需求。当然,如果您想使用\function而不是\lstinline之类的内容,请添加

\let\function\lstinline
加载listings包后

答案 1 :(得分:0)

尝试以下方法:

\documentclass[english]{article}
%\usepackage{verbatim}

\begin{document}

In order to write \verb|$\cap$|, you use the command \texttt{\textbackslash cap}.

\end{document}

请注意,要使用内联verb,您甚至不需要包verbatim

此外,此处必须使用\textbackslash,而不是$\backslash$

<强>附录:

阅读下面的评论,我认为以下内容可能有用:

\documentclass[english]{article}

\newcommand{\mycomm}[1]{\texttt{\textbackslash #1}}

\begin{document}

In order to write $\cap$, you use the command \mycomm{cap}.

\end{document}