Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

1 Answer 1

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).

    % verbatim method - the delimiter character (here: +)
    %   mustn't appear in the string being rendered in 
    %   verbatim mode
    % or, use macros to "escape" the backslash and curly braces
    \textbackslash documentclass\{name\}
share|improve this answer
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.