I'm using minted
to display inline code in a footnote. For some reason the # symbol is rendered twice.
This does not happen outside of footnotes.
\footnote{bla bla \mintinline{python}{x = 5 # text} and so on}
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityAs stated in the first footnote on page 8 of minted
documentation,
The command (
\mintinline
) has been carefully crafted so that in most cases it will function correctly when used inside other commands.11 For example,
\mintinline
works in footnotes! The main exception is when the code contains the percent%
or hash#
characters, or unmatched curly braces.
The following trick tries to handle #
:
\documentclass{article}
\usepackage{minted}
\makeatletter
\let\footnote@orig\footnote
\def\footnote{%
\begingroup
\@makeother\#%
\footnote@i
}
% added \long to accept multi-para footnotes
\long\def\footnote@i#1{%
\endgroup
\footnote@orig{#1}%
}
\makeatother
\begin{document}
content\footnote{bla bla \mintinline{python}{x = 5 # text} and so on}
\end{document}
Updates:
\footnote@i
long, cf @cgnieder
's comment.For information, if you use the package piton
in order to format Python listings, you won't have this problem (however \piton
works only with LuaLaTeX).
\documentclass{article}
\usepackage{xcolor}
\usepackage{piton}
\begin{document}
Some text.\footnote{bla bla \piton{x = 5 # text} and so on}
\end{document}
The colors are the colors are the style manni
of Pygments (and minted
).
I had a similar problem with double-hash rendering in beamer slides. Adding the attribute fragile
to the frame solved my problem.