GNU Source-highlight 2.5

by Lorenzo Bettini

This program, given a source file, produces a document with syntax highlighting.

Source-highlight reads source language specifications dynamically, thus it can be easily extended (without recompiling the sources) for handling new languages. It also reads output format specifications dynamically, and thus it can be easily extended (without recompiling the sources) for handling new output formats. The syntax for these specifications is quite easy (take a look at the manual).

Notice that source-highlight can also be used as a formatter (i.e., without highlighting): you can, for instance, format a txt file in HTML (and it will take care of translating special characters, such as, <, >, &).

Since version 2.2, source-highlight can also generate cross references; in order to do this it relies on GNU Ctags,

These are the output formats already supported:

These are the input languages (or input formats) already supported (in alphabetical order):

NOTICE: now the name of the program is source-highlight: there are no two separate programs, namely java2html and cpp2html, anymore.  However there are two shell scripts with the same name in order to facilitate the migration (however their use is not advised).

GNU Source-highlight is free software. Please see the file COPYING for details. For documentation, please read this file.

GNU Source-highlight is a GNU program and its main home page is at GNU site:

For further information, please consult the manual.

On-line Manual


You can download it from GNU's ftp site: or from one of its mirrors (see

I do not distribute Windows binaries anymore; since, they can be easily built by using Cygnus C/C++ compiler, available at However, if you don't feel like downloading such compiler, you can request such binaries directly to me, by e-mail (find my e-mail at my home page) and I can send them to you.
An MS-Windows port of Source-highlight is available from

Anonymous CVS Access

This project's CVS repository can be checked out through anonymous (pserver) CVS with the following instruction:
cvs -z3 co src-highlite
Further instructions can be found at the address:

Please notice that this way you will get the latest development sources of Source-highlight, which may also be unstable. This solution is the best if you intend to correct/extend this program: you should send me patches against the latest cvs repository sources.

If, on the contrary, you want to get the sources of a given release, through cvs, say, e.g., version X.Y.Z, you must specify the tag rel_X_Y_Z when you run the cvs command or the cvs update command.

When you compile the sources that you get through the cvs repository, before running the configure and make commands, you should, at least the first time, run the command:

     sh reconf

This will run the autotools commands in the correct order, and also copy possibly missing files. You should have installed recent versions of automake and autoconf in order for this to succeed. You will also need flex and bison.

NOTICE: This convention holds since release 2.1.

Changes in this release

What you need to build source-highlight

Since version 2.0 Source-highlight relies on regular expressions as provided by boost (, so you need to install at least the regex library from boost.  Most GNU/Linux distributions provide this library already in a compiled form.

Usage and examples

source-highlight only does a lexical analysis of the source code, so the program source is assumed to be correct!

Finally, there is texinfo documentation.  It is also available as an html file, and it is also available on-line.

Here we only show some examples of generated files.

Here are some links to some of the C and C++ sources of source-highlight colored with source-highlight itself:
generated with the following command
source-highlight -s cpp -f html --doc
And obviously it works with header file as well:
created with the command:
source-highlight -s cpp -f html *.h --css="mono.css"
Here are some examples of Java files processed with source-highlight (in most of them we have used the to make some test). Here's how Hello1.html, Hello2.html, Hello3.html, Hello4.html, Hello5.html, Hello_h_f.html, Hello_lines.html, Hello_xhtml.html, Hello_xhtml2.html, Hello_notfixed.html were created:
source-highlight -s java -f html -i -o Hello1.html
source-highlight -s java -f html --input --output Hello2.html --doc
source-highlight -s java -f html -i -o Hello3.html --title "Happy Java with java2html :-)" --tab 3
source-highlight -s java -f html < > Hello4.html --title "and what about CSS :-)" --css "Hello.css"
source-highlight -s java -f html < > Hello5.html --title "Wooo... this is quite dark ;-D" --css "mono-alt.css"
source-highlight -s java -f html --doc *.java
Processed   (creates
source-highlight -s java -f html --doc -i -o Hello_h_f.html --style-file="" --header="header.html" --footer="footer.html"
source-highlight -s java -f html --line-number --doc -i -o Hello_lines.html
source-highlight -s java -f xhtml --doc -i -o Hello_xhtml.html --css xhtml.css
source-highlight -s java -f xhtml --doc -i -o Hello_xhtml2.html --style-file
source-highlight -s java --outlang-def=html_notfixed.outlang -i -o Hello_notfixed.html --style-file
Here's another example:
Created with the command (notice that this one uses both CSS file and headers and footers):
source-highlight -s java -f html -i -o Hello_h_f.html 
            --header="./header.html" --footer="./footer.html"
Source-highlight can also generate HTML code to be embedded (i.e., copied and pasted) inside a Javadoc comment (or another kind of comment framework such as Doxygen).  This way, when you run javadoc on such a file, the resulting generated html documentation files will have the code snippets highlighted.  For instance, consider this piece of code,, representing an example of usage of the class SimpleClass; we would like to embed this code (formatted) into a javadoc comment of SimpleClass, so we process it with the option -f javadoc and we copy the result into the comment, as illustrated in When we process this file with javadoc, we obtain that code formatted in the documentation html file: SimpleClass-doc.html.  Doesn't it look nice :-)

Here's the output of source-highlight applied to a Prolog program (through the option `source-highlight -s prolog`:  This one is an highlighted Perl program (through the option `source-highlight -s prolog`):  Here's an highlighted PHP3 program: test.php3.html. And here's a Python program:  This the flex scanner for flex files flex_scanner.ll.html. This is a Ruby program: test.rb.html. This is a Javascript program test.js.html.  This is a Lua test program test.lua.html.  This is a Caml test program and this is an Sml test program test.sml.html

Here are some log files formatted using the color file

This is the language definition file for C/C++: cpp.lang.html, the one for the log files above, log.lang.html, and the language definition file for the language definition syntax itself: langdef.lang.html.

Here's the html output of formatted in html itself: test.htm.html.

and here's the output of formatted in html:

Finally, these HTML outputs contain cross references, test_refs.h.html, test_refs.cpp.html, generated with the following command:

source-highlight -s cpp -f html --title="Contains references to tags" 
--gen-references=inline test_refs.h test_refs.cpp


See CREDITS for detailed contributions and THANKS  for a complete list of people that helped me with Source-highlight :-)


Please tell me if you like this software :-)

Actually I want to extend it, so if you have some ideas...
The most import one will be to make source-highlight more powerful :-)

Please send all bug reports by electronic mail to:
bug-source-highlight at gnu dot org


Here's the list of TODO stuff, if you'd like to contribute :-)

Mailing Lists

The following mailing lists are available: if you want to subscribe to a mailing list just go to the URL and follow the instructions, or send me an e-mail and I'll subscribe you.

My home page is

source-highlight is free software. See the file COPYING for copying conditions. Anyway I won't get offended if you send me a postcard :-)

Return to GNU's home page.

Please send FSF & GNU inquiries & questions to There are also other ways to contact the FSF.

Please send comments on these web pages to, send other questions to

Copyright (C) 2001 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA

Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.

Updated:9 Jan 2001 mhw