Monday, March 5, 2012

Latex - Beamer + minted + Pygments

The minted package allows you to highlight source code according to its language type by using pygments.
http://tug.ctan.org/tex-archive/macros/latex/contrib/minted/

rene@linux-2561:~> sudo zypper in python-Pygments
rene@linux-2561:~/bin> unzip minted.zip 
Archive:  minted.zip
   creating: minted/
  inflating: minted/minted.dtx       
  inflating: minted/minted.ins       
  inflating: minted/minted.pdf       
  inflating: minted/README           
  inflating: minted/Makefile 
rene@linux-2561:~/bin/minted> python --version
Python 2.7.2
rene@linux-2561:~/bin/minted> make
tex minted.ins
This is TeX, Version 3.1415926 (TeX Live 2011)
(./minted.ins (/usr/share/texmf/tex/latex/base/docstrip.tex
Utility: `docstrip' 2.5d <2005/07/29>
English documentation    <1999/03/31>

**********************************************************
* This program converts documented macro-files into fast *
* loadable files by stripping off (nearly) all comments! *
**********************************************************

********************************************************
* No Configuration file found, using default settings. *
********************************************************

)

Generating file(s) minted.sty 

Processing file minted.dtx (package) -> minted.sty
Lines  processed: 1296
Comments removed: 994
Comments  passed: 0
Codelines passed: 296

 )
No pages of output.
Transcript written on minted.log

rene@linux-2561:~/bin/minted> sudo cp minted.sty /usr/share/texmf/tex/latex/minted/

rene@linux-2561:~> sudo texhash
texhash: Updating /etc/texmf/ls-R... 
texhash: Updating /var/lib/texmf/main/ls-R... 
texhash: Updating /usr/share/texmf/../../../var/lib/texmf/dist/ls-R... 
texhash: Updating /var/cache/texmf/fonts/ls-R... 
texhash: Updating /var/lib/texmf/ls-R... 
texhash: Done.

This is what I've got so far:



Source
\documentclass[slidestop,compress,mathserif]{beamer}
\usepackage{minted}
\usetheme{Antibes}
\usecolortheme{lily}
\title{PostgreSQL}
\author{@darwinian}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}[fragile]
\begin{itemize}
\item Generating factorials
\end{itemize}
\begin{minted}{sql}
WITH RECURSIVE source (counter,product) AS
 ( SELECT 1,1 UNION ALL
     SELECT counter +1 , product * (counter +1)
         FROM source WHERE counter < 10)
SELECT counter, product FROM source;
\end{minted}
\end{frame}
\end{document}
Other references: http://en.wikibooks.org/wiki/LaTeX/Packages/Installing_Extra_Packages

No comments:

Post a Comment