# Skip line number in listing doesn't work

I'm trying to skip some line numbers in my listing but it doesn't work. I followed this guide Skip line numbers and resume from specific number ... don't know why it's not working.

The new line number always shows in my border. Hope someone can help me.

This is my code:

\documentclass{article}
\usepackage{listings}
\usepackage{color}
\usepackage{xcolor}

\colorlet{punct}{red!60!black}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{delim}{RGB}{20,105,176}
\colorlet{numb}{magenta!60!black}

\let\origthelstnumber\thelstnumber
\makeatletter
\newcommand*\Suppressnumber{%
\let\thelstnumber\relax%
}%
}

\newcommand*\Reactivatenumber{%
\let\thelstnumber\origthelstnumber%
}

\makeatother
\begin{document}
\begin{lstlisting}[language=c++,basicstyle=\footnotesize\sffamily,
showstringspaces=false,
breaklines=true,
frame={leftline,bottomline,rightline,topline},
backgroundcolor={\color{background}},numbers=left,xleftmargin=15pt, firstnumber=195,caption={This is a test beginning with line 195 },label=lst:code,captionpos=b,escapeinside=||]
while (player->moveNext()) {
StringName term = player->get();

if (bla.exp) {
bla.exp *= 2;
} else {
bla.exp = 1;
}
term++;
}|\Suppressnumber|

// ...
|\Reactivatenumber{214}|
// this is a very (SHOULD START AT 214)
// long
// comment

double etc = 0.6 * (x/y) - speedlimit;
\end{lstlisting}
\end{document}


And it's always pushing the new line number inside the box like this:

Hope someone can help me :)

• Your \Reactivatenumber command has no argument, but your using it with {214}, that's why the number 214 appears in the listing text
– user31729
Aug 24, 2017 at 18:02
• Oh .. yes i see.. what a horrible mistake thanks @ChristianHupfer It's working now!
– mtzE
Aug 24, 2017 at 18:09

There are two logic errors in there:

• |\Reactivatenumber{214}| is used as a macro with argument but it is not defined as such, so 214 is no argument but just a token that is left in the input stream, appearing as text in the listings.
• The other one is that the lstnumber counter is never set to 214 there, so this must be done with \setcounter{lstnumber}{214} or \global\c@lstnumber=#1, followed by a decrease by one then.

\newcommand\Reactivatenumber[1]{%
\global\c@lstnumber#1%
\let\thelstnumber\origthelstnumber%
}%
}


Here is the final code:

\documentclass{article}
\usepackage{listings}
\usepackage{color}
\usepackage{xcolor}

\colorlet{punct}{red!60!black}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{delim}{RGB}{20,105,176}
\colorlet{numb}{magenta!60!black}

\let\origthelstnumber\thelstnumber
\makeatletter
\newcommand*\Suppressnumber{%
\let\thelstnumber\relax%
}%
}

\newcommand\Reactivatenumber[1]{%
\global\c@lstnumber#1%
\let\thelstnumber\origthelstnumber%
}%
}
\makeatother

\begin{document}
\begin{lstlisting}[language=c++,basicstyle=\footnotesize\sffamily,
showstringspaces=false,
breaklines=true,
frame={leftline,bottomline,rightline,topline},
backgroundcolor={\color{background}},numbers=left,xleftmargin=15pt, firstnumber=195,caption={This is a test beginning with line 195 },label=lst:code,captionpos=b,escapeinside=||]
while (player->moveNext()) {
StringName term = player->get();

if (bla.exp) {
bla.exp *= 2;
} else {
bla.exp = 1;
}
term++;
}|\Suppressnumber|
// ...
|\Reactivatenumber{214}|
// this is a very (SHOULD START AT 214)
// long
// comment

double etc = 0.6 * (x/y) - speedlimit;
\end{lstlisting}
\end{document}