Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a white-on-black style for LaTeX listings

I've been looking at Philip Bunge's post on how to create a "Tango" style with LaTeX listings, and trying to adapt this to make the default text style white and the background black (this is for slides, not an article!). This is what I added:

\definecolor{Black}{gray}{0.0}
\definecolor{White}{gray}{0.9}
...
\lstset{
  basicstyle=\color{White},
  backgroundcolor=\color{Black},
  ...
}

This assumes that basicstyle sets the default style of all text. The listings documentation says this:

basicstyle is selected at the beginning of each listing. You could use \footnotesize, \small, \itshape, \ttfamily, or something like that. The last token of must not read any following characters.

The output of this still shows "default" text as black. It is possible to set more style directives that cover most tokens in a given programming language, but even doing this some tokens (such as brackets and other punctuation) will be missed. What did I do wrong?

like image 802
snim2 Avatar asked Jun 28 '10 13:06

snim2


1 Answers

The following code worked for me, but I converted the .dvi file to a .pdf in order to have the text appear as white, so it might have been your viewer? I'm using xdvi and xpdf.

\documentclass[a4paper, 11pt]{article}
\usepackage{listings}
\usepackage{color}
\definecolor{theWhite}{gray}{0.9}
\definecolor{theBlack}{gray}{0.0}
\lstset { basicstyle=\color{theWhite}, backgroundcolor=\color{theBlack} }
\begin{document}
\begin{lstlisting}
((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
\end{lstlisting}
\end{document}

I hope that helps!

like image 184
emptyset Avatar answered Oct 21 '22 11:10

emptyset