Skip to content

Instantly share code, notes, and snippets.

@kroger
Created August 2, 2013 14:12
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kroger/6140188 to your computer and use it in GitHub Desktop.
Save kroger/6140188 to your computer and use it in GitHub Desktop.
Print python code using LaTeX as described here: http://pedrokroger.net/2011/04/printing-python-code-with-latex
\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
\renewcommand*\familydefault{\ttdefault}
\usepackage{listings}
\lstset{
language=Python,
showstringspaces=false,
formfeed=\newpage,
tabsize=4,
commentstyle=\itshape,
basicstyle=\ttfamily,
morekeywords={models, lambda, forms}
}
\newcommand{\code}[2]{
\hrulefill
\subsection*{#1}
\lstinputlisting{#2}
\vspace{2em}
}
\begin{document}
\begin{lstlisting}
def factorial(n):
"""The factorial of a number the slow way"""
# comments are printed in italic
if n == 0:
return 1
else:
return n * factorial(n-1)
\end{lstlisting}
%% Use this to include files
%% \code{Models}{../testapp/models.py}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment