Annotation of doc/help/texxml2latex.pl, revision 1.5
1.1 bowersj2 1: #!/usr/bin/perl
2:
1.2 bowersj2 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:
1.1 bowersj2 30: use strict;
31: use HTML::TokeParser;
32: use GDBM_File;
1.5 ! bowersj2 33: use File::Temp;
1.1 bowersj2 34:
35: # accept texxml document on standard in
36: my $p = HTML::TokeParser->new( $ARGV[0] );
1.4 albertel 37: my $dirprefix = "../../loncom/html/adm/help/tex/";
1.1 bowersj2 38:
1.5 ! bowersj2 39: # Make myself a temp dir for processing POD
! 40: my $tmpdir = File::Temp::tempdir('loncapahelpgenXXXXXXX', TMPDIR => 1);
! 41:
1.1 bowersj2 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];
1.5 ! bowersj2 49: if ($type eq 'S') {
1.1 bowersj2 50: my $tag = $token->[1];
51: my $attr = $token->[2];
1.5 ! bowersj2 52: if ($tag eq 'section') {
1.1 bowersj2 53: my $title = $attr->{'name'};
54: print "\\section{$title}\n\n";
55: }
56:
1.5 ! bowersj2 57: if ($tag eq 'subsection') {
1.1 bowersj2 58: my $title = $attr->{'name'};
59: print "\\subsection{$title}\n\n";
60: }
61:
1.5 ! bowersj2 62: if ($tag eq 'subsubsection') {
1.1 bowersj2 63: my $title = $attr->{'name'};
64: print "\\subsubsection{$title}\n\n";
65: }
66:
1.5 ! bowersj2 67: if ($tag eq 'file') {
1.1 bowersj2 68: my $file = $attr->{'name'};
69: open (LATEX_FILE, $dirprefix . $file);
70: print <LATEX_FILE>;
1.3 bowersj2 71: print "\n\n";
1.1 bowersj2 72: }
73:
1.5 ! bowersj2 74: if ($tag eq 'tex') {
1.3 bowersj2 75: print "\n\n";
1.1 bowersj2 76: print $attr->{'content'};
1.3 bowersj2 77: print "\n\n";
1.1 bowersj2 78: }
1.5 ! bowersj2 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: }
1.1 bowersj2 96: }
97: }
98:
99: # Print out the footer.
100: open (LATEX_FILE, $dirprefix . "Latex_Footer.tex");
101: print <LATEX_FILE>;
1.5 ! bowersj2 102:
! 103: # Remove the temp directory
! 104: system ("rm -rf $tmpdir");
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>