# Display LaTeX code in a document [duplicate]

I have a LaTeX document in which I want to display in the main document the way a LaTeX function is used, for example:

\documentclass{name} is bla bla bla

the thing is that LaTeX always recognises \documentclass as a function, therefore throwing an error.

Is there a way to solve this problem?

-

## marked as duplicate by zeroth, Yiannis Lazarides, Werner, barbara beeton, lockstepFeb 7 '13 at 21:25

Welcome to TeX.SE! Have you considered encasing the string \documentclass{name} in a \verb+...+ statement? (The + character should be chosen in a way that ensures that it's not also used in the verbatim string itself.) Alternatively -- and this may be especially relevant if you do not want to render the string using a monospaced font -- you could write \textbackslash$\{$name$\}$ to preserve both the backslash and the curly braces. – Mico Feb 7 '13 at 20:30
@Mico why the math mode around \{ and \}? – clemens Feb 7 '13 at 20:35
Thank you very much! The \verb+..+ solution does the job perfectly – user25656 Feb 7 '13 at 20:45
@Mico please either post an answer, or vote to close as a duplicate (must be one somewhere) – cmhughes Feb 7 '13 at 20:49
@cmhughes - done! – Mico Feb 7 '13 at 21:20

There are (at least) two methods for typesetting \documentclass{name} without LaTeX being tripped up by the three "special" characters in the string, viz., \, {, and }:

• The "verbatim" method will result in the string being typeset using a "monospaced" font -- which is probably what you want.

• You could "escape" the special characters directly, resulting in the string being typeset using the default text font (probably a serif font).

\documentclass{article}
\begin{document}

% verbatim method - the delimiter character (here: +)
%   mustn't appear in the string being rendered in
%   verbatim mode
\verb+\documentclass{name}+

% or, use macros to "escape" the backslash and curly braces
\textbackslash documentclass\{name\}

\end{document}

-
As an addition: the font used by \verb and the verbatim environment is stored in \verbatim@font and defaults to \normalfont\ttfamily. It can simply be redefined to get another verbatim formatting. – clemens Feb 7 '13 at 21:28