[system] / trunk / pg / macros / dangerousMacros.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/dangerousMacros.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 3358 Revision 3359
434# ${main::templateDirectory} 434# ${main::templateDirectory}
435# ${main::scriptDirectory}tth # path to tth application 435# ${main::scriptDirectory}tth # path to tth application
436# Global macros: 436# Global macros:
437# None 437# None
438 438
439my ($tthPreambleFile, $tthPreambleContents); # the contents of this file will not change during problem compilation 439# the contents of this file will not change during problem compilation it
440 # it only needs to be read once 440# only needs to be read once. however, the contents of the file may change,
441# and indeed the file refered to may change, between rendering passes. thus,
442# we need to keep track of the file name and the mtime as well.
443my ($tthPreambleFile, $tthPreambleMtime, $tthPreambleContents);
444
441sub tth { 445sub tth {
442 my $inputString = shift; 446 my $inputString = shift;
443 447
444 # read the contents of the tthPreamble.tex file, unless it has already been read
445 unless ( defined( $tthPreambleContents) ) {
446 $tthPreambleFile = "${templateDirectory}tthPreamble.tex" if ( -r "${templateDirectory}tthPreamble.tex" ); 448 my $thisFile = "${templateDirectory}tthPreamble.tex" if -r "${templateDirectory}tthPreamble.tex";
447 if ( defined($tthPreambleFile) ) { 449
450 if (defined $thisFile) {
451 my $thisMtime = (stat $thisFile)[9];
452 my $load =
453 # load preamble if we haven't loaded it ever
454 (not defined $tthPreambleFile or not defined $tthPreambleMtime or not defined $tthPreambleContents)
455 ||
456 # load if the file path has changed
457 ($tthPreambleFile ne $thisFile)
458 ||
459 # load if the file has been modified
460 ($tthPreambleMtime < $thisMtime);
461
462 if ($load) {
448 local(*TTHIN); 463 local(*TTHIN);
449 open (TTHIN, "${templateDirectory}tthPreamble.tex") || die "Can't open file ${templateDirectory}tthPreamble.tex"; 464 open (TTHIN, "${templateDirectory}tthPreamble.tex") || die "Can't open file ${templateDirectory}tthPreamble.tex";
450 #my @tthPreambleArray = <TTHIN>;
451 local($/); 465 local($/);
452 $/ = undef; 466 $/ = undef;
453 $tthPreambleContents = <TTHIN>;#join("",@tthPreambleArray); 467 $tthPreambleContents = <TTHIN>;
454 close(TTHIN); 468 close(TTHIN);
455 469
456 $tthPreambleContents =~ s/(.)\n/$1%\n/g; # thanks to Jim Martino 470 $tthPreambleContents =~ s/(.)\n/$1%\n/g; # thanks to Jim Martino
457 # each line in the definition file 471 # each line in the definition file
458 # should end with a % to prevent 472 # should end with a % to prevent
459 # adding supurious paragraphs to output. 473 # adding supurious paragraphs to output.
460 474
461 $tthPreambleContents .="%\n"; # solves the problem if the file doesn't end with a return. 475 $tthPreambleContents .="%\n"; # solves the problem if the file doesn't end with a return.
462
463 } else {
464 $tthPreambleContents = "";
465 } 476 }
477 } else {
478 $tthPreambleContents = "";
466 } 479 }
467 480
468 $inputString = $tthPreambleContents . $inputString; 481 $inputString = $tthPreambleContents . $inputString;
469 $inputString = "<<END_OF_TTH_INPUT_STRING;\n\n\n" . $inputString . "\nEND_OF_TTH_INPUT_STRING\necho \"\" >/dev/null"; #it's not clear why another command is needed. 482 $inputString = "<<END_OF_TTH_INPUT_STRING;\n\n\n" . $inputString . "\nEND_OF_TTH_INPUT_STRING\necho \"\" >/dev/null"; #it's not clear why another command is needed.
470 483
471 # $tthpath is now taken from $Global::externalTTHPath via %envir. 484 # $tthpath is now taken from $Global::externalTTHPath via %envir.
472 my $tthpath = $envir{externalTTHPath}; 485 my $tthpath = $envir{externalTTHPath};
494sub symbolConvert { 507sub symbolConvert {
495 my $string = shift; 508 my $string = shift;
496 $string =~ s/\x5C/\&#092;/g; #\ 92 &#092; 509 $string =~ s/\x5C/\&#092;/g; #\ 92 &#092;
497 $string =~ s/\x7B/\&#123;/g; #{ 123 &#123; 510 $string =~ s/\x7B/\&#123;/g; #{ 123 &#123;
498 $string =~ s/\x7D/\&#125;/g; #} 125 &#125; 511 $string =~ s/\x7D/\&#125;/g; #} 125 &#125;
499 $string =~ s/\xE7/\&#193;/g; #ç 231 &#193; 512 $string =~ s/\xE7/\&#193;/g; #Á 231 &#193;
500 $string =~ s/\xE6/\&#202;/g; #æ 230 &#202; 513 $string =~ s/\xE6/\&#202;/g; #Ê 230 &#202;
501 $string =~ s/\xE8/\&#203;/g; #è 232 &#203; 514 $string =~ s/\xE8/\&#203;/g; #Ë 232 &#203;
502 $string =~ s/\xF3/\&#219;/g; #ó 243 &#219; 515 $string =~ s/\xF3/\&#219;/g; #Û 243 &#219;
503 $string =~ s/\xA5/\&bull;/g; #¥ 165 &bull; 516 $string =~ s/\xA5/\&bull;/g; # 165 &bull;
504 $string =~ s/\xB2/\&le;/g; #² 178 &le; 517 $string =~ s/\xB2/\&le;/g; #¾ 178 &le;
505 $string =~ s/\xB3/\&ge;/g; #³ 179 &ge; 518 $string =~ s/\xB3/\&ge;/g; # 179 &ge;
506 $string =~ s/\xB6/\&part;/g; # 182 &part; 519 $string =~ s/\xB6/\&part;/g; # 182 &part;
507 $string =~ s/\xCE/\&#338;/g; #Î 206 &#338; 520 $string =~ s/\xCE/\&#338;/g; # 206 &#338;
508 $string =~ s/\xD6/\&#732/g; #Ö 214 &#732; 521 $string =~ s/\xD6/\&#732/g; #÷ 214 &#732;
509 $string =~ s/\xD9/\&Yuml;/g; #Ù 217 &Yuml; 522 $string =~ s/\xD9/\&Yuml;/g; # 217 &Yuml;
510 $string =~ s/\xDA/\&frasl;/g; #Ú 218 &frasl; 523 $string =~ s/\xDA/\&frasl;/g; #Ž 218 &frasl;
511 $string =~ s/\xF5/\&#305;/g; #õ 245 &#305 524 $string =~ s/\xF5/\&#305;/g; #ž 245 &#305
512 $string =~ s/\xF6/\&#710;/g; #ö 246 &#710; 525 $string =~ s/\xF6/\&#710;/g; # 246 &#710;
513 $string =~ s/\xF7/\&#193;/g; #÷ 247 &#193; 526 $string =~ s/\xF7/\&#193;/g; # 247 &#193;
514 $string =~ s/\xF8/\&#175;/g; #ø 248 &#175; 527 $string =~ s/\xF8/\&#175;/g; #¯ 248 &#175;
515 $string =~ s/\xF9/\&#728;/g; #ù 249 &#728; 528 $string =~ s/\xF9/\&#728;/g; #˜ 249 &#728;
516 $string =~ s/\xFA/\&#729;/g; #ú 250 &#729; 529 $string =~ s/\xFA/\&#729;/g; # 250 &#729;
517 $string =~ s/\xFB/\&#730;;/g; #û 251 &#730; 530 $string =~ s/\xFB/\&#730;;/g; #š 251 &#730;
518 $string; 531 $string;
519} 532}
520 533
521# ----- ----- ----- ----- 534# ----- ----- ----- -----
522 535

Legend:
Removed from v.3358  
changed lines
  Added in v.3359

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9