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 {
85: $section = "-section $section";
86: # Escape the pipes so they are considered ORs in the
87: # RE for podselect's "section" option, and not
88: # pipes by the shell:
89: $section =~ s/\|/\\\|/g;
90: }
91: $file = '../../loncom/' . $file;
92: my $tempfile = 't' . substr($file, rindex($file, '/') + 1);
93: system ("cp $file $tmpdir");
94: # The "echo" command is necessary; pod2latex can't
95: # handle a perl file that *starts* with pod.
96: system ("echo > $tmpdir/$tempfile; cat $file | podselect $section >> $tmpdir/$tempfile; cd $tmpdir; pod2latex -h1level 2 $tempfile");
97: my $latexFile = substr($tempfile, 0, rindex($tempfile, '.')) . '.tex';
98: open LATEX_FILE, $tmpdir . '/' . $latexFile;
99: print <LATEX_FILE>;
100: print "\n\n";
101: }
102: }
103: }
104:
105: # Print out the footer.
106: open (LATEX_FILE, $dirprefix . "Latex_Footer.tex");
107: print <LATEX_FILE>;
108:
109: # Remove the temp directory
110: system ("rm -rf $tmpdir");
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>