I have looked at the following:
- Suppress line numbering for empty lines in listings package
- Suppress line numbering for specific lines in listings package
However, the solution given in the latter thread only skips the line after the |\Suppressnumber|
command is given, and likewise, only resumes numbering after the |\Reactivatenumber|
command is given. In other words, this gives a range of skipped numbers.
What I'd like is:
- the line number to be suppressed for empty lines (and the counter not incremented: this problem is solved in the first post above);
- for specified lines only, not a range, to have their line numbers suppressed without incrementing the counter.
Using some very contrived C, for instance, this is what I would like to have:
\begin{lstlisting}
int main () { |\Suppressnumber|
1 printf("hello\n");
2 while (1) {
3 ;
4 if (0) {
5 ;
} else { |\Suppressnumber|
6 int b;
7 scanf("%d", &b);
} |\Suppressnumber|
} |\Suppressnumber|
} |\Suppressnumber|
\end{lstlisting}
I have experimented with most of the relevant hooks in listings
, including EveryLine
, EOL
, EveryPar
, InitVarsBOL
and InitVarsEOL
, and I can't think of a way to do this.