| … | |
… | |
| 4 | ################################################################ |
4 | ################################################################ |
| 5 | # Copyright @1995-1999 by Michael E. Gage, Arnold K. Pizer and |
5 | # Copyright @1995-1999 by Michael E. Gage, Arnold K. Pizer and |
| 6 | # WeBWorK at the University of Rochester. All rights reserved. |
6 | # WeBWorK at the University of Rochester. All rights reserved. |
| 7 | ################################################################ |
7 | ################################################################ |
| 8 | |
8 | |
| 9 | my $debugON=1; ## set this to 1 to save debugging information for errors in hardcopy output |
9 | my $debugON=0; ## set this to 1 to save debugging information for errors in hardcopy output |
| 10 | |
10 | |
| 11 | use lib '.'; use webworkInit; # WeBWorKInitLine |
11 | use lib '.'; use webworkInit; # WeBWorKInitLine |
| 12 | require 5.001; |
12 | require 5.001; |
| 13 | |
13 | |
| 14 | $/ ="\n"; |
14 | $/ ="\n"; |
| … | |
… | |
| 522 | |
522 | |
| 523 | } |
523 | } |
| 524 | |
524 | |
| 525 | $texSource .= "\\end{itemize} \\par\n"; |
525 | $texSource .= "\\end{itemize} \\par\n"; |
| 526 | } |
526 | } |
|
|
527 | if (defined($Global::WARNINGS) and $Global::WARNINGS) { |
|
|
528 | my $warnings = '{\\bf WARNINGS:\par{\\tiny ' . $Global::WARNINGS . ' }}'; |
|
|
529 | $warnings =~ s|/|\\\-/|g; #allow linebreaks in the middle of URLs |
|
|
530 | $warnings =~ s/<br>/\\par\n/ig; #introduce breaks at linebreaks and paragraphs |
|
|
531 | $warnings =~ s/<p>/\\par\n/ig; |
|
|
532 | $warnings =~ s/\#/\\\#/g; #protect against some of the symbols which are reserved in tex |
|
|
533 | $warnings =~ s/\_/\\\_/g; |
|
|
534 | $warnings =~ s/\>/\\\>/g; |
|
|
535 | $warnings =~ s/\</\\\</g; |
|
|
536 | $texSource .= $warnings; |
|
|
537 | } |
|
|
538 | $Global::WARNINGS = ''; #reset the Global::WARNINGS parameter |
| 527 | } |
539 | } |
| 528 | |
540 | |
| 529 | |
541 | |
| 530 | } |
542 | } |
| 531 | |
543 | |
| … | |
… | |
| 638 | |
650 | |
| 639 | my $dviCommandLine = "$Global::externalLatexPath $texFileBaseName.tex >/dev/null 2>/dev/null"; |
651 | my $dviCommandLine = "$Global::externalLatexPath $texFileBaseName.tex >/dev/null 2>/dev/null"; |
| 640 | my $psCommandLine = "$Global::externalDvipsPath -o $texFileBaseName.ps $texFileBaseName.dvi >/dev/null 2>/dev/null"; |
652 | my $psCommandLine = "$Global::externalDvipsPath -o $texFileBaseName.ps $texFileBaseName.dvi >/dev/null 2>/dev/null"; |
| 641 | my $pdfCommandLine = "$Global::externalPs2pdfPath $texFileBaseName.ps $texFileBaseName.pdf"; |
653 | my $pdfCommandLine = "$Global::externalPs2pdfPath $texFileBaseName.ps $texFileBaseName.pdf"; |
| 642 | |
654 | |
|
|
655 | # make sure that you are not using old copies of the following files: |
|
|
656 | unlink("$texFileBaseName.dvi","$texFileBaseName.ps", "$texFileBaseName.pdf"); |
|
|
657 | |
| 643 | if($targetFormat eq "pdf") { |
658 | if($targetFormat eq "pdf") { |
| 644 | system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed."; |
659 | #system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed."; |
|
|
660 | system($dviCommandLine); -e "$texFileBaseName.dvi" or &logPrint($texFileBaseName); |
|
|
661 | # this gives more information about pure TeX errors |
|
|
662 | # (i.e. the .pg file has compiled but the resulting TeX is not well formed.) |
|
|
663 | |
|
|
664 | # The following commands don't usually give very useful error messages anyway so just report failure. |
| 645 | system($psCommandLine); -e "$texFileBaseName.ps" or die "ps generation failed."; |
665 | system($psCommandLine); -e "$texFileBaseName.ps" or die "ps generation failed."; |
| 646 | system($pdfCommandLine); -e "$texFileBaseName.pdf" or die "pdf generation failed."; |
666 | system($pdfCommandLine); -e "$texFileBaseName.pdf" or die "pdf generation failed."; |
| 647 | $mimeType = "application/pdf"; |
667 | $mimeType = "application/pdf"; |
| 648 | } elsif($targetFormat eq "ps") { |
668 | } elsif($targetFormat eq "ps") { |
| 649 | system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed."; |
669 | #system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed."; |
|
|
670 | system($dviCommandLine); -e "$texFileBaseName.dvi" or &logPrint($texFileBaseName); |
|
|
671 | # this gives more information about pure TeX errors |
|
|
672 | # (i.e. the .pg file has compiled but the resulting TeX is not well formed.) |
| 650 | system($psCommandLine); -e "$texFileBaseName.ps" or die "ps generation failed."; |
673 | system($psCommandLine); -e "$texFileBaseName.ps" or die "ps generation failed."; |
| 651 | $mimeType = "application/postscript"; |
674 | $mimeType = "application/postscript"; |
| 652 | } elsif($targetFormat eq "dvi") { |
675 | } elsif($targetFormat eq "dvi") { |
| 653 | system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed."; |
676 | #system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed."; |
|
|
677 | system($dviCommandLine); -e "$texFileBaseName.dvi" or &logPrint($texFileBaseName); |
|
|
678 | # this gives more information about pure TeX errors |
|
|
679 | # (i.e. the .pg file has compiled but the resulting TeX is not well formed.) |
| 654 | $mimeType = "application/x-dvi"; |
680 | $mimeType = "application/x-dvi"; |
| 655 | } elsif($targetFormat eq "tex") { |
681 | } elsif($targetFormat eq "tex") { |
| 656 | $mimeType = "application/tex"; |
682 | $mimeType = "application/tex"; |
| 657 | } else { |
683 | } else { |
| 658 | die "unrecognized format: $targetFormat"; |
684 | die "unrecognized format: $targetFormat"; |
| … | |
… | |
| 697 | } |
723 | } |
| 698 | |
724 | |
| 699 | # ----- |
725 | # ----- |
| 700 | |
726 | |
| 701 | sub logPrint { |
727 | sub logPrint { |
|
|
728 | my $texFileBaseName=shift; |
| 702 | print &htmlTOP("TeX Error or error in creating PostScript file"); |
729 | print &htmlTOP("TeX Error or error in creating PostScript file"); |
| 703 | open (LOGFILE, " $tempDirectory$texFile$psvn.log") |
730 | open (LOGFILE, " $texFileBaseName.log") |
| 704 | || print "<H3>Can't open log file:</H3> path= $tempDirectory$texFile$psvn.log<BR>$!<BR><BR>" ; |
731 | || print "<H3>Can't open log file:</H3> path= $texFileBaseName.log<BR>$!<BR><BR>" ; |
| 705 | |
732 | |
| 706 | |
733 | |
| 707 | print "<H3>TeX Error Log:</H3>"; |
734 | print "<H3>TeX Error Log:</H3>"; |
| 708 | my $print_error_switch = ($debugON) ? 1: 0; |
735 | my $print_error_switch = ($debugON) ? 1: 0; |
| 709 | my $out=''; |
736 | my $out=''; |
| … | |
… | |
| 716 | $print_error_switch = 1 if $out =~ /^!/; # after a fatal error start printing messages |
743 | $print_error_switch = 1 if $out =~ /^!/; # after a fatal error start printing messages |
| 717 | print protect_HTML($out)."<BR>\n" if $print_error_switch; |
744 | print protect_HTML($out)."<BR>\n" if $print_error_switch; |
| 718 | } |
745 | } |
| 719 | close(LOGFILE); |
746 | close(LOGFILE); |
| 720 | |
747 | |
| 721 | open (TEXFILE, "${tempDirectory}${texFile}${psvn}.tex") |
748 | open (TEXFILE, "$texFileBaseName.tex") |
| 722 | || print "<H3>Can't open tex source file:</H3> path= ${tempDirectory}${texFile}${psvn}.tex:<BR> $!<BR><BR>\n"; |
749 | || print "<H3>Can't open tex source file:</H3> path= $texFileBaseName.tex:<BR> $!<BR><BR>\n"; |
| 723 | print "<BR>\n<H3>TeX Source File:</H3><BR>\n"; |
750 | print "<BR>\n<H3>TeX Source File:</H3><BR>\n"; |
| 724 | print "<PRE>"; |
751 | print "<PRE>"; |
| 725 | |
752 | |
| 726 | my $lineNumber = 1; |
753 | my $lineNumber = 1; |
| 727 | while (<TEXFILE>) { |
754 | while (<TEXFILE>) { |
| 728 | print protect_HTML("$lineNumber $_")."\n"; |
755 | print protect_HTML("$lineNumber $_")."\n"; |
| 729 | $lineNumber++; |
756 | $lineNumber++; |
| 730 | } |
757 | } |
| 731 | close(TEXFILE); |
758 | close(TEXFILE); |
| 732 | print "</PRE>"; |
759 | print "</PRE>"; |
| 733 | print &htmlBOTTOM("downloadPS.pl", \%inputs); |
760 | print &htmlBOTTOM("welcomeAction.pl", \%inputs); |
| 734 | } |
761 | } |
| 735 | sub protect_HTML { |
762 | sub protect_HTML { |
| 736 | my $line = shift; |
763 | my $line = shift; |
| 737 | chomp($line); |
764 | chomp($line); |
| 738 | $line =~s/\&/&/g; |
765 | $line =~s/\&/&/g; |