File:  [LON-CAPA] / doc / help / texxml2latex.pl
Revision 1.5: download - view: text, annotated - select for diffs
Fri Jul 18 20:42:27 2003 UTC (20 years, 9 months ago) by bowersj2
Branches: MAIN
CVS tags: HEAD
Added ability to use the "pod" tag in a texxml file to tell the help
system to grab stuff out of a perl module and format it as .tex. The
good news is this is a good deal more powerful then I would have hoped;
code to select various parts of the perldoc was already written; see
"man Pod::Select". (Cool!)

Also updated the formatting; this code is some of the first code I wrote
and it did not conform to LON-CAPA style.

    1: #!/usr/bin/perl
    2: 
    3: # The LearningOnline Network with CAPA
    4: # Converts a texxml file into a single tex file
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # 7-16-2002 Jeremy Bowers
   29: 
   30: use strict;
   31: use HTML::TokeParser;
   32: use GDBM_File;
   33: use File::Temp;
   34: 
   35: # accept texxml document on standard in
   36: my $p = HTML::TokeParser->new( $ARGV[0] );
   37: my $dirprefix = "../../loncom/html/adm/help/tex/";
   38: 
   39: # Make myself a temp dir for processing POD
   40: my $tmpdir = File::Temp::tempdir('loncapahelpgenXXXXXXX', TMPDIR => 1);
   41: 
   42: # Print the header
   43: open (LATEX_FILE, $dirprefix . "Latex_Header.tex");
   44: print <LATEX_FILE>;
   45: 
   46: while (my $token = $p->get_token())
   47: {
   48:     my $type = $token->[0];
   49:     if ($type eq 'S') {
   50: 	my $tag = $token->[1];
   51: 	my $attr = $token->[2];
   52: 	if ($tag eq 'section') {
   53: 	    my $title = $attr->{'name'};
   54: 	    print "\\section{$title}\n\n";
   55: 	}
   56: 
   57: 	if ($tag eq 'subsection') {
   58: 	    my $title = $attr->{'name'};
   59: 	    print "\\subsection{$title}\n\n";
   60: 	}
   61: 
   62: 	if ($tag eq 'subsubsection') {
   63: 	    my $title = $attr->{'name'};
   64: 	    print "\\subsubsection{$title}\n\n";
   65: 	}
   66: 
   67: 	if ($tag eq 'file') {
   68: 	    my $file = $attr->{'name'};
   69: 	    open (LATEX_FILE, $dirprefix . $file);
   70: 	    print <LATEX_FILE>;
   71: 	    print "\n\n";
   72: 	}
   73: 
   74: 	if ($tag eq 'tex') {
   75: 	    print "\n\n";
   76: 	    print $attr->{'content'};
   77: 	    print "\n\n";
   78: 	}
   79: 
   80: 	if ($tag eq 'pod') {
   81: 	    my $file = $attr->{'file'};
   82: 	    my $section = $attr->{'section'};
   83: 	    if (!defined($section)) { $section = ''; }
   84: 	    else { $section = "-section $section"; }
   85: 	    $file = '../../loncom/' . $file;
   86: 	    my $tempfile = 't' . substr($file, rindex($file, '/') + 1);
   87: 	    system ("cp $file $tmpdir");
   88: 	    # The "echo" command is necessary; pod2latex can't
   89: 	    # handle a perl file that *starts* with pod.
   90: 	    system ("echo > $tmpdir/$tempfile; cat $file | podselect $section >> $tmpdir/$tempfile; cd $tmpdir; pod2latex $tempfile");
   91: 	    my $latexFile = substr($tempfile, 0, rindex($tempfile, '.')) . '.tex';
   92: 	    open LATEX_FILE, $tmpdir . '/' . $latexFile;
   93: 	    print <LATEX_FILE>;
   94: 	    print "\n\n";
   95: 	}
   96:     }
   97: }
   98: 
   99: # Print out the footer.
  100: open (LATEX_FILE, $dirprefix . "Latex_Footer.tex");
  101: print <LATEX_FILE>;
  102: 
  103: # Remove the temp directory
  104: system ("rm -rf $tmpdir");

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>