1

I'm using minted to show pieces of code in my document. Some of the code has skipped line numbers. The resulting problem is that listings with skipped line numbers have different line number formatting than the ones without.

Example with skipped lines

The minted documentation and this StackExchange question shows a way to modify the theFancyVerbLine command to change the formatting. However that won't effect the listings with line skips.

Renewed the FanceVerb environment

I tried combining the two approaches but that would duplicate the line numbers. What do I miss from the minted documentation?

Thanks in advance.


Minimal working example:

% arara: xelatex: {shell: yes }
\documentclass{scrreprt}
\usepackage{minted}

\renewcommand{\theFancyVerbLine}{\textcolor[rgb]{0.5,0.5,1.0}{\footnotesize\arabic{FancyVerbLine}}}

\begin{document}

\begin{listing}[H]
    \begin{minted}[linenos]{py}
import bar from foo

print("Hello %s!" % "World")
    \end{minted}
\end{listing}

\begin{listing}[H]
    \renewcommand\theFancyVerbLine{%
    \ifnum\value{FancyVerbLine}=2
        \setcounter{FancyVerbLine}{125}\ldots
    \else
    \arabic{FancyVerbLine}%
    \fi
    }
    \begin{minted}[linenos]{py}
import deep_thought as dt

print("The answer is %s!" % dt.getAnswerTo("everything"))
    \end{minted}
\end{listing}

\end{document}

1 Answer 1

2

The required modification is to replace \arabic{FancyVerbLine} in the second listing with the definition above, i.e., \textcolor[rgb]{0.5,0.5,1.0}{\footnotesize\arabic{FancyVerbLine}}.

Furthermore you can color the dots and make them vertical.

MWE:

\documentclass{scrreprt}
\usepackage{minted}

\renewcommand{\theFancyVerbLine}{\textcolor[rgb]{0.5,0.5,1.0}{\footnotesize\arabic{FancyVerbLine}}}

\begin{document}

\begin{listing}[H]
    \begin{minted}[linenos]{py}
import bar from foo

print("Hello %s!" % "World")
    \end{minted}
\end{listing}

\begin{listing}[H]
    \renewcommand\theFancyVerbLine{%
    \ifnum\value{FancyVerbLine}=2
        \setcounter{FancyVerbLine}{125}\color[rgb]{0.5,0.5,1.0}\vdots
    \else
    \textcolor[rgb]{0.5,0.5,1.0}{\footnotesize\arabic{FancyVerbLine}}%
    \fi
    }
    \begin{minted}[linenos]{py}
import bar from foo

print("Goodbye %s!" % "World")
    \end{minted}
\end{listing}

\end{document}

Result:

enter image description here

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.