# Suppress line numbering for specific lines in listings package

I would like to suppress the line numbering for specific lines in listings package by identifying the specific lines using some kind of command.

-
Please accept answers. In your previous question there are 2 answers without any response: tex.stackexchange.com/questions/33999/… –  Marco Daniel Nov 8 '11 at 12:15

It isn't such simple as it sounds. You have to hook every line. Here a small solution which needs more testing:

\documentclass{article}
\usepackage{listings}

\lstset{numbers=left,numberblanklines=false,escapeinside=||}
\let\origthelstnumber\thelstnumber
\makeatletter
\newcommand*\Suppressnumber{%
\let\thelstnumber\relax%
}%
}

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

\makeatother
\begin{document}

\begin{lstlisting}
First line.
Second line.|\Suppressnumber|
Third line.
Next line.|\Reactivatenumber|
Next Line
\end{lstlisting}
\end{document}


Next time please provide an example. I took this one from you previous question.

-
Sorry for not providing an example; I felt my question was simple. Anyhow, thank you very much for the answer. I tried it and got the following result: –  user9131 Nov 8 '11 at 17:32
I suppose that you do not need the \global and why do you have all the \relax after the let statement? –  Herbert Nov 8 '11 at 17:41
@Herbert: The \relax is obsolete. I know this. I don't know why I haven't changed it. -- I tested without global and it works. –  Marco Daniel Nov 8 '11 at 17:48
Everything worked, except the line numbers were not suppressed, but the line number was just repeated so I saw 1 xxx 2 xxx 2 xxx 3 xxx. –  user9131 Nov 8 '11 at 17:58
@user9131: Marco's example works fine, showing that there's no line number printed after |\Suppressnumber|. What did you do differently? Did you receive any warnings in your .log? Perhaps you have an older version of listings - currently at 1.4. To see whether this is the case, add \listfiles before \documentclass and check your .log file after *File List*. –  Werner Nov 8 '11 at 18:33