4

This question has already been asked for the package listings, but I am using minted and want to achieve the same thing.

My document looks as follows:

\documentclass{article}
\usepackage{minted}

\begin{document}

\begin{minted}[breaklines=true,linenos]{javascript}
/* My Code: */

console.log("Hello");

console.log("World");
console.log("FooBar");

console.log("BarFoo");
console.log("FooFoo");

\end{minted}

\end{document}

This gives me the following output:

Minted_LaTeX_skip_line_numbers

However, I want to have the following result:

1  | /* My Code: */
...|
128| console.log("Hello");
...|
188| console.log("World");
189| console.log("FooBar");
...|
201| console.log("BarFoo");
202| console.log("FooFoo");

How can this be done?

1 Answers1

5

enter image description here

\documentclass{article}
\usepackage{minted}

\begin{document}

\renewcommand\theFancyVerbLine{%
\ifnum\value{FancyVerbLine}=2 
  \setcounter{FancyVerbLine}{127}\ldots
\else\ifnum\value{FancyVerbLine}=129
  \setcounter{FancyVerbLine}{187}\ldots
\else\ifnum\value{FancyVerbLine}=190
  \setcounter{FancyVerbLine}{200}\ldots
\else
\arabic{FancyVerbLine}%
\fi
\fi
\fi
}
\begin{minted}[breaklines=true,linenos]{javascript}
/* My Code: */

console.log("Hello");

console.log("World");
console.log("FooBar");

console.log("BarFoo");
console.log("FooFoo");

\end{minted}

\end{document}
David Carlisle
  • 757,742
  • Thank you! This works for perfectly, but now all of my other code snippets also have that numbering. How can I reset it or limit it to one specific minted? – John Doe Jul 19 '17 at 15:49
  • @JohnDoe yes the definition of \theFancyVerbLine is local so you can do it inside any existing group (eg if this is in figure or just surround by { ..renewcommand...begin minted ...end minted ...} so it is restored at the } – David Carlisle Jul 19 '17 at 15:58
  • What an ugly hack. I love it :-) – bp99 Oct 24 '21 at 20:58
  • 2
    @bp99 I believe you have a typo and you intended to write "brilliantly engineered solution" – David Carlisle Oct 24 '21 at 21:17