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 Answer 1

4

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}
8
  • 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, 2017 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 } Jul 19, 2017 at 15:58
  • What an ugly hack. I love it :-)
    – bp99
    Oct 24, 2021 at 20:58
  • 1
    @bp99 I believe you have a typo and you intended to write "brilliantly engineered solution" Oct 24, 2021 at 21:17
  • 1
    @bp99 better to ask a new question Oct 24, 2021 at 21:29

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.