Referencing line numbers in an external source file

by Chris Uchytil   Last Updated January 07, 2018 01:23 AM

This is a somewhat similar question to what was asked here: How can I reference line numbers in an external source file (e.g. C++) in a maintainable way? (I didn't want to respond to a question asked over 3 years ago) but I changed the escape characters to ^, I am using Python instead of C++, and I am using the lstinputlisting package. I followed the steps and it is very close to working. The issue I am having is that if I add

#lineref ^\label{test}^

at the appropriate point in the python file, when I reference this inside the latex file with


instead of giving me the line number it gives me the listing figure number (in this case 2.2). Is there a way to change this and get the line number instead?

Related Questions

Reference a line number in a document

Updated May 08, 2017 10:23 AM