This example shows how to produce PDF slides with syntax highlighting of source code. The example uses beamer and (presumably) pdflatex.

Another example shows syntax coloring for HTML output using htlatex. It's an unpleasant kludge
- it precludes calling
pdflatexon the same LaTeX file - one must experiment to find what
ectt-1000maps to - one defines colors for css categories, not for code syntax categories
but it works.
The following code revisits this problem and asks to do better.
\documentclass{article}
\usepackage{color}
\usepackage{listings}
\usepackage[T1]{fontenc}
\lstset{
basicstyle=\ttfamily,
language=C++,
keywordstyle=\rmfamily\bfseries,
commentstyle=\sffamily,
}
\begin{document}
\Css{div.lstlisting .ectt-1000 {font-family: monospace;color:blue}}
\Css{div.lstlisting .ecss-1000 {font-family: monospace;color:green}}
\Css{div.lstlisting .ecbx-1000 {font-family: monospace;color:red}}
\section*{Inserting source code}
\begin{lstlisting}
#include<stdio.h>
#include<iostream>
// A comment
int main(void)
{
printf("Hello World\n");
return 0;
}
\end{lstlisting}
\end{document}
Now commenting out the \Css lines and running pdflatex gives one output

and processing with htlatex gives another.

Can you suggest a way to make this kludge more usable by
- correlating the two "blue" colors—even though ultimately one is defined in LaTeX's color package and the other in HTML,
- making the
\Cssdefinitions point to colors through syntax category, - making it possible to process the file with
pdflatexwhile writing/for debugging (htlatexis considerably slower)
?
