summaryrefslogtreecommitdiff
path: root/support/html2latex/HTML
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/html2latex/HTML
Initial commit
Diffstat (limited to 'support/html2latex/HTML')
-rw-r--r--support/html2latex/HTML/COPYING339
-rw-r--r--support/html2latex/HTML/Changes45
-rw-r--r--support/html2latex/HTML/INSTALL15
-rw-r--r--support/html2latex/HTML/Latex.pm1458
-rw-r--r--support/html2latex/HTML/MANIFEST17
-rw-r--r--support/html2latex/HTML/Makefile.PL10
-rw-r--r--support/html2latex/HTML/README64
-rw-r--r--support/html2latex/HTML/README.win.txt16
-rw-r--r--support/html2latex/HTML/TODO20
-rw-r--r--support/html2latex/HTML/t/foreigns.correct7
-rw-r--r--support/html2latex/HTML/t/foreigns.html1
-rwxr-xr-xsupport/html2latex/HTML/t/foreigns.t20
-rw-r--r--support/html2latex/HTML/t/tags.correct116
-rw-r--r--support/html2latex/HTML/t/tags.gifbin0 -> 2537 bytes
-rw-r--r--support/html2latex/HTML/t/tags.html123
-rw-r--r--support/html2latex/HTML/t/tags.pngbin0 -> 2481 bytes
-rwxr-xr-xsupport/html2latex/HTML/t/tags.t19
17 files changed, 2270 insertions, 0 deletions
diff --git a/support/html2latex/HTML/COPYING b/support/html2latex/HTML/COPYING
new file mode 100644
index 0000000000..a43ea2126f
--- /dev/null
+++ b/support/html2latex/HTML/COPYING
@@ -0,0 +1,339 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 675 Mass Ave, Cambridge, MA 02139, USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ Appendix: How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) 19yy <name of author>
+
+ 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) 19yy name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/support/html2latex/HTML/Changes b/support/html2latex/HTML/Changes
new file mode 100644
index 0000000000..acb53a1cb7
--- /dev/null
+++ b/support/html2latex/HTML/Changes
@@ -0,0 +1,45 @@
+Revision history for Perl extension HTML::Latex.
+
+1.0 Thurs Sep 14 11:38:12 MST 2000
+ - removed invalids.t from testing and any log testing. It was
+ stupid to have it in there in the first place.
+ - added 'kill' type
+ - made SCRIPT into 'kill'. So, anything in SCRIPT /SCRIPT is
+ ignored. In other words, javascript is completely ignored now.
+
+0.9 Mon Aug 28 22:34:15 MST 2000
+ - set_log now accepts IO::File objects or FileHandle objects.
+ - Added support for international characters.
+ - Added quote-expansion
+ - Added ability to pass a FileHandle to html2latex().
+ - Added method parse_string().
+ - ~ doesn't expand to $ENV{HOME} unless $ENV{HOME} exists.
+
+0.8 Thu Aug 17 00:32:36 2000
+ - Changed handler routine paramater order and got rid of
+ $content_ref.
+ - Ported the conversion of images to ImageMagick
+ - Changed all calls to $html_element->content to
+ $html_element->content_list to deal with undef's (requires
+ HTML::Tree .68).
+ - Changed get_uri and store_uri a lot.
+ - Improved the information printed by &texify when using
+ $option{debug}.
+ - Tried to improve <PRE> and <CODE> behavior. I don't know what
+ to make it do. It's sort of difficult.
+ - Fixed the <LI> bug.
+ - Added an HTML-style paragraph option (no indent and 1 line
+ paragraph spacing).
+ - Altered default behavior of \[sub]section to \[sub]section-.
+ - Changed call to texify from array of parents to single parent
+ (more efficient and also can check try attributes).
+ - Added the ban_tag option.
+ - Fixed "^" bug.
+ - Made relative local IMG sources work correcly. At least, I
+ hope. All this local/network absolute/relative crap is getting on
+ my nerves. It never seems to work correctly.
+
+0.01 Thu Aug 17 00:02:34 2000
+ - original version; created by h2xs 1.20 with options
+ -XA -n HTML::Latex
+
diff --git a/support/html2latex/HTML/INSTALL b/support/html2latex/HTML/INSTALL
new file mode 100644
index 0000000000..2abc3bae8a
--- /dev/null
+++ b/support/html2latex/HTML/INSTALL
@@ -0,0 +1,15 @@
+Make sure before you do anything else that you install requirements.
+See README for more information. After you're done with that try the
+classic:
+
+perl Makefile.PL
+make install
+
+That should just install it. Although, I recommend:
+
+perl Makefile.PL
+make test
+make install
+make clean
+
+It's more safe (it's tested) and more clean (it's cleaned).
diff --git a/support/html2latex/HTML/Latex.pm b/support/html2latex/HTML/Latex.pm
new file mode 100644
index 0000000000..8b970f8485
--- /dev/null
+++ b/support/html2latex/HTML/Latex.pm
@@ -0,0 +1,1458 @@
+#!/usr/bin/perl -w
+# HTML::Latex
+# Copyright (C) 2000 Peter Thatcher
+
+# 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.
+
+package HTML::Latex;
+$VERSION = '1.1';
+
+use strict;
+# use warnings;
+# use diagnostics;
+use FileHandle;
+use File::Path;
+use File::Basename;
+use Data::Dumper;
+use Carp;
+use vars qw($packages $heads $tags $options $pres $banned $LOG $VERSION %present);
+
+#extra
+use HTML::TreeBuilder;
+use XML::Simple;
+
+################### BEGIN DOCUMENTATIEN #####################
+
+=head1 NAME
+
+HTML::Latex - Creates a Latex file from an HTML file.
+
+=head1 SYNOPSIS
+
+ use HTML::Latex
+
+ my $parser = new HTML::Latex($conffile);
+ $parser->set_option(\%options);
+ $parser->add_package(@packages);
+ $parser->ban_tag(@banned);
+ $parser->set_log($logfile);
+
+ # Option 1:
+ foreach my $uri (@ARGV) {
+ my ($htmlfile,$latexfile) = $parser->html2latex($uri);
+ }
+
+ # Option 2:
+ foreach my $uri (@ARGV) {
+ my $in = IO::File->new("< $uri");
+ my $out = IO::File->new("> $uri.tex");
+ $parser->html2latex($in,$out);
+ }
+
+ # Option 3:
+ my $html_string = join("\n",<>);
+ my $tex_string = $parser->parse_string($html_string,1);
+
+ # Option 4:
+ my $html_string = join("",@ARGV);
+ my $tex_string = $parser->parse_string($html_string);
+
+print $tex_string;
+
+=head1 DESCRIPTION
+
+This class is used to create a text file in Latex format from a file
+in HTML format. Use the class as follows:
+
+1. Create a new HTML::Latex object.
+
+2. Override any options using set_option(), add_package(), ban_tag(), or set_log().
+
+3. Run html2latex() on a file or URL.
+
+4. Do whatever you want with the filename that was returned.
+
+=head1 METHODS
+
+=over
+
+=item B<$p = HTML::Latex-E<gt>new($conffile)>
+
+Creates a new HTML::Latex object. It parses the configuation file
+$conffile to set attributes. The format of that file can be found in
+the CONFIGURATION FILE section.
+
+Example:
+
+ my $parser = HTML::Latex->new();
+
+=item B<($htmlfile,$latexfile) = $p-E<gt>html2latex($in,$out)>
+
+$in is any URL or filename or FileHandle. If it is a URL, it is
+mirrored locally. The local location is returned as $htmlfile. The
+method produces a Latex file $latexfile.
+
+Locally mirrored files are all stored in the "store" directory which
+can be set with either set_option() or in the configuration file. See
+B<store> under the OPTIONS section for more details.
+
+A mirrored file will automatically be re-downloaded when the URL is
+updated. If it has not been updated, html2latex() will use the local
+file only.
+
+Also, html2latex() defaults to index.html when a file is not given.
+For instance, if you used C<html2latex(http://slashdot.org)>, then the
+url http://slashdot.org/index.html would be used.
+
+Example:
+
+ my($htmlfile,$latexfile) =
+ $parser->html2latex('report01.html');
+
+
+=item B<$tex_string = $p-E<gt>parse_string($html_string [,$full])>
+
+$html_string is an HTML string. $tex_string is a LaTeX string. If
+$full is 0, then any <HTML> and <BODY> tags are ignored, and the
+string is just plain tex. If $full is 1, then <HTML> and <BODY> tags
+are implicitly added. Basically, it's a choice as to whether or not
+$tex_string has a LaTeX preamble in it.
+
+=item B<my @old_values = $p-E<gt>set_option(\%options)>
+
+Sets on option. For a description of options, see the OPTION section
+below. Returns an list of all the old values based on the keys of
+%options.
+
+Example:
+
+ $parser->set_option({border => 0, debug => 1});
+
+=item B<$p-E<gt>add_package(@packages)>
+
+Adds packages to the list used by \usepackage{} in Latex. The
+defaults are fullpage, graphicx, and url.
+
+Example:
+
+ $parser->add_package('doublespace');
+
+=item B<$p-E<gt>add_head(@heads)>
+
+Adds options to the list used by \documentclass[OPTIONS]{article} in
+Latex. Font is automatically put there, so don't put it there
+yourself.
+
+Example:
+
+ $parser->add_head('twocolumn');
+
+=item B<$p-E<gt>ban_tag(@banned)>
+
+Add @banned to the list of tags that html2latex() will ignore. This
+overrides tag definitions in the configuration file. By default, the
+<CODE> tag is banned. That is because some people were using
+<PRE><CODE></CODE></PRE>, which can be really bad if both are parsed.
+
+Example:
+
+ $parser->ban_tag('code');
+
+=item B<my $filehandle = $p-E<gt>set_log($logfile)>
+
+Have errors and messages printed to the filename or FileHandle or
+IO::File $logfile. By default, things are printed to STDERR.
+set_log() returns the FileHandle of the log file.
+
+Example:
+
+ my $filehandle = $parser->set_log('report01.log');
+
+=back
+
+=head1 CONFIGURATION FILE
+
+The configuration file is a very simple XML file. The root element is
+<conf>. Nested inside are four tags: <tag> <package> <ban> <options>.
+
+=head2 tag
+
+<tag> has 2 attributes: I<name> and I<type>. Inside of <tag> is
+nested zero to many <tex> tags. Each of these is described below.
+
+=over
+
+=item name
+
+The I<name> attributes assigns the other values (I<type> and I<tex>)
+to an HTML tag of a certain name.
+
+=item type
+
+The type of a tag basically tells html2latex() how to handle it.
+Internally, this assigns the tag to a certain handler.
+
+=item tex
+
+When handling a tag, html2latex must know what TeX string to replace
+the HTML tags with. This is done with the use of <tex>tex
+string</tex>. Different types require 0,1,or 2 such tags nested
+inside of <tag>. You can think of <tex> tags as arguments to pass to
+a I<type> handler. Internally, that is what it is.
+
+Extraneous White space is ignored; do not rely upon it. \N is replaced
+with newlines. Everything else is just as you type it.
+
+=head2 tag examples
+
+For a lot of examples, just look at the default configuration file,
+html2latex.xml. We will go over 1 example in detail. This example is
+for the HTML <B> tag.
+
+ <tag name="b" type="command">
+ <tex>textbf</tex>
+ </tag>
+
+This text tells html2latex() to treat the <B> tag as a TeX command.
+It gives it the additional argument of 'textbf'. html2latex() will
+call the command_handler('textbf') and the output will be \textbf{NESTED DATA}.
+
+=back
+
+=head2 package
+
+For each <package>package_name</package> given, package_name is added
+to the list printed in the Latex file. For instance, the lines
+
+ <package>fullpage</package>
+ <package>graphicx</package>
+ <package>url</package>
+
+adds the packages fullpage, graphicx, and url. The package 'fullpage'
+is often recommended.
+
+=head2 head
+
+For each <head>head</head> given, head is added to the list of options
+printed in the \documentclass command. For instance, the line
+
+ <head>twocolumn</head>
+
+creates the command \documentclass[10pt,twocolumn]{article}.
+
+=head2 ban
+
+<ban> will make html2latex ignore a tag. For instance, the line
+
+ <ban>code</ban>
+
+makes html2latex() ignore <code> even though it has a definition in
+the configuration file. This can be useful to turn on/turn off tags
+when trying different configurations.
+
+=head2 options
+
+Inside of <options> are a number of other tags. Each is described
+below in OPTIONS. The value inside of a given <OPTION> </OPTION>
+provides a default value that can be overridden with command-line
+options. For instance, <font>10</font> will set the default font size
+to 10.
+
+=head1 TYPES
+
+There are a number of different types of HTML tags support by
+HTML::Latex. The list is: command, environment, single, other, table,
+image, and ignore. Each are described below. TEX1 and TEX2 mean the
+first and second value given by <tex>. NAME is given by the name
+attribute. VALUE is the value nested within an HTML tag.
+
+=head2 command
+
+ HTML Key: <NAME>VALUE</NAME>
+ HTML Example: <B>Foo</B>
+ TeX Key: \TEX1{VALUE}
+ TeX Example: \textbf{Foo}
+
+=head2 environment
+
+ HTML Key: <NAME>VALUE</NAME>
+ HTML Example: <OL>Foo</OL>
+ TeX Key: \begin{TEX1} VALUE \end{TEX1}
+ TeX Example: \begin{enumerate} Foo \end{enumerate}
+
+=head2 single
+
+ HTML Key: <NAME>VALUE
+ HTML Example: <LI>Foo
+ TeX Key: \TEX1 VALUE
+ TeX Example: \item Foo
+
+=head2 other
+
+ HTML Key: <NAME>VALUE</NAME>
+ HTML Example: <DT>Foo
+ TeX Key: TEX1 VALUE TEX2
+ TeX Example: \item[Foo]
+
+=head2 kill
+
+ HTML Key: <NAME>VALUE</NAME>
+ HTML Example: <SCRIPT>javascript.garbage()</SCRIPT>
+ TeX Key: ""
+ TeX Example: ""
+
+This is of particular fun because any nested HTML tags are also ignored. Good for removing unwanted javascript.
+
+=head2 table
+
+This should be applied if and only if a tag is of type TABLE,TR, or TD.
+
+=head2 image
+
+This should be applied if and only if a tag is of type IMG.
+
+=head2 ignore
+
+Do nothing. Has the same affect as banning a tag.
+
+=head1 OPTIONS
+
+=over
+
+=item B<store>
+
+"store" is the directory that mirrored files are stored in. It is
+~/.html2latex by default. In side of this directory are
+subdirectories representing the HOST in a URL and the path from that
+HOST. For instance, if you used
+C<html2latex(http://slashdot.org/path/to/file.html>, it would store
+the file as ~/.html2latex/slashdot.org/path/to/file.html.
+
+=item B<cache>
+
+This will force html2latex to use cached files if possible. It always
+caches anyway, and uses the cached file if the network file has not
+changed. This just forces the use of the local file if available.
+
+=item B<document_class>
+
+Set the documentclass to use. Any valid latex document class is
+valid. Examples are B<report>, B<book>, and B<article>. B<article>
+is the default. If an invalid document class is used, the output
+latex file will not compile.
+
+=item B<paragraph>
+
+True uses HTML-style paragraphs. They leave a newline between
+paragraphs. False uses TeX-style paragraphs. They have no newline,
+but indent the first line of every paragraph. Default is true.
+
+=item B<font>
+
+Set the font size. Can be 10,11, or 12. Do not try anything else.
+html2latex will not check it, but the latex file will not compile (at
+least I think not). Default is 12.
+
+=item B<image>
+
+Set the scale for images in the latex file. This is useful because
+some images in HTML or much to big to fit on a page. Default is 1.0.
+Scale can be any non-zero positive floating point number; large
+numbers are not recommended.
+
+=item B<border>
+
+True means table borders are on. False mean they are off. This is
+always overridden by HTML attributes.
+
+=item B<mbox>
+
+html2latex() will put a tex \mbox around all of the tables it creates.
+I do not know why, but with a lot of tables (especially nested ones),
+the tex and pdf output will work better. So, if you do not like your
+output with tables, try this. True means on, false means off.
+Default is false.
+
+=item B<debug>
+
+The bigger the number set, the more the debugging info printed. 0
+means things relevant to the user. 1 means things that trace some
+code. 2 or greater means dumping data structures.
+
+=head1 Extending
+
+Extending HTML::Latex basically means making a new tag work. Usually,
+this would call for writing a new handler. If a present handler will
+suffice, then you can stip to the 3rd step. It's very simple to do so.
+There are 3 easy steps:
+
+=head2 Write the function.
+
+Write a function (preferably ending in '_handler'). It's input is 1
+HTML::Element and several tex strings. The type of HTML::Element and
+the value of the strings is set in the XML config file. Your furtions
+responsibilty is to return a TeX string representing the HTML::Element
+and all of it's children elements.
+
+The children are very easy to take care of. The string representing
+the children elements is obtained by calling C<texify($html_element)>.
+So, the function really only has to worry about the current
+HTML::Element.
+
+In particular, it must return that comes before and goes after the
+string represting the current HTML::Element. So, if you wanted a
+handler that print \TAG as the TeX for any <TAG> in HTML and a special
+TEX value given in the config file for </TAG>, then the handler would
+look like this:
+
+ sub my_handler{
+ my ($html_element,$tex) = @_;
+ return '\' . $html_element->tag() . texify($html_element) . $tex;
+ }
+
+In this example, one TEX parameter was passed in by the XML config
+file. The handler return what comes before the children concatenated
+with the texify-ed children texified with what comes after the
+children. See the documentation for HTML::Element for all of the
+things you can do with them.
+
+=head2 Assign a tag type to a handler.
+
+Just add an entry to %types below. It should have a type name as a
+key and a reference to your handler as a value. Following our
+example, we could add the line:
+
+ "my_type" => \&my_handler,
+
+To %types.
+
+=head2 Add support in the configuration file.
+
+The format of the configuration file is in XML and can be found above
+under CONFIGURATION FILE. The default XML file is at the bottom of
+Latex.pm under __DATA__. Basically, for every tag you want to use your
+new handler, use <tag> as follows:
+
+ <tag name="TAG_NAME" type="my_type">
+ <tex>TEX_PARAMATER</tex>
+ </tap>
+
+TAG_NAME is, of course, the tag name. "my_type" is the name of the
+type you assigned your handler to. TEX_PARAMATER is the value that
+gets placed under $tex in the example handler.
+
+
+That's it. Now HTML::Latex should obey the new handler and behave
+correctly.
+
+=head1 NOTES
+
+In you call html2latex() on several URLs any filename given after a
+URL will continue to use the latest HOST given. Also, files default
+to index.html, regardless of what the server thinks. So, if you use:
+
+ html2latex(http://slashdot.org)
+ html2latex(foo.html)
+ html2latex(http://linuxtoday.net)
+ html2latex(bar.html)
+
+html2latex() will try to grab http://slashdot.org/index.html,
+http://slashdot.org/foo.html, http://linuxtoday.net/index.html, and
+http://linuxtoday.net/bar.html
+
+=head1 BUGS
+
+* Anything between <TABLE> and <TR> and <TD> is ignored. I do not
+
+
+* Anything between <OL> or <UL> and <LI> will not be ignored, but will
+ really mess Latex up.
+
+=cut
+
+################### END DOCUMENTATION #######################
+
+################### BEGIN DEFENITIONS #######################
+
+# Test what modules we can use
+eval {require URI};
+$present{'URI'} = 1 unless $@;
+
+eval {require LWP::Simple};
+$present{'LWP::Simple'} = 1 unless $@;
+
+eval {require Image::Magick};
+$present{'Image::Magick'} = 1 unless $@;
+
+# The configuration file gives a "type" to each tag. This hash tells
+# what functions to use on each type
+my %types = (
+ "command" => \&command_handler,
+ "environment" => \&environment_handler,
+ "single" => \&single_handler,
+ "ignore" => \&texify,
+ "other" => \&other_handler,
+ "kill" => sub {return ""},
+
+ "image" => \&image_handler,
+ "table" => \&table_handler,
+ "pre" => \&pre_handler, # Experimental; don't use
+ );
+
+# Some characters typed in HTML need to be altered to be correct in
+# Latex. These must be done this specific order All the foreign
+# characters or special ascii characters that need to be altered. *
+# next the comment means it doesn't really work or is faked. If it's
+# commented out, that means it doesn't work at all.
+my @specials = (
+ ['<!--.*-->' , '' ], #comments
+ ['\$' , '\$' ],
+ ['\\\\(?!\$)', "\$\\backslash\$"], #\
+ ['<' , '$<$' ],
+ ['>' , '$>$' ],
+ ['&' , '\&' ],
+ ['%' , '\%' ],
+ ['#' , '\#' ],
+ ['{' , '\{' ],
+ ['}' , '\}' ],
+ ['_' , '\_' ],
+ ['\^' , '\^{}' ],
+ [chr(161), '!`' ], #¡
+ #[chr(162), '' ], #¢*
+ [chr(163), '{\\pounds}' ], #£
+ #[chr(164), '' ], #¤*
+ [chr(165), '{Y\hspace*{-1.4ex}--}'], #¥*
+ [chr(166), '$|$' ], #¦*
+ [chr(167), '{\\S}' ], #§
+ [chr(168), '\\"{}' ], #¨
+ [chr(169), '{\\copyright}' ], #©
+ [chr(170), '$^{\underline{a}}$'], #ª*
+ [chr(171), '<<' ], #«
+ [chr(172), '$\\neg$' ], #¬
+ [chr(173), '$-$' ], #­
+ #[chr(174), '' ], #®*
+ [chr(175), '$^-$' ], #¯
+ [chr(176), '$^{\\circ}$' ], #°
+ [chr(177), '$\\pm$' ], #±
+ [chr(178), '$^2$' ], #²
+ [chr(179), '$^3$' ], #³
+ [chr(180), '$^\\prime$' ], #´
+ [chr(181), '$\\mu$' ], #µ
+ [chr(182), '{\P}' ], #¶
+ [chr(183), '$\cdot$' ], #·
+ [chr(184), ',' ], #¸*
+ [chr(185), '$^1$' ], #¹
+ [chr(186), '$^{\\underline{\\circ}}$'], #º*
+ [chr(187), '>>' ], #»
+ [chr(188), '$\frac{1}{4}$' ], #¼
+ [chr(189), '$\frac{1}{2}$' ], #½
+ [chr(190), '$\frac{3}{4}$' ], #¾
+ [chr(191), '?`' ], #¿
+ [chr(192), '\\`A' ], #À
+ [chr(193), '\\\'A' ], #Á
+ [chr(194), '\\^A' ], #A
+ [chr(195), '\\~A' ], #Ã
+ [chr(196), '\\"A' ], #Ä
+ [chr(197), '{\\AA}' ], #Å
+ [chr(198), '{\\AE}' ], #Æ
+ [chr(199), '\\c{C}' ], #Ç
+ [chr(200), '\\`E' ], #È
+ [chr(201), '\\\'E' ], #É
+ [chr(202), '\\^E' ], #Ê
+ [chr(203), '\\"E' ], #Ë
+ [chr(204), '\\`I' ], #Ì
+ [chr(205), '\\\'I' ], #Í
+ [chr(206), '\\^I' ], #I
+ [chr(207), '\\"I' ], #Ï
+ [chr(208), '{D\\hspace*{-1.7ex}-\\hspace{.9ex}}'], #Ð*
+ [chr(209), '\\~N' ], #Ñ
+ [chr(210), '\\`O' ], #Ò
+ [chr(211), '\\\'O' ], #Ó
+ [chr(212), '\\^O' ], #Ô
+ [chr(213), '\\~O' ], #Õ
+ [chr(214), '\\"O' ], #Ö
+ [chr(215), '$\chi$' ], #×
+ [chr(216), '{\\O}' ], #Ø
+ [chr(217), '\\`U' ], #Ù
+ [chr(218), '\\\'U' ], #Ú
+ [chr(219), '\\^U' ], #Û
+ [chr(220), '\\"U' ], #Ü
+ [chr(221), '\\\'Y' ], #Ý*
+ [chr(222), 'P' ], #Þ*
+ [chr(223), '"s' ], #ß
+ [chr(224), '\\`a' ], #á
+ [chr(225), '\\\'a' ], #à
+ [chr(226), '\\^a' ], #â
+ [chr(227), '\\~a' ], #ã
+ [chr(228), '\\"a' ], #ä
+ [chr(229), '\\r{a}' ], #å
+ [chr(230), '{\ae}' ], #æ
+ [chr(231), '\\c{c}' ], #ç
+ [chr(232), '\\`e' ], #é
+ [chr(233), '\\\'e' ], #è
+ [chr(234), '\\^e' ], #ê
+ [chr(235), '\\"e' ], #ë
+ [chr(236), '\\`{\i}' ], #ì
+ [chr(237), '\\\'{\\i}' ], #í
+ [chr(238), '\\^{\\i}' ], #î
+ [chr(239), '\\"{\\i}' ], #ï
+ [chr(240), '\\v{o}' ], #ð
+ [chr(241), '\\~n' ], #ñ
+ [chr(242), '\\`o' ], #ò
+ [chr(243), '\\\'o' ], #ó
+ [chr(244), '\\^o' ], #ô
+ [chr(245), '\\~o' ], #õ
+ [chr(246), '\\"o' ], #ö
+ [chr(247), '$\\div$' ], #÷
+ [chr(248), '{\\o}' ], #ø
+ [chr(249), '\\`u' ], #ù
+ [chr(250), '\\\'u' ], #ú
+ [chr(251), '\\^u' ], #û
+ [chr(252), '\\"u' ], #ü
+ [chr(253), '\\\'y' ], #ý
+ [chr(254), 'p' ], #þ*
+ [chr(255), '\\"y' ], #ÿ
+ );
+
+# complie matchings
+foreach my $set (@specials) {
+ $set->[0] = qr|$set->[0]|;
+}
+
+################### END DEFENITIONS #######################
+
+# Paramaters for HANDLERs and SUBs are shown as <N> and [N]. N is the
+# number of the parameter, starting with 1. So, the first paramater
+# would be <1>, the second <2>, and so on. <N> means the paramater is
+# mandatory. [N] means it is optional.
+
+##################### BEGIN METHODS ######################
+
+# initializes options with optional configuration file
+sub new {
+ my ($class,$conffilename) = @_;
+
+ my $conffile;
+ if(defined($conffilename)){
+ $conffile = IO::File->new("< $conffilename");
+ } else {
+ $conffile = \*DATA;
+ }
+
+ my $conf = XMLin($conffile,forcearray => ['tex','pre','ban']);
+
+ # moved @banned from an array to a hash for fast lookup later
+ my $banned_ref = $conf->{ban};
+ $conf->{ban} = {};
+ foreach my $banned (@$banned_ref){
+ $conf->{ban}{$banned}++;
+ }
+
+ # make any refrences in @tex (see handlers below) to empty strings and new lines
+ # Ugly, I know. Perhaps XML::Simple is too simple.
+ foreach my $tag (keys %{$conf->{tag}}){
+ foreach my $tex (@{$conf->{tag}{$tag}{tex}}){ #some derefrence, eh?
+ $tex = (ref($tex) ? '' : $tex); # {} => ''
+ $tex =~ s/\\N/\n/g; # \N => newline
+ # if it's a verbatim and not banned
+ push @{$conf->{pre}}, $tag if ($tex eq 'verbatim' && !$conf->{ban}{$tag});
+ }
+ }
+
+ #open logging files
+ $conf->{log} = $conf->{conf}{options} ?
+ FileHandle->new($conf->{options}{log},'w') :
+ \*STDERR;
+
+ return bless $conf,$class;
+}
+
+# converts html2latex using &texify.
+# <1> The html filename or filehandle
+# <2> optional second filehandle
+sub html2latex {
+ my ($conf,$in,$out) = @_;
+
+ #global to functions called below, which is what we want
+ local $packages = $conf->{package} || [];
+ local $heads = $conf->{head} || [];
+ local $tags = $conf->{tag} || {};
+ local $options = $conf->{options} || {};
+ local $banned = $conf->{ban} || {};
+ local $pres = $conf->{pre} || {};
+ local $LOG = $conf->{log};
+ $options->{store} =~ s/^\s*~/$ENV{HOME}/ if exists $ENV{HOME};
+
+ print $LOG Dumper $conf if $options->{debug} > 1;
+
+ #open files.
+ my($filenamein,$filenameout);
+ unless(ref $in and ref $out){ #filenhadles -- leave them alone.
+ ($in,$out,$filenamein,$filenameout) = open_files($in,1) if defined($in);
+ }
+
+ #if you have a uri and it exists
+ #build the HTML tree
+ if($in && $out){
+ my $tree = HTML::TreeBuilder->new;
+ $tree->warn(1);
+ my $result = $tree->parse_file($in);
+
+ #here's where all the big magic happens
+ print $out &preamble_handler($tree->root);
+
+ #destroy the HTML tree
+ $tree->delete;
+
+ return ($filenamein,$filenameout) if ($filenamein && $filenameout);
+ return $result; #If you recieved filehandles, just return the return of $tree->parse
+ } else {
+ # print $LOG "You better give html2latex() a valid filename if you want it to do anything.\n";
+ return;
+ }
+}
+
+sub parse_string {
+ my ($conf,$input,$full) = @_;
+ return unless defined($input);
+
+ local $packages = $conf->{package} || [];
+ local $heads = $conf->{head} || [];
+ local $tags = $conf->{tag} || {};
+ local $options = $conf->{options} || {};
+ local $banned = $conf->{ban} || {};
+ local $pres = $conf->{pre} || {};
+ local $LOG = $conf->{log};
+ $options->{store} =~ s/^\s*~/$ENV{HOME}/ if exists $ENV{HOME};
+
+ print $LOG Dumper $conf if $options->{debug} > 1;
+
+ my $tree = HTML::TreeBuilder->new;
+ $tree->warn(1);
+ $tree->parse($input);
+
+ my $result;
+ if($full){
+ $result = preamble_handler($tree->root); # Print whole file
+ } else {
+ $result = texify($tree->find_by_tag_name('body'));
+ }
+ $tree->delete;
+
+ return $result;
+}
+
+# set options for running html2latex
+# <1> is a hash refrence of options
+sub set_option {
+ my ($conf,$options) = @_;
+ my @old_values = ();
+ while(my ($key,$value) = each %$options){
+ if(defined($value)){
+ push @old_values, $conf->{options}{$key};
+ $conf->{options}{$key} = $value;
+ }
+ }
+}
+
+sub add_package {
+ my $conf = shift;
+ push @{$conf->{package}}, @_;
+}
+
+sub add_head {
+ my $conf = shift;
+ push @{$conf->{head}}, @_;
+}
+
+sub ban_tag {
+ my $conf = shift;
+ foreach my $banned (@_){
+ $conf->{ban}{$banned}++;
+ }
+}
+
+#set log file to $logfile
+#return FileHandle to log file.
+sub set_log {
+ my ($conf,$logfile) = @_;
+ if(ref $logfile){
+ $conf->{log} = $logfile;
+ } else {
+ $conf->{log} = FileHandle->new($logfile,'w') or
+ die "FILE: Bad logfile: $logfile";
+ }
+ return $conf->{log};
+}
+##################### END HANDLERS #########################
+
+##################### BEGIN HANDLERS #######################
+
+# All HANDLERs are called like so:
+# &HANDLER($html_element,@tex);
+
+# @tex is a list of latex strings $html_elmemnt is a node in the HTML
+# tree. HTML::ELement man page for more on that.
+
+# Anyway, the comments for each HANDLER represent the starting HTML
+# string and the output tex string. Anything inbetween HTML tags is
+# recursivly texified by the big sub &texify, which then calls other
+# HANDLERs.
+
+# HTML input form: <FOO> Bar </FOO>
+# Latex output form: \command{bar}
+sub command_handler{
+ my($html_element,$command) = @_;
+ return "\\$command\{" . texify($html_element) . "\}\n";
+}
+
+# HTML input form: <FOO> Bar </FOO>
+# Latex output form: tex1 bar tex2
+sub other_handler{
+ my($html_element,@tex) = @_;
+ return $tex[0] . texify($html_element) . $tex[1];
+}
+
+# HTML input form: <FOO> Bar </FOO>
+# Latex output form: \begin{tex} Bar \end{tex}
+sub environment_handler{
+ my($html_element,$environment) = @_;
+ return '\begin{' . $environment . '}' . "\n" .
+ texify($html_element) . "\n" . '\end{' . $environment . '}' . "\n";
+}
+
+# HTML input form: <FOO> Bar (implicit end)
+# Latex output form: \tex Bar
+sub single_handler{
+ my($html_element,$single) = @_;
+ return $single . " " . texify($html_element) . "\n";
+}
+
+# HTML input form: <PRE> Bar </PRE>
+# Latex output has all of the spaces made into hard spaces and
+# newlines into hard newlines. It's the best I can do since latex
+# doesn't want to respect whitespace. It's very experimental. One
+# should really just use the verbatim environment, but what the heck,
+# give people the option.
+sub pre_handler{
+ my($html_elemnt) = shift;
+ my $text = $html_elemnt->as_text;
+
+ $text =~ s/[ ]/\\ /og;
+ $text =~ s/\n/\\\\\n/og;
+
+ return $text;
+}
+
+# Does a lot of work to create a table in latex format.
+# It takes <TABLE>, <TR>, and <TD>. It works by finding those tags nested inside
+# and then calling texify on them while keepind track of when to print
+# latex syntax. It's messy, I know. Nested tables are completely
+# ignored, and anything inside a table but not inside of a <TD> tag is
+# also ignored. If anyone would like to improve this, that would be
+# very cool.
+# <3> The HTML::Element representing the table. It doesn't use
+# $content_ref, so you don't really need it.
+
+sub table_handler{
+ my($html_element,$tex) = @_;
+ my $output = "";
+ if($tex eq "table"){
+ # It's a table tag
+ $output = ($options->{mbox}? '\mbox{' : '') .
+ create_latex_table($html_element) . ($options->{mbox}? '}' : '');
+ } else {
+ # It's a td or tr, let create_latex_table() take care of "\\" and "&"
+ # add the texified text inside
+ $output = texify($html_element);
+ }
+ return $output;
+}
+
+# HTML input form: <IMG src="bar.(jpg|jpeg|gif|png)">
+# Latex output form: \includegraphic{bar.png}
+# In also converts the image to a .png using "convert".
+# <3> The HTML::Element representing the tag. It doesn't use
+# $content_ref, so you don't really need it.
+sub image_handler{
+ my($html_element,$tex) = @_;
+ my $source = $html_element->attr('src') || "";
+ my $scale = $html_element->attr('scale') || $options->{image};
+ my $alt = $html_element->attr('alt') || "";
+
+ if($scale and my $image = convert_image($source,$scale)){
+ # convert worked
+ return "\\$tex\[scale=$scale\]\{$image\} ";
+ } else {
+ #convert didn't work or images weren't selected.
+ print $LOG "IMG: Couldn't convert $source; using alt\n";
+ print $LOG "\tRecieved <$image>\n" if $options->{debug};
+ return $alt;
+ }
+}
+
+# Prints the preamble. Not to extensize right now, but will become
+# very extensive if I decide to parse stuff in the HEAD tag.
+sub preamble_handler{
+ my($html_element,$tex) = @_;
+ my $document_class = $html_element->attr('class') || $options->{document_class} || 'article';
+ my $font_size = $html_element->attr('fontsize') || $options->{font_size} || 10;
+ my $output;
+
+ $output .= join ('',
+ '\documentclass[',
+ join (",","${font_size}pt",@$heads),
+ ']{',
+ $document_class,
+ '}',
+ "\n",
+ '\usepackage{',
+ join(", ",@$packages),
+ '}',
+ "\n"
+ );
+ $output .= join ('',
+ '\setlength{\parskip}{1ex}',
+ "\n",
+ '\setlength{\parindent}{0ex}',
+ "\n",
+ ) if $options->{paragraph};
+
+ $output .= texify($html_element);
+
+ return $output;
+}
+
+###################### END HANDLERS #######################
+
+
+# Takes in an array of HTML::Element-es which calls a handler on all of its
+# children, which calls texify recursively, and eventually makes a
+# string.
+
+sub texify {
+ my $parent_element = shift;
+ my $output = "";
+
+ foreach my $html_element ($parent_element->content_list){
+ if(ref $html_element){
+ # If this element is another HTML::Element
+ my $tag = $html_element->tag();
+ print $LOG "\t" x ($html_element->depth - 1) . "<$tag> " if $options->{debug};
+
+ if(my $tag_hash_ref = $tags->{$tag} and !$banned->{$tag}){
+ # If the tag is used with a handler and it isn't banned, use it.
+ my $handler_ref = $types{$tag_hash_ref->{type}} or
+ die "<$tag> needs a proper type (not $tag_hash_ref->{type})\n";
+ my @tex = @{$tag_hash_ref->{tex} || []};
+ print $LOG "is of type $tag_hash_ref->{type}: calling handler with \"" .
+ join(",",@tex) . "\"\n" if $options->{debug};
+ $output .= $handler_ref->($html_element,@tex);
+ } else {
+ # Otherwise, just texify the contents;
+ print $LOG "has no type \n" if $options->{debug};
+ $output .= texify($html_element);
+ }
+ } else {
+ # Otherwise, it's just a string
+ print $LOG "\t" x ($parent_element->depth + 1), $html_element if $options->{debug} > 1;
+ unless($parent_element->is_inside(@$pres)){
+ #don't change any characters if inside a tag such as PRE.
+ #Quote expansion needs more finese.
+ $html_element =~ s/([^\s\[\{\(~])"/$1''/og; #" preceded by character not \s,[,{,or [
+ $html_element =~ s/"/``/og;
+ foreach my $special (@specials){
+ $html_element =~ s/$special->[0]/$special->[1]/g;
+ }
+ }
+ $output .= urlify($html_element);
+ }
+ }
+ return $output;
+}
+
+
+# opens necessary files
+# <1> The base of the filename
+sub open_files {
+ return unless (my $htmlfile = get_uri(@_));
+
+ #if filename has anything .*html, then remove the extension
+ my ($filename,$path,$suffix) = fileparse($htmlfile,'\.\w*html?');
+ my $texfile = "$path$filename.tex";
+
+ check_for_previous_files($texfile);
+
+ my $fh_in = FileHandle->new("< $htmlfile") or die "Can't open $htmlfile: $!";
+ my $fh_out = FileHandle->new("> $texfile") or die "Can't open $texfile: $!";
+ print $LOG "FILE: Processing $htmlfile and writing to $texfile\n";
+ return ($fh_in,$fh_out,$htmlfile,$texfile);
+}
+
+# checks for existance of file and moves it to name .old .
+# <1> The filename
+# [2] whether files should be renamed and overridden or just left alone.
+# default is rename override
+# returns whether the file exists or not
+sub check_for_previous_files {
+ my $filename = shift;
+ my $override = shift || 1;
+
+ if(-f $filename && $override){
+ rename $filename, "$filename.old";
+ print $LOG "FILE: renamed $filename $filename.old\n";
+ }
+ return $filename;
+}
+
+# checks for existance of file and prints that it successfully created it.
+# <1> filename
+# [2] error to print if didn't create;
+sub check_for_current_files {
+ my $filename = shift;
+ if( -f $filename){
+ print $LOG "FILE: Successfully created $filename\n";
+ return $filename;
+ }
+ else{
+ print $LOG "FILE: Failed to create $filename\n";
+ return;
+ }
+}
+# Creates a latex table from an html table using the other table sub procedures.
+# <1> The $html_element that is a table tag.
+# Returns the table in latex string form
+sub create_latex_table {
+ my $table = shift;
+ my $output;
+ my($latex_table_ref,$row_number,$column_number) = create_latex_table_def($table);
+ my $border = $table->attr('border') || $options->{border};
+
+ $output .= "\n\n" . '\begin{tabular}{' . $latex_table_ref . '}' . "\n";
+ $output .= "\\hline \n" if $border;
+
+ #pay attention to only the TR tags inside the TABLE tag.
+ my @rows = grep 'tr', $table->content_list;
+ foreach my $row (@rows){
+ #pay attention to only the TD tags inside the TR tags.
+ my @columns = grep 'td', $row->content_list;
+
+ for my $i (0 .. $column_number - 1){
+ # Make Sure to fill in blank ones if necessary
+ my $column = $columns[$i];
+ # Add the td data
+ $output .= texify($column) if $column;
+ # Add the puncation at the end if not the last one
+ $output .= (($i < $column_number -1)? " &" : "");
+ }
+
+ # Add the puncation at the end if not the last one
+ $output .= (($row->pindex() < $row_number -1 or $border)? " \\\\" : "") . "\n";
+ $output .= " \\hline \n" if $border;
+ }
+
+ $output .= "\n" . '\end{tabular}' . "\n\n";
+
+ return $output;
+}
+
+# Based on the alignments of the rows, create a latex table defenition (i.e. "cccc")
+# <1> The the number of columns the table has;
+# <2> A refrence to an array with alignment defenitions
+# <3> Whether it has a border or not;
+# Returns the table definition, the number of columns and the number of rows
+sub create_latex_table_def {
+ # get variables
+ my $table = shift;
+ my $border = $table->attr('border') || $options->{border};
+ my ($row_number,$column_number) = find_table_lengths($table);
+ my @column_alignments = create_column_alignments($table);
+
+ # define table_def
+ my $latex_table_def = ($border? "|" : "");
+ for my $i (0 .. $column_number - 1){
+ my $align = $column_alignments[$i];
+ $latex_table_def .= ($align? ($border? $align . "|" : $align) : ($border? "c|" : "c"));
+ }
+
+ return ($latex_table_def,$row_number,$column_number);
+}
+
+# Finds the maximum number of columns that any row in a table has
+# and also the number of rows it has.
+# <1> the refrence to the HTML::Element table.
+sub find_table_lengths {
+ my $table = shift;
+ #only care about TR children
+ my @rows = grep 'tr', $table->content_list;
+ my $max_row_length = 0;
+ foreach my $row (@rows){
+ #only care about the TD children
+ my @columns = grep 'td', $row->content_list;
+ if(@columns > $max_row_length){
+ $max_row_length = @columns;
+ }
+ }
+
+ # row_number column_number
+ return (scalar(@rows),$max_row_length);
+}
+
+# returns an array of column alignments
+# <1> the refrence to the HTML::Element table.
+sub create_column_alignments {
+ my $table = shift;
+ my @column_alignments;
+ #only care about TR children
+ my @rows = grep 'tr', $table->content_list;
+ if($rows[0]){
+ #only care about the TD children
+ my @columns = grep 'td', $rows[0]->content_list;
+ foreach my $column (@columns){
+ my $align = $column->attr('align');
+ if($align and $align eq 'left'){
+ $align = 'l';
+ } elsif($align and $align eq 'right'){
+ $align = 'r';
+ } else {
+ $align = 'c';
+ }
+
+ push @column_alignments, $align;
+ }
+ }
+
+ return @column_alignments;
+}
+
+
+# converts an image from jpeg or gif into png
+# returns the name of the new filename is successfull
+# <1> filename
+
+sub convert_image {
+ my $source = shift;
+
+ my($absolute,$relative) = get_uri($source);
+ if ($absolute and $relative){ #If we can find the file
+ #if it successfully stores the file
+ my ($aname,$apath,$asuffix) = fileparse($absolute,'\.(gif|png|jpe?g)');
+ my ($rname,$rpath,$rsuffix) = fileparse($relative,'\.(gif|png|jpe?g)');
+
+ if($asuffix eq '.gif' || $asuffix eq '.jpg' || $asuffix eq '.jpeg'){ #
+ # Picture is of a convertable type
+ if($present{'Image::Magick'}){
+ # convert it with Image::Magick
+ require Image::Magick;
+
+ my $aoutput = "$apath$aname.png"; #write to and return with png
+ my $routput = "$rpath$rname.png";
+ my $image = Image::Magick->new();
+ $image->Read("$absolute");
+ $image->Write("$aoutput");
+ undef $image;
+
+ print $LOG "IMG: Converted $source to $routput\n";
+ return $routput;
+ } else {
+ # No Image::Magick. Warn user and return nothing.
+ print $LOG "IMG: Can't convert $source without Image::Magick; using alt\n";
+ return;
+ }
+ } elsif ($asuffix eq '.png'){
+ # It's a PNG for sure.
+ my $routput = "$rpath$rname.png";
+ return $routput;
+ } else {
+ # so, it's not a png,gif, or jpg. That means it's an invalid.
+ print $LOG "IMG: Invalid picture type: $source; using alt\n";
+ return;
+ }
+ } else {
+ # We can't even get at the file.
+ return;
+ }
+}
+
+# If the filename is really a URL, then go grab it, translate
+# the name to the local file directory, and return that file name.
+# Otherwise, just return the thing you got in.
+# <1> is the URI
+# [2] can specify to change the default host for subsiquent calls
+# return ($absolute_path_to_file,$relative_path_to_file);
+# The relative can be absolute itself (same as $absolute).
+{
+ #variables to stay the same across calls of get_uri. It's used in
+ #case we get image URLs with no host or scheme or path.
+ my $HOST = undef; #global value of current HOST
+ my $PATH = undef; #path inside host where we start
+ my $SCHEME = undef; #scheme originally used
+
+ sub get_uri {
+ my ($uri,$absolute_local,$relative_local);
+ $uri = $absolute_local = $relative_local = shift;
+ print $LOG "looking for $uri\n" if $options->{debug};
+ my $override = shift || 0; #absolute means that you replace $HOST and $PATH
+
+ if(-f $uri){
+ # it's an absolute local file.
+ $PATH = dirname($uri) if $override;
+ print $LOG "returning $uri\n" if $options->{debug};
+ return ($uri,$uri);
+ } elsif(defined($PATH) && -f "$PATH/$uri") {
+ #it must be a local relative image
+ print $LOG "returning $PATH/$uri\n" if $options->{debug};
+ return ("$PATH/$uri",$uri);
+ } elsif($uri =~ m|://|){
+ #It's a full URL
+
+ # Load necessary modules if you can.
+ unless($present{'URI'}) {
+ print $LOG "NEED: Can't handle request of $uri without module URI\n";
+ return;
+ }
+
+ require URI;
+ URI->import();
+
+ unless($present{'LWP::Simple'}) {
+ print $LOG "NEED: Can't handle request of $uri without module LWP::Simple\n";
+ return;
+ }
+
+ require LWP::Simple;
+ LWP::Simple->import();
+
+ $uri = new URI($uri);
+ my ($path,$filename) = ($uri->path =~ m|(.*/)(.*)|);
+ #replace the host,host_path, and scheme if it doesn't have a value and we're allowed to
+
+ print $LOG "It's a full URL\n" if $options->{debug};
+ if($override){
+ $HOST = $uri->host;
+ $PATH = $path || '/';
+ $SCHEME = $uri->scheme;
+ print $LOG "Setting HOST to $HOST, PATH to $PATH, and SCHEME to $SCHEME\n" if $options->{debug};
+ }
+
+ my $absolute = ($options->{store} || '.') . '/' . ($uri->host || "") . ($path || "/") . ($filename || "index.html");
+
+ if(store_uri($uri,$absolute)){ #Now, download the file. If it fails, return 0.
+ print $LOG "returning $absolute\n" if $options->{debug};
+ return ($absolute,$absolute);
+ } else {
+ return;
+ }
+ } elsif(defined($HOST) && defined($SCHEME)){
+ #It's a partial URL.
+ if($uri =~ m|^/|){
+ #it's an absolute partial URL
+ my $absolute_uri = $SCHEME . '://' . $HOST . $uri;
+ $absolute_local = ($options->{store} || '.') . '/' . $HOST . $uri;
+ if(store_uri($absolute_uri,$absolute_local)){ #Now, download the file. If it fails, return nothing.
+ return($absolute_local,$absolute_local);
+ } else {
+ return;
+ }
+ } else {
+ #it's a relative partial URL
+ my $absolute_uri = $SCHEME . '://' . $HOST . $PATH . $uri;
+ $absolute_local = ($options->{store} || '.') . '/' . $HOST . $PATH . $uri;
+ if(store_uri($absolute_uri,$absolute_local)){ #Now, download the file. If it fails, return nothing.
+ return($absolute_local,$uri);
+ } else {
+ return;
+ }
+ }
+ } else {
+ print $LOG "FILE: Unable to access $uri\n";
+ return;
+ }
+ }
+}
+
+# store a URI as a local file, and create a path if necessary
+# <1> The URI
+# <2> The file to store it in
+# returns the base of a filename
+sub store_uri {
+ my ($uri,$localfile) = @_;
+ my ($name,$path) = fileparse($localfile);
+
+ if(-f $localfile && $options->{cache}){
+ #Use localfile if it's cached and caching is allowed
+ print $LOG "URI: Using $localfile for $uri. See -h to stop cacheing\n";
+ return $localfile;
+ } else {
+ #Override localfile if new.
+ mkpath($path,1) if (head($uri));
+ if (is_error(mirror($uri,$localfile))){
+ print $LOG "URI: Unable to access $uri\n";
+ return;
+ } else {
+ print $LOG "URI: Mirrored $uri in $localfile\n";
+ return $localfile;
+ }
+ }
+}
+
+# replaces URL with \url{URL}. This code is taken right from the Perl
+# Cookbook, which I reccomend. Honestly, I'm not quite sure how it
+# works; but, it does.
+# <1> string to urlify.
+{
+
+ # I think putting them here will prevent them from needing to be
+ # loaded into memory after each function call.
+ my $urls = '(http|telnet|gopher|file|wais|ftp)';
+ my $ltrs = '\w';
+ my $gunk = '/#~:.?+=&%@!\-';
+ my $punc = '.:?\-';
+ my $any = "${ltrs}${gunk}${punc}";
+ sub urlify {
+ $_[0] =~ s!\b($urls:[$any]+?)(?=[$punc]*[^$any]|$)!\\url{$1}!igox;
+ return $_[0];
+ }
+}
+1; #package must return true.
+########################## END SUBS #############################
+
+__DATA__
+
+<!--
+
+Written by Peter Thatcher, 08/2000.
+
+html2latex.xml - the configuration file for HTML::Latex and
+html2latex.
+
+Documentation on the file format can be found in the manpage for
+HTML::Latex under the section "CONFIGURATION FILE".
+
+-->
+<!-- Head Tag needed: DO NOT DELETE!!-->
+<conf>
+ <!-- Tag description -->
+ <tag name="b" type="command">
+ <tex>textbf</tex>
+ </tag>
+ <tag name="body" type="environment">
+ <tex>document</tex>
+ </tag>
+ <tag name="br" type="single">
+ <tex>\\</tex>
+ </tag>
+ <tag name="blockquote" type="environment">
+ <tex>quote</tex>
+ </tag>
+ <tag name="center" type="environment">
+ <tex>center</tex>
+ </tag>
+ <tag name="code" type="environment">
+ <tex>verbatim</tex>
+ </tag>
+ <tag name="dd" type="other">
+ <tex></tex>
+ <tex>\N</tex>
+ </tag>
+ <tag name="dl" type="environment">
+ <tex>description</tex>
+ </tag>
+ <tag name="dt" type="other">
+ <tex>\item[</tex>
+ <tex>]</tex>
+ </tag>
+ <tag name="em" type="command">
+ <tex>emph</tex>
+ </tag>
+ <tag name="h1" type="command">
+ <tex>section*</tex>
+ </tag>
+ <tag name="h2" type="command">
+ <tex>subsection*</tex>7
+ </tag>
+ <tag name="h3" type="command">
+ <tex>subsubsection*</tex>
+ </tag>
+ <tag name="h4" type="command">
+ <tex>textbf</tex>
+ </tag>
+ <tag name="h5" type="command">
+ <tex>textbf</tex>
+ </tag>
+ <tag name="h6" type="command">
+ <tex>textbf</tex>
+ </tag>
+ <tag name="hr" type="single">
+ <tex>\hline</tex>
+ </tag>
+ <tag name="i" type="command">
+ <tex>emph</tex>
+ </tag>
+ <tag name="img" type="image">
+ <tex>includegraphics</tex>
+ </tag>
+ <tag name="li" type="single">
+ <tex>\item</tex>
+ </tag>
+ <tag name="ol" type="environment">
+ <tex>enumerate</tex>
+ </tag>
+ <tag name="p" type="single">
+ <tex>\N\N</tex>
+ </tag>
+ <tag name="pre" type="environment">
+ <tex>verbatim</tex>
+ </tag>
+ <tag name="script" type="kill"></tag>
+ <tag name="strong" type="command">
+ <tex>textbf</tex>
+ </tag>
+ <tag name="table" type="table">
+ <tex>table</tex>
+ </tag>
+ <tag name="td" type="table">
+ <tex>tr</tex>
+ </tag>
+ <tag name="title" type="command">
+ <tex>title</tex>
+ </tag>
+ <tag name="tr" type="table">
+ <tex>td</tex>
+ </tag>
+ <tag name="ul" type="environment">
+ <tex>itemize</tex>
+ </tag>
+
+ <!-- Options -->
+ <options>
+ <store>~/.html2latex</store>
+ <cache>0</cache>
+ <document_class>article</document_class>
+ <paragraph>1</paragraph>
+ <font>10</font>
+ <image>1</image>
+ <border>0</border>
+ <mbox>0</mbox>
+ <debug>0</debug>
+ </options>
+
+ <!-- LaTeX Packages-->
+ <package>fullpage</package>
+ <package>graphicx</package>
+ <package>url</package>
+
+ <!-- Tags to Ignore-->
+ <ban>code</ban>
+</conf>
diff --git a/support/html2latex/HTML/MANIFEST b/support/html2latex/HTML/MANIFEST
new file mode 100644
index 0000000000..f20fd7dafd
--- /dev/null
+++ b/support/html2latex/HTML/MANIFEST
@@ -0,0 +1,17 @@
+Changes
+COPYING
+INSTALL
+Latex.pm
+Makefile.PL
+MANIFEST
+README
+README.win.txt
+TODO
+t/tags.gif
+t/tags.correct
+t/tags.html
+t/tags.png
+t/tags.t
+t/foreigns.html
+t/foreigns.correct
+t/foreigns.t \ No newline at end of file
diff --git a/support/html2latex/HTML/Makefile.PL b/support/html2latex/HTML/Makefile.PL
new file mode 100644
index 0000000000..c7b2b16b77
--- /dev/null
+++ b/support/html2latex/HTML/Makefile.PL
@@ -0,0 +1,10 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ 'NAME' => 'HTML::Latex',
+ 'VERSION_FROM' => 'Latex.pm',
+ 'PREREQ_PM' => {
+ XML::Simple => 1.04,
+ HTML::TreeBuilder => 2.97,
+ },
+ );
diff --git a/support/html2latex/HTML/README b/support/html2latex/HTML/README
new file mode 100644
index 0000000000..01747601f8
--- /dev/null
+++ b/support/html2latex/HTML/README
@@ -0,0 +1,64 @@
+======================================================================
+ HTML::Latex
+======================================================================
+
+Summary
+=======
+
+Converts properly formatted HTML files, filehandles, or strings to
+LaTeX. It offers several options in processing, such a the ignoring
+of tags, the configuration of the TeX, and downloading of URLs. It is
+also much easier to extend than any other html2latex converter.
+
+License
+=======
+
+It is available under the GPL by default. If you are faced with
+license compatibility issues because of Perl's dual-license
+configuration, I will _consider_ releasing it under the Artistic
+License as well. Contact me at peterthatcher@asu.edu
+
+Requirements
+============
+
+For a convinient place for all of the following modules, look for
+ftp://html2latex.sourceforge.net/html2latex/pub/. They won't be the
+lastest ones, but they should work.
+
+html2latex requires the following perl modules:
+ *HTML::TreeBuilder
+ *XML::Simple
+
+html2latex can use, but does not require (I hope not, anway):
+ *LWP::Simple (called libwwwperl too)
+ *URI
+ *Image::Magik
+
+These are needed if you want to use URLs instead of just files, or if
+you want to use images in your HTML that are not on your computer, but
+are on the Internet
+
+Each of the modules may require further modules installed; check their
+documentation to see.
+
+If you want a really easy way to install both of these, try typing
+"perl -MCPAN -e shell" on the command line. This is a voodoo magic
+interface to CPAN (Comprehensize Perl Archive Network). You will need
+an internet connection running, and should be root to install as well.
+Once their, type "install MODULE", where MODULE is the name of the
+module you wish to install, such as HTML::TreeBuilder. For more info,
+try "man CPAN".
+
+Documentation
+=============
+
+All Documentation is in HTML::Latex.pm itself. The default
+configuration file (in XML) is at the bottom of it under __DATA__.
+
+
+Other
+=============
+
+If you need a good example of how to use HTML::Latex, look for
+html2latex at http://html2latex.sourceforge.net. It's why HTML::Latex
+exists.
diff --git a/support/html2latex/HTML/README.win.txt b/support/html2latex/HTML/README.win.txt
new file mode 100644
index 0000000000..3bb25ac110
--- /dev/null
+++ b/support/html2latex/HTML/README.win.txt
@@ -0,0 +1,16 @@
+Special Instructions for Windows Users:
+=======================================
+
+They only thing you really have to worry about beyond a regular UNIX
+installation is:
+
+1) Use nmake instead of make. Or, if make is unavailable, you will
+ have to copy the modules by hand. To the correct perl library
+ directory. (c:\perl\site\lib if you are using ActiveState, for
+ instance).
+
+2) Change the "store" directory. This is where all web-mirrored files
+ will be stored. The location for the store directory is found in
+ the XML configuration file at the bottom of Latex.pm under
+ <option><store>. In version 0.9, this is line number 1382. Just
+ change the text in there to anything you like.
diff --git a/support/html2latex/HTML/TODO b/support/html2latex/HTML/TODO
new file mode 100644
index 0000000000..9d18974cba
--- /dev/null
+++ b/support/html2latex/HTML/TODO
@@ -0,0 +1,20 @@
+Short Term:
+* Improve testing files.
+* Look into using Latex package Hyperref
+* Make section\section* an option. Perhaps automate TOC building.
+* change 'index.html' default behavior.
+* Possibly rearrange POD documentation.
+
+Long Term:
+
+* Make it run on Windows better/also.
+* Give more TeX options, and header style, and a table of contents and such.
+* Parsing of more HTML options, esepcially meta information in the HEAD.
+* Right an automated installer.
+
+Things left to test:
+* All options
+* Consistancy of options between objects.
+* Alternate config files
+* Good debugging info
+* Alternate stores
diff --git a/support/html2latex/HTML/t/foreigns.correct b/support/html2latex/HTML/t/foreigns.correct
new file mode 100644
index 0000000000..d670eb5ee1
--- /dev/null
+++ b/support/html2latex/HTML/t/foreigns.correct
@@ -0,0 +1,7 @@
+\documentclass[10pt]{article}
+\usepackage{fullpage, graphicx, url}
+\setlength{\parskip}{1ex}
+\setlength{\parindent}{0ex}
+\begin{document}
+!`¢{\pounds}¤{Y\hspace*{-1.4ex}--}$|${\S}\"{}{\copyright}$^{\underline{a}}$<<$\neg$$-$®$^-$$^{\circ}$$\pm$$^2$$^3$$^\prime$$\mu${\P}$\cdot$,$^1$$^{\underline{\circ}}$>>$\frac{1}{4}$$\frac{1}{2}$$\frac{3}{4}$?`\`A\'A\^A\~A\"A{\AA}{\AE}\c{C}\`E\'E\^E\"E\`I\'I\^I\"I{D\hspace*{-1.7ex}-\hspace{.9ex}}\~N\`O\'O\^O\~O\"O$\chi${\O}\`U\'U\^U\"U\'YP"s\`a\'a\^a\~a\"a\r{a}{\ae}\c{c}\`e\'e\^e\"e\`{\i}\'{\i}\^{\i}\"{\i}\v{o}\~n\`o\'o\^o\~o\"o$\div${\o}\`u\'u\^u\"u\'yp\"y
+\end{document}
diff --git a/support/html2latex/HTML/t/foreigns.html b/support/html2latex/HTML/t/foreigns.html
new file mode 100644
index 0000000000..e57e7b4655
--- /dev/null
+++ b/support/html2latex/HTML/t/foreigns.html
@@ -0,0 +1 @@
+¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ \ No newline at end of file
diff --git a/support/html2latex/HTML/t/foreigns.t b/support/html2latex/HTML/t/foreigns.t
new file mode 100755
index 0000000000..3be49e97e9
--- /dev/null
+++ b/support/html2latex/HTML/t/foreigns.t
@@ -0,0 +1,20 @@
+#!/usr/bin/perl -w
+use Latex;
+use strict;
+
+my @files = qw(t/foreigns);
+my $parser = new HTML::Latex;
+
+print '1..',scalar @files,"\n";
+
+foreach my $file (@files){
+ $parser->set_log("/dev/null");
+
+ my ($htmlfile,$latexfile) = $parser->html2latex("$file.html") or die "Couldn't process $file.html";
+
+ print "not " if (!(-f $latexfile) || `diff $latexfile $file.correct`);
+ print "ok\n";
+}
+
+unlink <*.tex>;
+
diff --git a/support/html2latex/HTML/t/tags.correct b/support/html2latex/HTML/t/tags.correct
new file mode 100644
index 0000000000..5101e8c44e
--- /dev/null
+++ b/support/html2latex/HTML/t/tags.correct
@@ -0,0 +1,116 @@
+\documentclass[10pt]{article}
+\usepackage{fullpage, graphicx, url}
+\setlength{\parskip}{1ex}
+\setlength{\parindent}{0ex}
+\title{Test \#1}
+\begin{document}
+ Table without border
+
+\begin{tabular}{cc}
+Ampersand &\& \\
+Left Angle &$<$ \\
+Right Angle &$>$ \\
+Dollar Sign &\$\$\$\$ \\
+Forward Slash &/ \\
+Percent &\% \\
+Left Brace &\{ \\
+Back Slash &$\backslash$ \\
+Right Brace &\} \\
+Underscore &\_ \\
+Funny &$\backslash$\$
+
+\end{tabular}
+
+ Nested table with border
+
+\begin{tabular}{|l|r|}
+\hline
+align left &align right \\
+ \hline
+....................................... &....................................... \\
+ \hline
+align center &
+
+\begin{tabular}{|c|c|}
+\hline
+1 &2 \\
+ \hline
+3 &4 \\
+ \hline
+
+\end{tabular}
+
+ \\
+ \hline
+
+\end{tabular}
+
+\begin{description}
+\item[Defenition of Recursion ]See Recursion
+
+\end{description}
+\section*{Header 1}
+\subsection*{Header 2}
+\subsubsection*{Header 3}
+\textbf{Header 4}
+\textbf{Header 5}
+\textbf{Header 6}
+ A small ordered list. \begin{enumerate}
+\item \textbf{Bold}
+
+\item \emph{Italics}
+
+\item \textbf{Strong}
+
+\item \emph{Emph}
+
+
+\end{enumerate}
+ A small unordered list. \begin{itemize}
+\item !@\#\$\%\^{}\&*()\{\}
+\item Nested list \begin{itemize}
+\item !@\#\$\%\^{}\&*()\{\}
+\item bill@bobb.com
+
+\end{itemize}
+
+
+\end{itemize}
+\emph{This is italisized}
+\\
+\emph{This is italisized}
+\\
+ This is not.\\
+\textbf{This is bold.}
+\\
+\textbf{This is bold}
+\\
+ This is not.\\
+ \$words\{cow\} = ``moo''; \# this is code\\
+ This is not.\\
+\begin{quote}
+This is a block quote
+\end{quote}
+ This is not.\\
+\begin{center}
+This is centered text
+\end{center}
+\\
+ This is not.\\
+ This is not a comment\\
+\begin{center}
+\includegraphics[scale=1]{./tags.png} \\
+this is an image that does not work\\
+ Both the pictures are centered.
+\end{center}
+
+
+ This is a paragraph.
+
+
+ This is a new paragraph.
+
+
+ This is a new new paragraph.
+
+\end{document}
diff --git a/support/html2latex/HTML/t/tags.gif b/support/html2latex/HTML/t/tags.gif
new file mode 100644
index 0000000000..432afb2d02
--- /dev/null
+++ b/support/html2latex/HTML/t/tags.gif
Binary files differ
diff --git a/support/html2latex/HTML/t/tags.html b/support/html2latex/HTML/t/tags.html
new file mode 100644
index 0000000000..fbc305285f
--- /dev/null
+++ b/support/html2latex/HTML/t/tags.html
@@ -0,0 +1,123 @@
+<HTML>
+<TITLE>Test #1</TITLE>
+Table without border
+<TABLE>
+<TR>
+ <TD>Ampersand</TD><TD>&amp;</TD>
+</TR>
+<TR>
+ <TD>Left Angle</TD><TD>&lt;</TD>
+</TR>
+<TR>
+ <TD>Right Angle</TD><TD>&gt;</TD>
+</TR>
+<TR>
+ <TD>Dollar Sign</TD><TD>$$$$</TD>
+</TR>
+<TR>
+ <TD>Forward Slash</TD><TD>/</TD>
+</TR>
+<TR>
+ <TD>Percent</TD><TD>%</TD>
+</TR>
+<TR>
+ <TD>Left Brace</TD><TD>{</TD>
+</TR>
+<TR>
+ <TD>Back Slash</TD><TD>\</TD>
+</TR>
+<TR>
+ <TD>Right Brace</TD><TD>}</TD>
+</TR>
+<TR>
+ <TD>Underscore</TD><TD>_</TD>
+</TR>
+<TR>
+ <TD>Funny</TD><TD>\$</TD>
+</TR>
+</TABLE>
+Nested table with border
+<TABLE border="1">
+<TR>
+ <TD align="left">align left</TD>
+ <TD align="right">align right</TD>
+</TR>
+<TR>
+<TD>.......................................</TD>
+<TD>.......................................</TD>
+</TR>
+<TR>
+ <TD align="center">align center</TD>
+ <TD align="center">
+ <TABLE border="2">
+ <TR>
+ <TD>1</TD>
+ <TD>2</TD>
+ </TR>
+ <TR>
+ <TD>3</TD>
+ <TD>4</TD>
+ </TR>
+ </TABLE>
+ </TD>
+</TR>
+</TABLE>
+<DL>
+<DT>Defenition of Recursion
+<DD>See Recursion
+</DL>
+<H1>Header 1</H1>
+<H2>Header 2</H2>
+<H3>Header 3</H3>
+<H4>Header 4</H4>
+<H5>Header 5</H5>
+<H6>Header 6</H6>
+
+ A small ordered list.
+<OL>
+<LI> <B>Bold</B>
+<LI> <I>Italics</I>
+<LI> <STRONG>Strong</STRONG>
+<LI> <EM>Emph</EM>
+</OL>
+
+ A small unordered list.
+<UL>
+<LI> !@#$%^&*(){}
+<LI>
+ Nested list
+ <UL>
+ <LI> !@#$%^&*(){}
+ <LI> bill@bobb.com
+ </UL>
+</UL>
+
+<EM>This is italisized</EM><BR>
+<I>This is italisized</I><BR>
+This is not.<BR>
+<STRONG>This is bold.</STRONG><BR>
+<B>This is bold</B><BR>
+This is not.<BR>
+<CODE> $words{cow} = "moo"; # this is code</CODE><BR>
+This is not.<BR>
+<!-- This is a comment at the end of your document -->
+<BLOCKQUOTE>This is a block quote</BLOCKQUOTE>
+This is not.<BR>
+<CENTER>This is centered text</CENTER><BR>
+This is not.<BR>
+This is not a comment<BR>
+<CENTER>
+<IMG src="tags.gif" alt="this is an image that works"><BR>
+<IMG src="cow.jpg" alt="this is an image that does not work"><BR>
+Both the pictures are centered.
+</CENTER>
+<P>This is a paragraph.<P>This is a new paragraph.<P>This is a new new paragraph.
+</HTML>
+
+
+
+
+
+
+
+
diff --git a/support/html2latex/HTML/t/tags.png b/support/html2latex/HTML/t/tags.png
new file mode 100644
index 0000000000..01bdf65e2b
--- /dev/null
+++ b/support/html2latex/HTML/t/tags.png
Binary files differ
diff --git a/support/html2latex/HTML/t/tags.t b/support/html2latex/HTML/t/tags.t
new file mode 100755
index 0000000000..648e3da0e8
--- /dev/null
+++ b/support/html2latex/HTML/t/tags.t
@@ -0,0 +1,19 @@
+#!/usr/bin/perl -w
+use Latex;
+use strict;
+
+my @files = qw(t/tags);
+my $parser = new HTML::Latex;
+
+print '1..',scalar @files,"\n";
+
+foreach my $file (@files){
+ $parser->set_log("/dev/null");
+
+ my ($htmlfile,$latexfile) = $parser->html2latex("$file.html") or die "Couldn't process $file.html";
+
+ print "not " if (!(-f $latexfile) || `diff $latexfile $file.correct`);
+ print "ok\n";
+}
+
+unlink <*.tex>;