[Tex/LaTex] How to input part of a file in verbatim

codeinputverbatim

I'm writing the documentation to a large piece of Matlab code. I would like include tags in my Matlab code and then read the lines of code between the tags into Latex and output them as verbatim (or use some other form of code representation such as the lstlisting package).

I noticed that the catchfile package can help me with reading code as verbatim (as described here) and that the catchfilebetweentags package does essentially the other part of the job (as described in the answers to this question, yet I'm still struggling to do both simultaneously. Any ideas? Thank you.

Best Answer

I don't know how to use catchfilebetweentags. I would write a script to extract each code section into its own file, then use the mcode package to include the file in the doc.

You might find mcode useful anyway, since it does the matlab syntax highlighting for you.

\lstinputlisting{/SOME/PATH/FILENAME.M}
\lstinputlisting[firstline=6, lastline=15]{/SOME/PATH/FILENAME.M}