我正在使用的代码这答案允许minted
提供内联代码。但不幸的是,这会破坏行号,行号不再显示。
我怎样才能同时拥有内联代码和minted
用?进行行编号
MWE:没有带行号的内联代码:
\documentclass[a6paper,10pt]{article}
\usepackage{minted}
\begin{document}
Ciao \mint[linenos]{c}/int a = 1;/ Prova
\begin{minted}[linenos]{c}
int a = 1;
\end{minted}
\end{document}
结果:
MWE 带有内联代码,行号不起作用:
\documentclass[a6paper,10pt]{article}
\usepackage{minted}
\makeatletter
% avoid space tokens since we're in horizontal mode
\renewcommand\mint[3][]{%
\DefineShortVerb{#3}%
\minted@resetoptions
\setkeys{minted@opt}{#1}%
\SaveVerb[aftersave={%
\UndefineShortVerb{#3}%
\minted@savecode{\FV@SV@minted@verb}%
\minted@pygmentize{#2}%
\DeleteFile{\jobname.pyg}}]{minted@verb}#3}
\renewcommand\minted@savecode[1]{%
\immediate\openout\minted@code\jobname.pyg\relax
\immediate\write\minted@code{#1}%
\immediate\closeout\minted@code}
\renewcommand\minted@pygmentize[2][\jobname.pyg]{%
\def\minted@cmd{pygmentize -l #2 -f latex -F tokenmerge
\minted@opt{gobble} \minted@opt{texcl} \minted@opt{mathescape}
\minted@opt{linenos} -P "verboptions=\minted@opt{extra}"
-o \jobname.out.pyg #1}%
\immediate\write18{\minted@cmd}%
\ifthenelse{\equal{\minted@opt@bgcolor}{}}%
{}%
{\begin{minted@colorbg}{\minted@opt@bgcolor}}%
\input{\jobname.out.pyg}%
\ifthenelse{\equal{\minted@opt@bgcolor}{}}%
{}%
{\end{minted@colorbg}}%
\DeleteFile{\jobname.out.pyg}}
\makeatother
\RecustomVerbatimEnvironment{Verbatim}{BVerbatim}{}
\begin{document}
Ciao \mint[linenos]{c}/int a = 1;/ Prova
\begin{minted}[linenos]{c}
int a = 1;
\end{minted}
\end{document}
输出: