| … | |
… | |
| 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 | |
| 439 | my ($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. |
|
|
443 | my ($tthPreambleFile, $tthPreambleMtime, $tthPreambleContents); |
|
|
444 | |
| 441 | sub tth { |
445 | sub 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}; |
| … | |
… | |
| 494 | sub symbolConvert { |
507 | sub symbolConvert { |
| 495 | my $string = shift; |
508 | my $string = shift; |
| 496 | $string =~ s/\x5C/\\/g; #\ 92 \ |
509 | $string =~ s/\x5C/\\/g; #\ 92 \ |
| 497 | $string =~ s/\x7B/\{/g; #{ 123 { |
510 | $string =~ s/\x7B/\{/g; #{ 123 { |
| 498 | $string =~ s/\x7D/\}/g; #} 125 } |
511 | $string =~ s/\x7D/\}/g; #} 125 } |
| 499 | $string =~ s/\xE7/\Á/g; #ç 231 Á |
512 | $string =~ s/\xE7/\Á/g; #Á 231 Á |
| 500 | $string =~ s/\xE6/\Ê/g; #æ 230 Ê |
513 | $string =~ s/\xE6/\Ê/g; #Ê 230 Ê |
| 501 | $string =~ s/\xE8/\Ë/g; #è 232 Ë |
514 | $string =~ s/\xE8/\Ë/g; #Ë 232 Ë |
| 502 | $string =~ s/\xF3/\Û/g; #ó 243 Û |
515 | $string =~ s/\xF3/\Û/g; #Û 243 Û |
| 503 | $string =~ s/\xA5/\•/g; #¥ 165 • |
516 | $string =~ s/\xA5/\•/g; #€ 165 • |
| 504 | $string =~ s/\xB2/\≤/g; #² 178 ≤ |
517 | $string =~ s/\xB2/\≤/g; #¾ 178 ≤ |
| 505 | $string =~ s/\xB3/\≥/g; #³ 179 ≥ |
518 | $string =~ s/\xB3/\≥/g; #„ 179 ≥ |
| 506 | $string =~ s/\xB6/\∂/g; #¶ 182 ∂ |
519 | $string =~ s/\xB6/\∂/g; # 182 ∂ |
| 507 | $string =~ s/\xCE/\Œ/g; #Î 206 Œ |
520 | $string =~ s/\xCE/\Œ/g; #‘ 206 Œ |
| 508 | $string =~ s/\xD6/\˜/g; #Ö 214 ˜ |
521 | $string =~ s/\xD6/\˜/g; #÷ 214 ˜ |
| 509 | $string =~ s/\xD9/\Ÿ/g; #Ù 217 Ÿ |
522 | $string =~ s/\xD9/\Ÿ/g; # 217 Ÿ |
| 510 | $string =~ s/\xDA/\⁄/g; #Ú 218 ⁄ |
523 | $string =~ s/\xDA/\⁄/g; #Ž 218 ⁄ |
| 511 | $string =~ s/\xF5/\ı/g; #õ 245 ı |
524 | $string =~ s/\xF5/\ı/g; #ž 245 ı |
| 512 | $string =~ s/\xF6/\ˆ/g; #ö 246 ˆ |
525 | $string =~ s/\xF6/\ˆ/g; #– 246 ˆ |
| 513 | $string =~ s/\xF7/\Á/g; #÷ 247 Á |
526 | $string =~ s/\xF7/\Á/g; #— 247 Á |
| 514 | $string =~ s/\xF8/\¯/g; #ø 248 ¯ |
527 | $string =~ s/\xF8/\¯/g; #¯ 248 ¯ |
| 515 | $string =~ s/\xF9/\˘/g; #ù 249 ˘ |
528 | $string =~ s/\xF9/\˘/g; #˜ 249 ˘ |
| 516 | $string =~ s/\xFA/\˙/g; #ú 250 ˙ |
529 | $string =~ s/\xFA/\˙/g; #™ 250 ˙ |
| 517 | $string =~ s/\xFB/\˚;/g; #û 251 ˚ |
530 | $string =~ s/\xFB/\˚;/g; #š 251 ˚ |
| 518 | $string; |
531 | $string; |
| 519 | } |
532 | } |
| 520 | |
533 | |
| 521 | # ----- ----- ----- ----- |
534 | # ----- ----- ----- ----- |
| 522 | |
535 | |