#!/usr/bin/perl
##############################################################################
##############################################################################
# Written by CTL (lansdoct@cs.alfred.edu)
# Copyright (C) 2000 by Christopher Lansdown
#   
# 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.
##############################################################################
# This program does a simple conversion of html to TeX.  It mostly just
# converts simple elements over then gets rid of the rest.
##############################################################################

# Additions by RIG: <center>, <a name="...">, <a href="...">...</a>

my $VERSION='0.1.0';


########################
#First put in the macros
my $line = <<EOTXT;
\\font\\titlefont=cmb20
\\font\\bigtitlefont=cmb28
\\font\\sectionfont=cmr18
\\font\\termfont=cmb14
\\font\\commandfont=cmr13

\\def\\bigtitle\#1{\\centerline{\\bigtitlefont \#1} \\vskip 6pt \\hrule height3pt}

\\def\\title\#1{\\vskip 20pt \\centerline{\\titlefont \#1} \\vskip -.8em \\centerline{ \\vrule width300pt height1.3pt} \\vskip 12pt}

\\def\\section\#1{\\vskip 18pt \\vbox{\\centerline{\\sectionfont \#1}
\\vskip -14pt
\\centerline{\\vrule width130pt height1pt}} 
\\vskip 8pt}


EOTXT

########################
#Read in the actual html
my @body = <>;
$line .= join('', @body);


#############################
#Map html stuff to TeX stuff

#set comments properly
$line =~ s|\"(.*?)\"|\`\`$1\'\'|gs;

#set up line breaks
$line =~ s|<BR>|\\hfil\\break|gi;
$line =~ s|<p>|\n\n|gi;

#set up rules
$line =~ s|<hr>|\\vskip 4pt\\hrule\\vskip 4pt|gi;

#set up bold and the like
$line =~ s|<i>(.*?)</i>|{\\it $1}|gi;
$line =~ s|<em>(.*?)</em>|{\\it $1}|gi;
$line =~ s|<b>(.*?)</i>|{\\bf $1}|gi;
$line =~ s|<strong>(.*?)</strong>|{\\bf $1}|gi;
$line =~ s|<center>(.*?)</center>|\\begin{center}$1\\end{center}|gi;

#set up headers
$line =~ s|<H1>(.*?)</H1>|\\bigtitle{$1}|sgi;
$line =~ s|<H2>(.*?)</H2>|\\title{$1}|sgi;
$line =~ s|<H3>(.*?)</H3>|\\section{$1}|sgi;

###########################
#Get rid of all other tags
$line =~ s|<[^>]*>||g;

#######################
#Add the trailing stuff
$line .= "\n\\end";

#################
#And print it out
print $line;
