#!/usr/bin/perl -w
use strict;
use Getopt::Long;
use Pod::Usage;
use LaTeXML::Post;

#**********************************************************************
# Parse command line.

my($source,$destination)=(".","");
my($help)=(0);
my $format=undef;
my $verbosity=0;
my $stylesheet;
GetOptions("destination=s"=>\$destination,
	   "source=s"     =>\$source,
	   "verbose+"     =>\$verbosity,
	   "stylesheet:s" =>\$stylesheet,
	   "format=s"     =>\$format,
	   "help|?"       =>\$help,
	  ) or pod2usage(2);
pod2usage(1) if $help;
pod2usage("Missing input xmlfile") unless @ARGV;

my $xmlfile = shift(@ARGV);

#**********************************************************************
# Do the processing.
binmode(STDERR,":utf8");
binmode(STDOUT,":utf8");

my $doc = LaTeXML::Post->new()->process($xmlfile, 
					sourceDirectory=> $source,
					destination    => $destination,
					format         => $format,
					stylesheet     => $stylesheet,
					verbosity      => $verbosity,
					toString       => !$destination);

print $doc unless $destination;

#**********************************************************************
__END__

=head1 NAME

C<latexmlpost> postprocesses an xml file generated by latexml for common tasks,
such ad convert math to images and processing graphics inclusions for the web.

=head1 SYNOPSIS

latexmlpost [options] xmlfile

  Options:
   --source=sourcedir         specifies directory of source TeX file.
   --destination=outputfile   specifies output file (and directory).
   --format=html|xhtml        requests processing for html(+images), or xhtml(+MathML) respectively
   --stylesheet=xslfile       requests the XSL transform of the document using the given
                              xslfile as stylesheet.
   --verbose                  prints progress messages during processing.
   --help                     shows help message.

=head1 OPTIONS AND ARGUMENTS

latexmlpost postprocesses an xml file, C<xmlfile>, generated by latexml 
to perform common tasks, such as convert math to images and processing
graphics inclusions for the web.  If C<-> is given for C<xmlfile>, the
xml data is read from standard input.

=over 4

=item B<--destination=>I<destination>

Specifies the destination file and directory.  The directory is needed for
mathimages and graphics processing.

=item B<--source>=I<source>

Specifies the directory where the original latex source is located.
Unless latexmlpost is run from that directory, it may be necessary
to specify this option in order to find graphics and style files.

=item B<--stylesheet>=I<xslfile>

Requests the XSL transformation of the document using the given xslfile as stylesheet.
If the stylesheet is omitted, a `standard' one will be used (C<dtd/LaTeXML.xsl>).

=item B<--help>

Shows this help message.

=back

=head1 DESCRIPTION


=cut
#**********************************************************************

