Slides with code, highlighting with latex

While preparing the slides for EuroPython, I decided to come back to Latex after more than 10 years from my thesis. The reason is that latex modules provide code syntax highlight – something unmanageable with libreoffice.

The `minted` package provides all that with just

def your_python(code):
    return here

You can shorten all that with a macro

# and you can even use
# math formulas $\sum_{x=0}^{n}x
in_comments = sum(range(n+1))

The hard issue I faced was to mark code (eg. like highlighter marking) because minted allows formatting only into comments. The following didn’t work.

# we wanted the append method to be emphasized, 
a = [1, 2]
# but the output was verbatim!

After some wandering I started from the ground. Minted package uses the python script pygment to convert code into a syntax-highlighted latex page:

#pygmentize -o out.tex -f latex -l python  -O full=true

So it was pygment to refuse interpreting latex formatting into the code. Luckily the latest development branch
Moreover I found in the pygment development branch, a patch allowing escape sequences into pygment.

# setting pipe (|) as an escapeinside character
def now_this(works):
# run with
#pygmentize -o out.tex -f latex -l python -O full=true,escapeinside="||"

After installing the last pygmentize from bitbucket, I just patched minted and enjoy the new syntax directly from latex

% set the pygmentize option in the 
%  latex page!
def now_this(works):