Lastly I tried the Solarized color theme for Emacs which provides a nifty color scheme (for light or dark backgrounds). This led me to wonder whether I could use this theme for highlighting code chunks in my $\LaTeX$ documents.
Although it looks great, I gave up on it for Emacs because I had difficulties reading my text with the base color for body text (base0
or base00
, depending on the background color). Also, I don’t like having different emphasizes for the same code identifier, e.g. <a href=
where color for <
is different than for a
.
Pygmentize is very great, and the Minted $\LaTeX$ package is based on it. I already dropped some words on it. According to the documentation, it is possible to customize the output and add our own formatter. Let’s try a simplified style:
from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Token
class SolarizedStyle(Style):
background_color = "#fcf4dc"
default_style = ""
styles = {
Token: '#52676f',
Comment: '#465a61',
Operator: '#728a05',
Keyword: '#728a05',
Name: "#a57705",
Name.Builtin: '#2075c7',
Name.Function: '#2075c7',
Name.Class: '#2075c7',
String: '#259185',
Number: '#c61b6e'
}
Then, we need to put this in the pygments/styles/
folder, in Python site-packages
. To check that it works,
>>> from pygments.styles import get_style_by_name
>>> get_style_by_name('solarized')
It should return something like
pygments.styles.solarized.SolarizedStyle
We can test it with a little Python script, e.g. par_checker.py. Below, from left to right are the simplified solarized theme, and the built-in colorful and Tango themes.
I must admit that I still like how the Tango palette looks like. Now, here is how it looks under my Emacs (left, solarized; right, my custom tango palette):
Well, I have to test it into a $\LaTeX$ paper.
The Tango palette is great. And it is with great irony that I have to use VIM to beautify my code that I’m typing in Emacs. Indeed, as I like working with Context, instead of $\LaTeX$, I was in need of an efficient solution for syntax highlighting. Despite my best efforts with on-line wiki, I raised the question on http://tex.stackexchange.com, see Code highlighting in ConTeXt. At the time I asked on tex.SE, I wasn’t able to get it because of my outdated version of Context. Once I updated to the svn version, everything worked well per @Aditya’s solution.
Let’s wrap the above code like this:
\usemodule[vim]
\starttext
\definevimtyping [PYTHON] [syntax=python]
\startPYTHON
### Put code here ###
\stopPYTHON
\stoptext
Then, run it:
$ context par_checker.tex
I got the following PDF: