5

I'm trying to display the following:

.\integrate blah

in a monospaced font.

For everything else I've wanted to put in a monospace font, \texttt or \verb has worked fine, but it doesn't with this. I've worked out that I need to escape the \ in the text, but replacing it with \\ gives a newline.

What should I use to escape the \ in LaTeX?

Stefan Kottwitz
  • 231,401
robintw
  • 7,362

3 Answers3

10

You can use \verb to display a backslash in monospaced font; the following example shows another option to display a backslash in monospaced font:

\documentclass{article}

\begin{document}

\verb+\+

\texttt{\symbol{92}}

\verb+\integrate+

\texttt{\symbol{92}integrate}

\end{document}
Gonzalo Medina
  • 505,128
7

You could use \textbackslash to produce a backslash. To get it monospaced, you should use T1 font encoding which is recommendable anyway, otherwise it's not a true typewriter backslash.

You might also have a look at answers to these questions:

Compare:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{url}
\begin{document}
\verb|.\integrate|

\texttt{.\textbackslash integrate}

\texttt{.\char`\\integrate}

\path{.\integrate}
\end{document}

backslash screenshot

Stefan Kottwitz
  • 231,401
1
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{url}
\DeclareUrlCommand\cs{\ttfamily.\textbackslash}
\begin{document}

\cs{integrate}

\end{document}