Add html preformatted text into latex

I am writing my thesis using LaTeX, and a would like to add some code in it. I tried so far the listings by I am not satisfied with the result. Is there a way to add a pre-formated code in HTML into LaTeX?

I want to take my code from Kate as a pre-formated text in HTML and put it into my thesis text. Is that possible?

For example I have the following code in C:

struct cpu_info {
long unsigned utime, ntime, stime, itime;
long unsigned iowtime, irqtime, sirqtime;
};


I copy from Kate that code as HTML. The contents of the clipboard are

<pre style='color:#141312;background-color:#ffffff;'>
<b>struct</b> cpu_info {
<span style='color:#0057ae;'>long</span> <span style='color:#0057ae;'>unsigned</span> utime, ntime, stime, itime;
<span style='color:#0057ae;'>long</span> <span style='color:#0057ae;'>unsigned</span> iowtime, irqtime, sirqtime;
};</pre>


I want to insert this code in Latex in order to produce the formatted text of the above HTML code without using listings if it is possible.

My code is written in C so if anyone has a good lstset for C, that would be also great for me.

I use \documentclass[a4paper,10pt]{article}.

-

migrated from stackoverflow.comOct 24 '11 at 22:21

This question came from our site for professional and enthusiast programmers.

maybe try the verbatim environment... –  phimuemue Oct 24 '11 at 20:50
In which way does the output produced by listing not satisfy you? –  Paŭlo Ebermann Oct 24 '11 at 21:27
In order to achieve the same result with an editor formatting, it could take me hours to do, as it is the first time that I am using latex. I managed to make an lstset put its output is very poor. So I asked if there is out there any "quick" solution. –  Manos Oct 24 '11 at 21:42
XML/HTML isn't that well supported by listings. See XML syntax highlighting, which might be a duplicate. There is also the minted package which uses Pygments, a Python syntax highlighter, which might have better XML support. –  Martin Scharrer Oct 24 '11 at 22:27
Also, because your question got migrated from stackoverflow.com to us, please make sure you have a registered account on both sites so that they can be associated to each other. This is required so that you gain ownership of this question on this site. –  Martin Scharrer Oct 24 '11 at 22:31

If possible, I would just use the C code directly. Here is an example:

\documentclass[a4paper,10pt]{article}
\usepackage{xcolor}
\usepackage{listings}
\begin{document}
\lstset{
language=C,
basicstyle=\small\sffamily,
frame=tblr,
backgroundcolor=\color{yellow!20},
numbers=left,
xleftmargin=5.0ex,
numberstyle=\tiny,
numbersep=4pt,
stepnumber=2,
%showstringspaces=false,
keywordstyle=\color{blue}\bfseries
}

printf%
},emphstyle={\color{red}\bfseries}%
}%

\begin{lstlisting}
/* Hello World program */

#include<stdio.h>

struct cpu_info {
long unsigned utime, ntime, stime, itime;
long unsigned iowtime, irqtime, sirqtime;
};

main()
{
printf("Hello World");
}\end{lstlisting}
\end{document}

-
Closer to the original Kate formatting (but I'm not sure why it leaves 'struct' uncolored, but colors 'unsigned' and 'long', since they're all keywords): \definecolor{keyword}{HTML}{0057AE} \definecolor{basic}{HTML}{141312} \definecolor{background}{HTML}{FFFFFF} \lstset{language=C, backgroundcolor=\color{background}, basicstyle=\color{basic}\ttfamily, keywordstyle=\color{keyword}\bfseries, } –  Mike Renfro Oct 25 '11 at 16:39
I wasn't mimicking any formatting, just suggesting that it is better to simply use the C code directly rather than try to format the HTML version of the C code. –  Peter Grill Oct 25 '11 at 16:50
@pe I ended with your suggestion using C code directly. There was a problem with the code that overfilled the margins of my text, due to many nested code. The solution to that was to minimize the size of tabs. With a little search I found the tabsize parameter, set it to 2 and "Wohoooo" problem is gone. Thanks all for your help. –  Manos Oct 25 '11 at 18:00
@PeterGrill sure, I just added it in case the original poster got picky about specific colors matching what Kate produced. No doubt it's better to just use listings for C in any case. –  Mike Renfro Oct 26 '11 at 1:23