title: LaTeX: Lstlisting automatically recognizing code passage
body: <p>I am writing a program (in C, but I suppose that's not so relevant) in connection with a little documentary material in LaTeX. I want the documentary material to contain code snippets from my original code.</p>
  
  <p>In order to include source code and keep it up to date, I do the following in my document:</p>
  
  <pre><code>\lstinputlisting[firstline=200, lastline=210]{../src/source.c)
  </code></pre>
  
  <p>This loads automatically the lines 200 to 210 (which contain e.g. a function) from <code>../src/source.c</code> into my document. </p>
  
  <p>However, if I add some lines before line 200, this means that line 200 "wanders down some lines", so I have to adjust this in order to get my original function.</p>
  
  <p>So here's my question: Does anybody know about a possibility how to dynamically tell <code>lstinputlisting</code> (or any adequate substitute) to tell which lines to take?</p>
  
  <p>I imagine something like the following: I add special comments to my C source code that will be recognized by <code>lstinputlisting</code>, e.g.</p>
  
  <pre><code>/// lstinputlisting "myfunc" BEGIN
  int myFunction(int x){
    return x+2;
  }
  /// lstinputlisting "myfunc" END
  </code></pre>
  
  <p>Then, <code>lstlisting</code> scans the file and just includes the lines between the <code>BEGIN</code> and the <code>END</code> things.</p>