Wednesday, January 8, 2014

Colored code in org-mode export

To export org-mode code with more style controls, use (note the var name has changed recently and the old one doesn't work any more!):

(setq org-latex-listings t)

One can then tweak the styles. For example, mine for exporting to beamer is:

\definecolor{dkgreen}{rgb}{0,0.5,0}
\definecolor{dkred}{rgb}{0.5,0,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{blue(pigment)}{rgb}{0.2, 0.2, 0.6}
\lstset{
  basicstyle=\ttfamily\bfseries\footnotesize\color{blue(pigment)},
  morekeywords={virtualinvoke},
  keywordstyle=\color{blue}\bf,
  ndkeywordstyle=\color{red},
  commentstyle=\color{dkred},
  stringstyle=\color{dkgreen},
}

\makeatletter
\def\verbatim{\vspace{-0.3cm}\footnotesize\@verbatim \@vobeyspaces \@xverbatim}
\makeatother

Save the above code to a file, and then input this file to the org-beamer export:

#+LATEX: \input{the_above_file.tex}

And This is how it looks like:


No comments:

Post a Comment