Python code in LaTeX
Including Python code in LaTeX papers is very simple and convenient with the “listings” package. Documentation of the package is part of the (awesome) LaTeX wikibook…
First, include the package in your document:
\documentclass{article} \usepackage{listings} \begin{document} \end{document}
And then insert code directly in the document:
\lstset{language=Python} \lstset{frame=lines} \lstset{caption={Insert code directly in your document}} \lstset{label={lst:code_direct}} \lstset{basicstyle=\footnotesize} \begin{lstlisting} from brg.datastructures import Mesh mesh = Mesh.from_obj('faces.obj') mesh.draw() \end{lstlisting}
Or add code from a file:
\lstinputlisting[language=Python]{mesh.py}