Pedro's blog: db2, mysql, php, linux and performance


Listings code on Latex – XSLT
09/12/2009, 17:47
Filed under: Latex | Tags: , , ,

Using the package listings you can add non-formatted text as you would do with \begin{verbatim} but its main aim is to include the source code of any programming language within your document.  Wikibooks

One of the problems of this package is the poor colored syntax with some programming languages, like XML or XSLT, trying language=XML and language=XSLT, the result was… bullshit poor, I prefere to use language=HTML because it has a minimal pretty syntax  and I made some changes, the result:

\lstnewenvironment{fakeXML}[1][]{
\lstset{basicstyle=\scriptsize\sffamily,
linewidth=0.90\linewidth,
numbers=left,
stepnumber=1,
numbersep=10pt,
frame=single,
framerule=1.0pt,
backgroundcolor=\color{darkgray},
language=HTML,
identifierstyle=\color[rgb]{1,0,0},
emph={schema, element, complexType, choice, simpleType, sequence, restriction, pattern}, emphstyle=\color{red},
keywordstyle=\color[rgb]{0,0,1},
commentstyle=\color[rgb]{0.133,0.545,0.133},
stringstyle=\color[rgb]{0.627,0.126,0.941},
morekeywords={xml, ref, xs, version, targetNamespace, minOccurs, maxOccurs}
}\lstset{#1}}{}

\begin{fakeXML}
<?xml version=”1.0″?>
<xs:schema targetNamespace=…

</xs:schema>
\end{fakeXML}

It looks like:

Listings and XML

Another problem solved! 😆