# LaTeX Listings Package, No Line Number for Comments

I am trying to get only the actual code to be line numbered rather than both code and comments. Example:

\lstset{basicstyle=\footnotesize, xleftmargin=40pt, frame =
single, numbers = left,caption = Test, label = list:Test}
\begin{lstlisting}[language = java,mathescape]
//Test comment
if( this = test)
print;
\end{lstlisting}
\vspace{2 mm}


Prints all line numbers for the comment as well.

-

I don't think it is possible to do what you want with the "listings" package. However, if it is worth your time you can break it up in sections and use a style for numbers and another for no-numbers. See the example below for one way of doing this.

\documentclass{article}
\usepackage{listings}
\begin{document}
\lstdefinestyle{numbers}
{numbers=left, stepnumber=1, numberstyle=\tiny, numbersep=10pt}
\lstdefinestyle{nonumbers}
{numbers=none}
\begin{lstlisting}[style=nonumbers]
// and more
\end{lstlisting}
\begin{lstlisting}[style=numbers]
for i:=maxint to 0 do
begin
{do some code}
end;
\end{lstlisting}
\begin{lstlisting}[style=nonumbers]