# Automated Code Listing Line Numbers

I want to automate source code examples in my documentation. Listing comes very close to doing this as it allows specification of start and ending line numbers:

\lstinputlisting[firstline=300,lastline=500]{file.cc}


However, source code tends to be a living document. I would love some way to markup my code with some kind of EXAMPLE_BEGIN and EXAMPLE_END type of tag in the comments and let that define the bounds for the listing.

If this isn't possible with a current package, I'm not opposed to writing one that does this. If that's the case, is there a good starting point? (i.e. Modifying Listing? Modifying Minted? Parsing with a macro?)

Quoted from listings documentation:.

Instead of using linerange with line numbers, one can use text markers. Each such marker consists of a , , and a . You once (or more) define prefixes and suffixes and then use the marker text instead of the line numbers.

\documentclass{article}

\usepackage{filecontents}
\usepackage{listings}

\begin{filecontents*}{livingdocument.txt}
Here some text which will not be included
EXAMPLE_BEGIN
1. All these texts will be included
2. All these texts will be included
3. All these texts will be included
EXAMPLE_END
Here some text as well which will not be included
\end{filecontents*}

\begin{document}

\lstinputlisting[linerange=EXAMPLE\_BEGIN-EXAMPLE\_END,includerangemarker=true]{livingdocument.txt}

\end{document}


(Those shifts must be coming from the default language settings.)

For more details please see Section 6.8 Multicolumn Listings in listings documentation.