Tuesday 23 October 2007

Source code in LaTeX

If you want to include some source code into a LaTeX-document, you can of course use the verbatim environment. It can be useful to refer to an external file rather than copy & paste the source into the LaTeX-file.

To refer to an external file (which has the advantage that you do not need to apply modifications in two places) can be done by using the moreverb package: insert
\usepackage{moreverb}
at the beginning of your document. I use the following macro
\newcommand{\listscript}[1]{{\footnotesize\verbatiminput{#1}}}


You can now use
\listscript{ex5.m}
in your document if you want to include the source text in the file ex5.m.

No comments: