If I type $ formulae $, then the result will be


But I want to type "$ formulae $" expression itself, so the result will be

$ formulae $

(I mean the result include $ expressions!)

Thanks ;)

  • 3
    try \verb|$formula$|
    – nox
    Jul 8, 2018 at 0:56

2 Answers 2


I believe you are asking about how to render material -- possibly, but not necessarily, a math formula -- verbatim or "as is". Put differently, you wish to show some input code itself, rather than the result of the code block being processed by LaTeX.

LaTeX offers the \verb macro and the verbatim environment for such use cases. The first is meant for inline material, the second for "displayed" material, e.g., one or more displayed equations. Following a common typographic convention, verbatim material is typeset using a mono-spaced or "typewriter" font. Line breaks in the input material result in line breaks in the output. Automatic line-wrapping is disabled. The material contained in a verbatim environment is typeset flush-left. Paragraph indentation is disabled. Spaces at the start of a line are not ignored.

Importantly, the argument of \verb is not delimited by a pair of matching curly braces -- {and }. Instead, it must be delimited by some character that doesn't occur anywhere in the macro's argument. Thus,


renders 1-1=0 in a typewriter font, because the delimiter character -- 2 -- does not occur in the formula. In contrast, if one were to write


only the first 1 would get rendered in typewriter font, while 1=0- would be rendered in ordinary text font -- not what's desired, right? Interestingly, the delimiter character can be any character -- including the "TeX special" characters such as \, %, ^, etc. -- except the space character. Thus, while \verb{1-1=0} is invalid (as was already noted), \verb{1-1=0{ is actually valid from a syntactical standpoint. (But it sure looks weird, doesn't it?!)

An important practical limitation of \verb is that it cannot be used in the argument of \footnote.

The fancyvrb package provides the macro \Verb and the environment Verbatim; they extend the capabilities of \verb and verbatim in useful ways. For instance, if one loads the fancyvrb package and issues the instruction \VerbatimFootnotes after \begin{document}, one can use the \Verb macro inside footnotes. (This isn't as arcane as one might be tempted to think...) The Verbatim environment can be set up to do all kinds of interesting stuff to the material that's in the scope of the environment. For instance, the font that's used to typeset the Verbatim material needn't be the system typewriter font, one can set a color other than black, one can use bold, etc. It's also possible to define one's own, customized verbatim-type environments and to read verbatim-like material from external files. By all means, do study the package's user guide to familiarize yourself with the customization possibilities. Incidentally, if the material inside a Verbatim environment contains the characters \ (backslash) and/or _ (underscore), it's necessary to execute \usepackage[T1]{fontenc} in the preamble. In contrast, having \ or _ in the argument of \Verb does not require the user to run the instruction \usepackage[T1]{fontenc} in order to get the expected output.

If you prefer to use \Verb instead of \verb -- say, because you need to render verbatim material in a footnote -- do be aware that not all characters can be used as the delimiter character. In particular, attempting to use \, %, [, ], {, or } as the delimiter character generates an error message, and using * as the delimiter character generates some unexpected output. (Check out the example code below...) I trust that these limitations don't constitute a meaningful binding constraint in practice.

A noteworthy difference between the verbatim and Verbatim environments is that if there's any material (including a single character) on the line immediately before \end{verbatim}, it will be output; even a single space character immediately before \end{verbatim} will generate a new blank line of output. In contrast, any material (including space characters) on the line immediately before \end{Verbatim} is ignored. In addition, if there's any material on the line immediately after \end{Verbatim} (including a comment!), an error message will be generated and LaTeX will crash. Again, I trust this is not a binding constraint on the way you input your material.

A final comment: Rendering material in verbatim mode, i.e., without any processing at all, is actually a surprisingly tricky affair in LaTeX (and Plain-TeX too). If you happen to have sufficiently fancy material, even \Verb might choke. For such cases, you may need to turn to LuaLaTeX, as LuaLaTeX offers far more flexible and robust ways to handle input material, including material to be processed verbatim. For more information on this subject, please see the posting How to handle verbatim material in LuaLaTeX?

Some practical examples.

enter image description here

\usepackage{xcolor}   % for '\color' macro
\usepackage{fancyvrb} % for '\Verb' macro & 'Verbatim' env.

Hello \verb{Hello{ Hello  % looks weird, but is ok

\verb21-1=02              % looks even weirder, but is ok as well

Bye \Verb(Bye( Bye

Bye \Verb*Bye* Bye        % ouch!

\hrule % to illustrate start and end of the environments
 \begin{verbatim}  % space at start of line, before \begin{verbatim}, is ok
Hello Hello
 \end{verbatim}    % space character is not ignored, generates a blank line
Bye Bye
% "xyz" at start of preceding line is ignored

Good morning
  • BTW, I deliberately omitted a discussion of the \verb* macro, the verbatim* environment, and the verbatim package -- their capabilities do not seem pertinent to the OP's question. If one is in the habit of leaving spaces between \end and the name of the environment, e.g., if one wishes to write \end {verbatim} (note the space between \end and {verbatim}), one should definitely load the verbatim package in order to accommodate this input syntax preference. A side-effect of loading the verbatim package is that any material on the same line as \end {verbatim} is now ignored.
    – Mico
    Jul 8, 2018 at 8:51

Please type \$ formulae \$ in you tex editor, and it will work..

  • 3
    Not if "formulae" contains stuff that are only meant for math mode like _, \verb is the correct method
    – daleif
    Jul 8, 2018 at 5:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .