1

I'm using lstinputlisting to include code examples in my thesis, but as I'm working on the text and the code simultaneously, the code is not yet fixed in length. Is there any way that I can define a range of lines in my code dynamically so that the imported lines will be updated if I change the code (somehow as I'd do in iPython)?

At the moment I'm only using firstline= and lastline= as in this script example:

\lstinputlisting[language=Python, firstline=135, lastline=145]{code/inv1.py}

But when I add a line to my script, the range is out-of-phase with some funny results.

A dream scenario would be something like this pseudo code:

\lstinputlisting[language=Python, firstline=label{#loop2}, lastline=label{#end_loop2}]{code/inv1.py}

Can minted or another listing package be the solution? My code and scripts are in C# and Python.

3
  • 1
    See "6.7 Arbitrary linerange markers" in the documentation. Jun 17 '15 at 21:37
  • @Ulrike Thank you, I didn't expect it to be that easy! When knowing the terminology I also noticed that the question have been up before. tex.stackexchange.com/questions/53045/…
    – user2821
    Jun 17 '15 at 22:31
  • I think this question should be marked as duplicate rather than deleted, as I didn't find earlier occurrence when I searched for an answer.
    – user2821
    Jun 17 '15 at 22:35

Browse other questions tagged or ask your own question.