Monday, November 28, 2011

XML Higlighting in Latex + using it in a figure

It's been a while that I did not have time to write something.. It doesn't mean that I don't have anything to write about.. and.. of course I have! :)

I'm busy with writing my thesis using Latex, it's sometimes a great tool to use.. And other times, you're getting really frustrated to achieve what you really wanna do!


This time I was trying to simply put an XML content in a table/figure or such, because I needed to refer to it later on in my thesis.. I cannot just put the content as it is.. If you are in trouble just like me, am sure you found two great XML highlighters: "minted" and using "listings" package. Both work like a charm, but the problem is when you wanna put XML content in a table/figure. Well, highlighting sucks in such cases.

One solution that I found is as the following:

\begin{figure}[htbp]
\begin{minted}{xml}
   <book isbn="978-0452284234"> 
      <name<Nineteen Eighty Four</name>
      <author<George Orwell</author>
   </book>
\end{minted}
\caption[XML Representation Example]{XML Representation Example}
% \vskip
\label{fig:xml}
\end{figure}

I did not try for "listings" package, but I think it will also work.. With this, you'll get a result as the following:
Photobucket

Hope it helps!..

No comments: