0

Using the following

\documentclass{article}

\usepackage{filecontents}
\usepackage{listings}

\begin{filecontents*}{src.code}
<ul>
   <!-- first -->
   <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
   <!-- end -->
   <li>Aliquam tincidunt mauris eu risus.</li>
   <!-- second -->
   <li>Vestibulum auctor dapibus neque.</li>
   <!-- end -->
</ul>
\end{filecontents*}

\begin{document}

\lstinputlisting[rangeprefix=<!--\ ,%
rangesuffix=\ -->,% 
language=HTML,
linerange={first-end,second-end},%
numbers=left,%
firstnumber=1,%
includerangemarker=false]{src.code}

\end{document}

I end up with the lines be numbered equally as 2 2. How can I have the lines in a given listing environment being numbered continuously starting with 1? ... whatever their "physical" split over multiple ranges might be.

3
  • Your usage of linerange seems a bit strange to me. For information on how to print certain lines of a given file, you can have a look at Using \lstinputlisting to include a file but only certain lines or line ranges
    – leandriis
    Mar 30 '18 at 9:23
  • How come that the use appears "strange"? I want to use range markers to extract portions of a source-code artifact (using markers, not line numbers), but in the resulting and rendered listing I want to have them numbered continuously (1, ..., n) ... regardless of their actual line numbers.
    – mrcalvin
    Mar 30 '18 at 12:26
  • I'm sorry. I've been overlooking the possibility of using range marker and only knew the possibility to use explicit line numbers (which in your case would lead to the desired output).
    – leandriis
    Mar 30 '18 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.