#!/usr/bin/perl -w eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' if 0; # not running under some shell # Copyright 2002 Ed Avis, see the file COPYING. # Included with the package 'pip'. # =head1 NAME pip_latex2html - wrapper for latex2html to use it as a filter =head1 SYNOPSIS C =head1 DESCRIPTION pip_latex2html reads LaTeX source on standard input and writes an HTML document to standard output. It does this by running the latex2html command. =head1 BUGS latex2htmlE<39>s output is normally a collection of files: as well as the HTML page itself you have images, a CSS stylesheet and maybe other things. But this wrapper just outputs the HTML. In particular this means that images and equations cannot be included in the output. Then there are the shortcomings of latex2html itself, which cannot perfectly handle every type of LaTeX document. This is unavoidable since LaTeX markup is a complete (and very complex) programming language. =head1 AUTHOR Ed Avis, ed@membled.com. =cut use strict; use File::Temp qw(tempdir); my $VERSION = '1.2'; sub usage() { print STDERR <. END ; } foreach (@ARGV) { if (index('--help', $_) == 0) { usage(); exit(0); } elsif (index('--version', $_) == 0) { print STDERR <&STDOUT') or die "cannot dup stdout: $!"; open(STDOUT, '>&STDERR') or die "cannot dup stderr: $!"; system(qw(pip -i latex2html -split 0 -noascii_mode -nonavigation -notop_navigation -noaddress -noinfo -noimages -dir), $dir, '-.tex') && die "error running latex2html: $!"; open(STDOUT, '>&OLDOUT') or die "cannot dup stdout back again: $!"; my @made = grep { $_ ne 'index.html' } <*.html>; if (@made == 0) { die "latex2html failed to create an HTML output file\n"; } elsif (@made == 1) { my $f = $made[0]; open(FH, $f) or die "cannot open $f: $!"; # Remove stylesheet references. Should actually parse the HTML, # but can't be bothered. # while () { print unless /^\s*<\s*link\b[^>]*\brel\s*=\s*["']stylesheet['"][^>]*>\s*$/i; } close FH or die "cannot close $f: $!"; } elsif (@made >= 1) { die "latex2html created more than one HTML output file\n"; } else { die }