Latex 打印单斜杠、反斜杠 r、反斜杠 n [英] Latex printing single slash, backslash r, backslash n

查看:185
本文介绍了Latex 打印单斜杠、反斜杠 r、反斜杠 n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 *.tex 文件中的以下行按原样"打印:

I want the following line inside a *.tex file to be printed "as is":

while (tmp[0] == '
' || tmp[0] == '
') {tmp++;}

当我将它包装在这样的 verb 命令中时:

When I wrap it in a verb command like this:

verb"while (tmp[0] == '
' || tmp[0] == '
') {tmp++;}"

它不起作用,我得到:

! Undefined control sequence.

所有其他谷歌答案都如此复杂.

All other google answers are so complicated.

当然,必须有一个简单的方法来做到这一点,对吧?谢谢!

Surely, there's got to be an easy way to do this, right? Thanks!

这是评论中要求的最小反例:

Here is the minimal counter example requested in the comments:

%%%%%%%%%%%%%%%%%%%%%%%%%%
% document class: beamer %
%%%%%%%%%%%%%%%%%%%%%%%%%%
documentclass{beamer}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% no navigation bars please %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
setbeamertemplate{footline}[frame number]{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% no navigation symbols please %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
setbeamertemplate{navigation symbols}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% no footers at all please %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
setbeamertemplate{footline}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%
% center the title please %
%%%%%%%%%%%%%%%%%%%%%%%%%%%
setbeamertemplate{frametitle}[default][center]

%%%%%%%%%%%%%%%%%%
% begin document %
%%%%%%%%%%%%%%%%%%
egin{document}

%%%%%%%%%
% title %
%%%%%%%%%
	itle{Some Title}   

%%%%%%%%%%
% author %
%%%%%%%%%%
author{Some Author}

%%%%%%%%%%%%
% date ... %
%%%%%%%%%%%%
date{	oday} 

%%%%%%%%%%%%%
% frame ... %
%%%%%%%%%%%%%
frame{	itlepage} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SECTION :: Introduction %
%%%%%%%%%%%%%%%%%%%%%%%%%%%
section{Section Introduction} 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Frame Title :: Introduction %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
frame{frametitle{Status}
%%%%%%%%%%%%%%%%%%
% Items :: Begin %
%%%%%%%%%%%%%%%%%%
egin{itemize}
item
while (tmp[0] == 'A' $||$ tmp[1] == 'B') ${$tmp++;$}$
end{itemize}
}
end{document}

推荐答案

要在 LaTeX 中打印实际的反斜杠,请使用命令 ackslash,因此对于您的代码:

To print an actual backslash in LaTeX you use the command ackslash, so for your code:

while (tmp[0] == 'ackslash r' || tmp[0] == 'ackslash n') {tmp++;}

我忘了你在数学模式下需要这个命令.如果您希望一切都原样",这就是您需要的代码(对于垂直线和大括号也是如此):

I forgot you need this command in math mode. If you want everything "as is", this is the code you need (for the vertical lines and the curly brackets as well):

while (tmp[0] == `$ackslash$r' $|$ tmp[0] == `$ackslash$n') ${$tmp++;$}$

这篇关于Latex 打印单斜杠、反斜杠 r、反斜杠 n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆