LaTeX listings: Eclipse colors
This is the style I use to highlight my Java code in LaTeX documents with the Listings package, with Eclipse colors:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
% Colors for code highlighting according to the Eclipse default theme \definecolor{keywordColor}{rgb}{0.5, 0, 0.33} \definecolor{commentColor}{rgb}{0.25, 0.5, 0.35} \definecolor{stringColor}{rgb}{0.16, 0, 1} \definecolor{numberColor}{rgb}{0, 0, 0} % Color style \lstdefinestyle{mystyle}{ flexiblecolumns=true, keepspaces=true, tabsize=4, showstringspaces=false, basewidth={0em,0em},, numbers=left, basicstyle=\scriptsize, numberstyle=\color{numberColor}, commentstyle=\color{commentColor}\itshape, stringstyle=\color{stringColor}\ttfamily, keywordstyle=\color{keywordColor}\bfseries, } |
And this is an example of a document, where I show the same listing both with black and white colors an Eclipse colors:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
\documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} % not needed on XeLaTeX/LuaLaTeX \usepackage{xcolor} \usepackage{listings} % Colors for code highlighting according to the Eclipse default theme \definecolor{keywordColor}{rgb}{0.5, 0, 0.33} \definecolor{commentColor}{rgb}{0.25, 0.5, 0.35} \definecolor{stringColor}{rgb}{0.16, 0, 1} \definecolor{numberColor}{rgb}{0, 0, 0} % Color style \lstdefinestyle{mystyle}{ flexiblecolumns=true, keepspaces=true, tabsize=4, showstringspaces=false, basewidth={0em,0em},, numbers=left, basicstyle=\scriptsize, numberstyle=\color{numberColor}, commentstyle=\color{commentColor}\itshape, stringstyle=\color{stringColor}\ttfamily, keywordstyle=\color{keywordColor}\bfseries, } % Black and white style \lstdefinestyle{mystylebw}{ flexiblecolumns=true, keepspaces=true, tabsize=4, showstringspaces=false, basewidth={0em,0em},, numbers=left, basicstyle=\scriptsize, commentstyle=\itshape, stringstyle=\ttfamily, } \begin{document} \section*{Demo} With the default black and white style: \begin{lstlisting}[language=Java,style=mystylebw] // A simple Java program class Demo { public static void main(String[] args) { System.out.println("Hello, world!"); } } \end{lstlisting} \noindent With the color style: \begin{lstlisting}[language=Java,style=mystyle] // A simple Java program class Demo { public static void main(String[] args) { System.out.println("Hello, world!"); } } \end{lstlisting} \end{document} |
Here’s the result: