I'm having an issue with typesetting code using the minted package when I want to highlight for example print(x) # prints x
in a footnote:
\documentclass{article}
\usepackage{minted}
\begin{document}
Comments in Python\footnote{\mintinline{python}{print(x) # prints x}}.
\end{document}
The issue is that #
is printed twice:
If I were to highlight code with the percent sign, I could change its catcode:
\catcode`\%=11
Comments in \TeX\footnote{\mintinline{tex}{\LaTeX % comment}}.
However, changing the catcode of #
gives an error, since it is used in the definition of \mintinline
. The error is:
! Undefined control sequence.
\PYG #1#2->\FV@PYG
{#1}{\FancyVerbBreakStart #2\FancyVerbBreakStop }
l.2 ...x}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} prints x}
How can I fix this (in a scalable way)? I intend to use this quite a lot, since #
is a common character in the ARM assembly code I intend to typeset. (I cannot provide an ARM example here, since the ARM lexer is not in the latest pygments release yet).
\mintinline
in for example footnotes when using#
and%
, but does not give a solution.\mintinline
everything is tokenized. Isn't there a macro to define something, like\defmintinline\name{print(x) # prints x}
? Then you can use\name
whenever you want and it works right.