Annotation of doc/help/render.texxml.pl, revision 1.19

1.1       bowersj2    1: # The LearningOnline Network with CAPA
                      2: # Perl script to render texxml files to a dvi
                      3: #
                      4: # Copyright Michigan State University Board of Trustees
                      5: #
                      6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      7: #
                      8: # LON-CAPA is free software; you can redistribute it and/or modify
                      9: # it under the terms of the GNU General Public License as published by
                     10: # the Free Software Foundation; either version 2 of the License, or
                     11: # (at your option) any later version.
                     12: #
                     13: # LON-CAPA is distributed in the hope that it will be useful,
                     14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16: # GNU General Public License for more details.
                     17: #
                     18: # You should have received a copy of the GNU General Public License
                     19: # along with LON-CAPA; if not, write to the Free Software
                     20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     21: #
                     22: # /home/httpd/html/adm/gpl.txt
                     23: #
                     24: # http://www.lon-capa.org/
                     25: #
                     26: # 7-16-2002 Jeremy Bowers
                     27: 
                     28: use strict;
                     29: use Fcntl;
                     30: use POSIX qw(tmpnam);
                     31: 
1.2       bowersj2   32: if ( scalar(@ARGV) < 2 )
1.1       bowersj2   33: {
                     34:     print (<<USAGE);
                     35: Usage: $0 texxml_file_name or
1.17      albertel   36:        perl $0 -- texxml_file_name [epssource] [--with-filenames]
1.6       bowersj2   37:        where "texxml_file_name" optionally includes the extension
1.1       bowersj2   38: Output: texxml_file_name.dvi
                     39: 
                     40: $0 renders texxml files into dvi files by copying the tex file
                     41: resulting from from texxml2latex.pl and the referenced eps files
                     42: into a temporary directory and running LaTeX on the .tex file.
                     43: 
1.2       bowersj2   44: If a second argument is passed, it is used as the location of the 
                     45: .eps files the document uses.
                     46: 
1.1       bowersj2   47: Must be run as somebody with permissions to write temp files and 
                     48: access /home/httpd/html/adm/help/eps.
1.17      albertel   49: 
                     50: If thre is a second argument, it will be used as the path to the 
                     51: eps files, otherwise "../../loncom/html/adm/help/eps" is used.
                     52: 
                     53: If the optional argument --with-filenames is included then
                     54: the filename for each fragment is stuck into the finished file.
1.1       bowersj2   55: USAGE
                     56: 
                     57:     exit();
                     58: }
                     59: 
                     60: my $tmpdir = tmpnam();
                     61: my $fileroot = $ARGV[1];
1.6       bowersj2   62: 
                     63: if (substr($fileroot, -7) eq ".texxml")
                     64: {
                     65:     $fileroot = substr($fileroot, 0, -7);
                     66: }
                     67: 
1.11      albertel   68: my $epssource = "../../loncom/html/adm/help/eps";
1.17      albertel   69: # override eps source, for build on install
                     70: if ( $ARGV[2] && $ARGV[2] ne '--with-filenames') {
                     71:     $epssource = $ARGV[2];
                     72: }
1.2       bowersj2   73: 
1.17      albertel   74: my $include_filenames='';
                     75: if ( $ARGV[2] eq '--with-filenames' || $ARGV[3] eq '--with-filenames') {
                     76:     $include_filenames='--with-filenames';
1.2       bowersj2   77: }
1.1       bowersj2   78: 
1.18      albertel   79: #my $redir = ">& /dev/null"; # empty this for easier debugging
                     80: my $redir = "~/error_log.txt";
                     81: system("rm -f $redir");
                     82: $redir=">> $redir";
1.3       bowersj2   83: 
1.5       bowersj2   84: mkdir $tmpdir, 0755;
1.1       bowersj2   85: 
                     86: print "Converting texxml to tex...\n";
1.17      albertel   87: if (system ( "perl texxml2latex.pl $fileroot.texxml $include_filenames > $tmpdir/$fileroot.tex" )) {
1.15      bowersj2   88:     $! = 1;
                     89:     die "Terminated render because texxml2latex failed; see previous error message.";
                     90: };
1.1       bowersj2   91: 
                     92: print "Copying .eps files...\n";
1.2       bowersj2   93: system ( "cp $epssource/* $tmpdir/" );
1.1       bowersj2   94: 
                     95: print "Running Latex...\n";
1.14      bowersj2   96: system ( "cd $tmpdir; echo | latex $fileroot $redir; echo | latex $fileroot $redir; makeindex $fileroot.idx; echo | latex $fileroot\ $redir; " );
1.1       bowersj2   97: 
1.2       bowersj2   98: print "Running dvips...\n";
1.10      albertel   99: system ( "cd $tmpdir; dvips -Ppdf -G0 -f $fileroot.dvi > $fileroot.ps  " );
1.1       bowersj2  100: 
1.2       bowersj2  101: print "Copying ps file...\n";
1.1       bowersj2  102: system ( "cp $tmpdir/$fileroot.ps .");
                    103: 
1.7       bowersj2  104: print "Converting to PDF (may take a bit)...\n";
                    105: system ( "ps2pdf $fileroot.ps $fileroot.pdf" );
                    106: 
1.19    ! www       107: print "Rescuing log and tex file for debugging ...\n";
        !           108: system ("cp $tmpdir/$fileroot.log ."); 
        !           109: system ("cp $tmpdir/$fileroot.tex ."); 
        !           110: 
1.1       bowersj2  111: print "Clearing temp directory...\n";
1.12      albertel  112: system ( "rm -rf $tmpdir" );
1.1       bowersj2  113: 
1.3       bowersj2  114: if ( -e $fileroot . ".ps" )
                    115: {
1.7       bowersj2  116:     print "$fileroot.ps and $fileroot.pdf are ready.\n";
1.3       bowersj2  117: }
                    118: else
                    119: {
1.19    ! www       120:     print "Generation of $fileroot.ps failed.\n";
1.3       bowersj2  121: }

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