0

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?

Torbjørn T.
  • 206,688
  • 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 07 '13 at 20:30
  • 1
    @Mico why the math mode around \{ and \}? – cgnieder Feb 07 '13 at 20:35
  • Thank you very much! The \verb+..+ solution does the job perfectly – user25656 Feb 07 '13 at 20:45
  • 1
    @Mico please either post an answer, or vote to close as a duplicate (must be one somewhere) – cmhughes Feb 07 '13 at 20:49
  • @cmhughes - done! – Mico Feb 07 '13 at 21:20
  • @cgnieder - The use of the inline math mode delimiters is indeed unnecessary! – Mico Feb 07 '13 at 21:21

1 Answers1

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

    \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}
    
Mico
  • 506,678
  • 1
    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. – cgnieder Feb 07 '13 at 21:28