#!/usr/bin/perl -w ## This is gen-resume, the LaTeX to XHTML converter for resume-sfllaw.tex. ## Copyright (C) 2002,2003 Simon Law ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA use strict; use warnings; my @footnotes; # Holds footnotes for later on my $depth = 0; # Holds the itemize depth my $item = 0; # Says whether we are in a list of items or not. my $document = 0; # We are still processing the preamble. # Print the header print < Simon Law's Résumé EOH while (<>) { if (!$document) { if (m/\\begin{document}/) { $document = 1; } next; } # Eliminate comments (but keep percentage signs) s/([^\\%]?)%.*/$1/g; # Let's get some TeX to XML character conversion stuff s/\\#/#/g; s/\\%/%/g; s/\\&/&/g; s/\\'([aeiou])/&$1acute;/g; s/---/—/g; # — s/--/–/g; # – s/[`']{2}?/"/g; s#\\LaTeX#LATEX#g; s#\\TeX#TEX#g; s#\\\\#
#g; s#\\hspace{.*?}#
\n#g; s#\\hrulefill#
\n#g; s/([^\\]?)~/$1 /g; s#\\Cpp({})?#C++#g; # Convert URLs to hyperlinks s#(\\url{.*?) #$1~#g; # Correct overzealous ~ gobbling s#\\url{(.*?)}#$1#g; # Convert italics properly s#\\textit{(.*?)}#$1#g; # Get my name displayed right s#\\name{(.*?)}#$1#g; # Handle footnotes by cacheing them in @footnotes if (m/\\footnote{(.*?)}/) { push @footnotes, $1; s#\\footnote{.*?}#"" . scalar @footnotes . ""#e; } # Handle section titles if (m/\\section{(.*)}/) { print "

$1

\n"; } # Handle item lists elsif (m/\\item (.*)/) { if ($item) { print "\n
  • $1"; } else { print "
  • $1"; $item = 1; } } # Get left and right job titles set elsif (m/\\position{(.*)}/) { print "\n"; } elsif (m/\\period{(.*)}/) { print "
    $1$1
    \n"; } # Make blank lines truly blank. elsif (m/^\s*$/) { print "\n"; } # Work out centering without the
    tag elsif (m/\\begin{centering}/) { print "

    "; } elsif (m/\\end{centering}/) { print "

    "; } # Print centerline stuff elsif (m/\\centerline{(.*?)}/) { print "

    $1

    \n"; } # Are we in an itemize environment? elsif (m/\\begin{itemize}/) { $depth++; print "
      \n"; $item = 0; } elsif (m/\\end{itemize}/) { if ($depth) { print " \n"; } print "
    \n"; } # Things to ignore: elsif (m/\\setlength/ or m/\\clearpage/ or m/\\end/) {} # Print everything else else { print; $item = 0; } } # Display those footnotes if (scalar @footnotes) { print "

    \n"; for (my $i = 1; $i <= scalar @footnotes; $i++) { print "

    $i $footnotes[$i-1]

    \n"; } } # Print the footer print < Valid XHTML 1.1!

    EOF