LaTeX中是否存在命令,以便我在该环境中编写的所有内容都按原样显示?
例如,当我想制作如何在LaTeX中使用命令的指南时,我有兴趣编写类似的东西:
In order to write $\cap$, you use the command \cap.
但这会返回错误,因为(最后一个)\cap
不在正确的环境中。那么我该怎么做才能让LaTeX忽略命令并只显示文本?
我尝试使用\mbox{\cap}
,这不起作用,我也知道我可以$\backslash$cap
,但这是一个特定问题的解决方案。
答案 0 :(得分:2)
您可以使用默认的LaTeX \verb
(可选择配对分隔符)或listings
(使用\lstinline
支持括号中的参数):
\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}