Listing 1. Perl Function Converting a LaTeX String to an HTML Markup

sub LaTeX2HTML {
  # Directory to put generated image
  my $ImgPath = "/usr/apache/htdocs/l2h/images";
  # URL to image directory
  my $ImgURL = "<A HREF="http://myserver/l2h/images";">http://myserver/l2h/images";</A>
  # latex2html executable
  my $L2H = "/opt/local/bin/latex2html";

  my $latexString = shift;
  # Use time and PID for unique filename
  my $filename = "image$^T$$";

  open (LATEXFILE, ">$filename.tex")
                   || die "File Open Error";
  print LATEXFILE "\\documentclass[12pt]
                          {article} \n
                   \\begin{document} \n
                   \\begin{equation} \n
                   $latexString \n
                   \\end{equation} \n
                   \\end{document}";
  close (LATEXFILE);

  system ("$L2H $filename.tex > /dev/null");
  rename "$filename/img1.gif",
         "$ImgPath/$filename.gif";
  system ("rm -rf $filename.tex $filename");

  my $HTMLstr =
        "<IMG SRC=\"$ImgURL/$filename.gif\">";

  return $HTMLstr;
}