I use a lot of code in my lectures, in many different programming languages.
I use highlight to generate HTML (via ikiwiki) for web pages.
For class presentations, I mostly use the beamer LaTeX class.
In order to simplify generating overlays, I wrote a perl script hl-beamer.pl to preprocess source code. An htmlification of the documention/man-page follows.
NAME
hl-beamer - Preprocessor for hightlight to generate beamer overlays.
SYNOPSIS
hl-beamer -c // InstructiveExample.java | highlight -S java -O latex > figure1.tex
DESCRIPTION
hl-beamer looks for single line comments (with syntax specified by -c) These comments can start with @ followed by some codes to specify beamer overlays or sections (just chunks of text which can be selectively included).
OPTIONS
-c commentstring Start of single line comments
-k section1,section2 List of sections to keep (see @( below).
-s number strip number spaces from the front of every line (tabs are first converted to spaces using Text::Tabs::expand)
-S strip all directive comments.
CODES
@( section named section. Can be nested. Pass -k section to include in output. The same name can (usefully) be re-used. Sections omit and comment are omitted by default.
@) close most recent section.
@< [overlaytype] [overlayspec] define a beamer overlay. overlaytype defaults to visibleenv if not specified. overlayspec defaults to +- if not specified.
@> close most recent overlay
EXAMPLE
Example input follows. I would probably process this with
hl-beamer -s 4 -k encodeInner
Sample Input
// @( omit
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;
import java.util.Scanner;
// @)
// @( encoderInner
private int findRun(int inRow, int startCol){
// @<
int value=bits[inRow][startCol];
int cursor=startCol;
// @>
// @<
while(cursor<columns &&
bits[inRow][cursor] == value)
//@<
cursor++;
//@>
// @>
// @<
return cursor-1;
// @>
}
// @)
BUGS AND LIMITATIONS
Currently overlaytype and section must consist of upper and lower case letters and or underscores. This is basically pure sloth on the part of the author.
Tabs are always expanded to spaces.