乳胶印刷单斜线,反斜杠r,反斜杠n

时间:2018-03-20 09:19:32

标签: escaping latex verbatim-string

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

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

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

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

它不起作用,我得到:

! Undefined control sequence.

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

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

编辑:

以下是评论中要求的最小计数器示例:

%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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 %
%%%%%%%%%%%%%%%%%%
\begin{document}

%%%%%%%%%
% title %
%%%%%%%%%
\title{Some Title}   

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

%%%%%%%%%%%%
% date ... %
%%%%%%%%%%%%
\date{\today} 

%%%%%%%%%%%%%
% frame ... %
%%%%%%%%%%%%%
\frame{\titlepage} 

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

1 个答案:

答案 0 :(得分:1)

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

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

编辑:我忘了你在数学模式下需要这个命令。如果您希望“按原样”处理所有内容,则这是您需要的代码(对于垂直线和大括号):

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

This gives this ouput