Take the 2-minute tour ×
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
    
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
1  
@Mico why the math mode around \{ and \}? –  cgnieder Feb 7 '13 at 20:35
    
Thank you very much! The \verb+..+ solution does the job perfectly –  user25656 Feb 7 '13 at 20:45
1  
@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
show 1 more comment

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.

1 Answer

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}
    
share|improve this answer
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 7 '13 at 21:28
add comment

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