Latex printing single slash, backslash r, backslash n

被刻印的时光 ゝ 提交于 2019-12-02 14:31:03

问题


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

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

When I wrap it in a \verb command like this:

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

it doesn't work, and I get:

! Undefined control sequence.

All other google answers are so complicated.

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

EDIT:

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 %
%%%%%%%%%%%%%%%%%%
\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:


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

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

EDIT: 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] == `$\backslash$r' $\|$ tmp[0] == `$\backslash$n') $\{$tmp++;$\}$



来源:https://stackoverflow.com/questions/49380309/latex-printing-single-slash-backslash-r-backslash-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!