Bug#569576: texlive-latex-recommended: listings package shows wrong line numbers in file listings
On Tue, 16 Feb 2010 09:52:35 +0100 Norbert Preining wrote:
> On Fr, 12 Feb 2010, Vsevolod Krishchenko wrote:
> > In texlive-2007 (lenny) listings packages has typed a correct line number in a file listing.
> > For example, '\lstinputlisting[firstline=20, lastline=25]{..}' command starts numeration from '20'.
> >
> > In texlive-2009 (squeeze), listing always starts with line number '1'.
> > For example, '\lstinputlisting[firstline=20, lastline=20]{..}' starts line numbers from '1'.
> > So, listing first line will have a number '1' but in fact it is a line number '20'.
>
> Which is correct.
No it's not.
> > Due to this bug, any document using partial file listing will have invalid listings line numbers after recompilation.
>
> No this is not a bug.
Yes it is.
> Please read the documentation, I just *now* did it and found that
> you are not using the package in the right way.
>
> > % File 'test01.tex'
> > \documentclass[a4paper,10pt]{article}
> > \usepackage[utf8x]{inputenc}
> > \usepackage{listings}
> > \lstset{
> > numbers=left,
> > stepnumber=1
> > }
> > \begin{document} % this is a line number 9, not 1!
> > \lstinputlisting[firstline=9, lastline=11, language=TeX]{test01.tex}
> > \end{document}
>
> From the documentaiton:
> firstline=...
> lastline=...
> can be used on individual listings only. The given line ranges of the
> listing are displayed. The intervals must be sorted and must not intersect.
>
> There is *nothing* about the line*number* as printed!!!
>
> If you read a bit on in the documentation you come to
> 4.8 Line numbers
> and find:
>
> firstnumber=...
> auto lets the package choose the first number: a new listing starts with
> number one, a named listing continues the most recent same-named listing
> (see below), and a stand alone file begins with the number corresponding to
> the first input line.
> last continues the numbering of the most recent listing and number sets
> it to the number.
>
> So it clearly states that without any setting all listings start with
> number 1, unless you use firstnumber=whatever.
Read it again. It says
> auto lets the package choose the first number
and
> a stand alone file begins with the number corresponding to the first input line.
A "stand alone file" is a file included with "\lstinputlisting" and
the first input line is chosen with "[firstline=...]".
> So a simple solution is to
> \lstinputlisting[firstnumber=9, firstline=9, lastline=11, language=TeX]{test01.tex}
This is a workaround but no solution.
> Closing this bug.
Please open it again.
> Best wishes
>
> Norbert
Greetings,
Fabian
Reply to: