I'm a total latex noob, I would like to accomplish something similar to what has been asked here, but rather than resuming numbering from where it was left off, I'd like to pass the new line number as argument to the \Reactivatenumber
command. Sort of like this:
\documentclass{article}
\usepackage{listings}
\lstset{numbers=left,numberblanklines=false,escapeinside=||}
\let\origthelstnumber\thelstnumber
\makeatletter
\newcommand*\Suppressnumber{%
\lst@AddToHook{OnNewLine}{%
\let\thelstnumber\relax%
\advance\c@lstnumber-\@ne\relax%
}%
}
\newcommand*\Reactivatenumber{%
\lst@AddToHook{OnNewLine}{%
\let\thelstnumber\origthelstnumber%
\advance\c@lstnumber\@ne\relax}%
}
\makeatother
\begin{document}
\begin{lstlisting}
var myFunc = function() {|\Suppressnumber|
//my function does many great things
//and it's only 10 lines long!|\Reactivatenumber{12}|
}
\end{lstlisting}
\end{document}
To produce something like this (pardon formatting):
1 | var myFunc = function() {
| //my function does many great things
| //and it's only 10 lines long!
12 | }
What would be the right way to define the \Reactivatenumber
command? Cheers.
Best Answer
You can set the
lstnumber
counter to one less than the next line number inReactivatenumber
:Code: