Take the 2-minute tour ×

I want to employ a \verb command in a footnote. But, when I run pdflatex on



I want this.\footnote{\verb|But, it does not work!|}


I get this:

! LaTeX Error: \verb illegal in command argument.

How can I do what I am after? (I know that I could just use \footnote{\texttt{But, I lose the semantic mark-up.}})

share|improve this question
You want to do something that LaTeX doesn't allow you to do. You either (a) go in and mess with the code under the hood to allow you to do it or (b) work around it. For (b), it'd be nice to know what "semantic mark-up" you are after. –  Willie Wong Jul 26 '10 at 22:53
1) I know that LaTeX doesn't allow it. (a) That is in the question. (b) I'm trying to help seed in the beta. 2) I'm puzzled by your (b). As I understand it \texttt{} is formatting mark-up, and \verb|| is semantic mark-up. (You mark something as \verb and leave the formatting of it up to LaTeX and your documentclass. –  vanden Jul 26 '10 at 23:04
\verb is absolutely the opposite of semantic markup it is just a low level instruction to the TeX parser to change the lexical analysis of its input (which is why it doesn't work in macro arguments where the input has already been tokenised). It doesn't say anything about what the content means, just that \ and {} should be parsed in a different way. –  David Carlisle Dec 18 '12 at 12:22
add comment

5 Answers

up vote 19 down vote accepted

The package fancyvrb supports this. Just put \VerbatimFootnotes anywhere after the preamble, and then:

We can put verbatim\footnote{\verb+_Yes!_+} text in footnotes.

Edit: As pointed out in the comment and here, this may conflict with some footnote-specific packages, e.g. footmisc when used with the para option, but there are other alternatives. Quoting two from there:

  • The memoir class defines its \footnote command so that it will accept verbatim in its arguments, without any supporting package.

  • With fancyvrb, you can \SaveVerb something and \UseVerb it in a footnote.

There exist also further packages like examplep.

share|improve this answer
Note, though, that \VerbatimFootnotes doesn't play well with some other packages. See the UK TeX FAQ entry for discussion and alternatives. –  vanden Jul 26 '10 at 23:08
add comment

! LaTeX Error: \verb illegal in command argument.? Yes. sir!

Well, then let’s use it in an environment:

The environment lrbox{<savebox>} works similar to \sbox{<savebox>}{<stuff to save>} but instead of saving an argument into a savebox it’s the environment’s body that gets saved into a savebox. That savebox is then used inside the \footnote command.


I want this.%
    \verb|You got this! % \ _ { }|%

I defined a custom environment and a custom macro for you.%
\begin{verbbox}\scriptsize\verb|\begin{verbox} \verb!\begin{verbox} Inception?\end{verbox}! \end{verbbox}|\end{verbbox}%
\footnote{Wow?! \verbBox}%


enter image description here

share|improve this answer
Related: lrbox in \newenvironment –  Qrrbrbirlbel Dec 18 '12 at 12:59
add comment

The bigfoot package allows verbatim material in footnotes:

% only for this example:

I want this.\footnote{\verb|But, it does not work!&%$|}


enter image description here

share|improve this answer
add comment

Another plug for the memoir class: its \verbfootnote allows for verbatim material.

\usepackage[nohead, paperwidth=15cm, paperheight=7cm]{geometry}
% from the memmoir manual (§ 12.1.1):
Below, footnote~\ref{fn1} is a \verb?\footnote? while
footnote~\ref{fn2} is a \verb?\verbfootnote?.

The \verb?\verbfootnote? command should appear%
\footnote{There may be some problems if color is used.\label{fn1}} %
to give identical results as the normal \verb?\footnote?, but it can
include some verbatim text%
\verbfootnote{The \verb?\footnote? macro, like all other macros except
  for \verb?\verbfootnote?, can not contain verbatim text in its
  argument.\label{fn2}} %
in the \meta{text} argument.

share|improve this answer
add comment

In this approach, the verbatim material is placed in a box prior to entering the footnote, and the box is recalled within the footnote.

I am ready for a footnote.%
\verbatim material
\footnote{See if \theverbbox\ can appear in footnotes.} And we continue\ldots


enter image description here

share|improve this answer
add comment

Your Answer


