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

  • 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
  • 6
    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
  • 6
    \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

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.

  • 2
    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

! 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


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

  • 1
    This worked for me. It's the simplest solution to the problem. I tried fancyvrb package first, but I might not have understood exactly how to use \VerbatimFootnotes. – CyberFonic Jan 6 '16 at 23:08
  • Sadly bigfoot.sty also conflicts with footmisc.sty, which allows you to have double spaced text and single spaced footnotes. Here's the example that's used to illustrate how footmisc works, but with the addition of bigfoot. Is there a way to use both and still get singlespaced footnotes with \doublespacing? \documentclass[11pt]{article} \usepackage{setspace} \usepackage{bigfoot} \usepackage{footmisc} \usepackage{lipsum} \renewcommand\footnotelayout{\fontsize{10}{12}\selectfont} \doublespacing \begin{document} \lipsum*[1]\footnote{\lipsum[1]}\footnote{\lipsum[1]} \end{document} – Leo Simon Feb 16 '16 at 19:11
  • @LeoSimon I don't get double spaced footnotes with bigfoot alone nor with both footmisc and bigfoot, neither with or without changing \footnotelayout. (I have an up to date TeX Live, updated yesterday…) – clemens Feb 17 '16 at 11:02
  • @clemens, thanks I'll try to figure out how to update. – Leo Simon Feb 17 '16 at 18:21
  • Having the same problem as the OP, I tried this solution: while it solved my issue, now my not-so-short footnotes spread across multiple pages instead of being localized at the bottom of the page were they are used! Probably this solution requires a little bit of fine tuning. – Rackbox Apr 29 at 13:12

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


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.


\cprotect is straightforward to use and flexible (e.g., see this answer to a related question which uses the same solution to use \verb within section titles as well).



I want this.\cprotect\footnote{\verb|And, it works!|}


Here is a screenshot (with\textheight adjusted as in the other answers to make the screenshot small):

screenshot of output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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