Today I decided to learn more about the Template-Toolkit. I am the kind of person that can learn the first steps better when I read things on paper. Reading from screen is fine for me for looking up a reference, but reading long texts is a pain. Regardless if it is a CRT or a TFT display.

The docs of Template Toolkit are, as of many Perl modules, splitted in many small chunks, which is also fine for reference, but a pain to print out.

So I decided to put the stuff together in a Word (/me ducks) file and make a pdf out of it, so i can share it with people. I planned to make it in three parts. The manual and the tutorial consist of a few documents so i did them by hand. I copied the relevant parts from the HTML-doc and inserted them into Word, changed headings, inserted pagebreaks, did some pageformatting and printed it to a pdf.

So far so good. But when I came to the reference I realized that there are far too many files to do it conviniently by hand. Solution: script it.

Here is the script I used for the issue. It uses regexes to deal with the html, but since Active States HTML-Docs are computer generated I think that is ok in this case :-D
my @f = ( "c:/perl/html/site/lib/Template.html", "c:/perl/html/site/lib/Template/Base.html", #... "c:/perl/html/site/lib/Template/Plugin/XML/Style.html", "c:/perl/html/site/lib/Template/Plugin/XML/XPath.html", ); open OUT, ">ref.html"; print OUT <<"HTML"; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w"> <html xmlns=""> <head> <title>Template::Config - Factory module for instantiating other TT2 m +odules</title> <link rel="stylesheet" href="Active.css" type="text/css" /> <link rev="made" href="mailto:" /> </head> <body> <table border="0" width="100%" cellspacing="0" cellpadding="3"> <tr><td class="block" valign="middle"> <big><strong><span class="block">&nbsp;Template::Config - Factory modu +le for instantiating other TT2 modules</span></strong></big> </td></tr> </table> <p> HTML for my $f ( @f ) { #trigger $i=0; open IN, $f or die "$f: $!"; while ( <IN> ) { $i=1 if /<!-- INDEX END -->/; $i=0 if /<h1><a name="authors?">/; #tweak the NAME heading my $ff = $f; $ff =~ s/^.+Template/Template/; $ff =~ s/\.html//; $ff =~ s/\//::/g; s/<h1><a name="name">NAME<\/a><\/h1>/[[[PB!]]]<h0><a name="nam +e">$ff<\/h0>/; s/<hr \/>//g; #tweak headings one step smaller s/(<\/?h)([0-9])(>)/$1.($2+1).$3/eg; print OUT $_ if $i; } } print OUT "</body></html>";
That worked fine. All I had to do manually was replacing the [[[PB!]]] parts with pagebreaks using the "search and replace" functionality of Word, formatting the pages and adding a autogenerated Table of Contents. Et voila, a full fledged book. :-)

As you may have noticed, the html relies on a external stylesheet, so you can even tweak the formatting to you your liking.

I will put the six Files (TT-Manual-Single, TT-Manual-Double, TT-Tutorial-Single, TT-Tutorial-Double, TT-Reference-Single and TT-Reference-Double) on my webspace at as soon as I get home, since I cannot ssh from work.

The difference between "Double" and "Single" here is that one is optimized for double paged print, the other for single page print.

The files are now available at There is a 20MB transfer limit per day on jcwren's server, so please be kind if it does not work for you. Just try the other day.

holli, /regexed monk/