diff options
author | Karl Berry <karl@freefriends.org> | 2006-11-16 01:02:47 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-11-16 01:02:47 +0000 |
commit | 3c85b55e2f245fb7edac7e445f107e6d0bb423ae (patch) | |
tree | c62b7f80edafe0455310d08e09f4218127bf9e87 /Master/texmf-dist/scripts/context/perl | |
parent | e5ecff27a26ef59e1dbe9702677687fd7107be3a (diff) |
context update
git-svn-id: svn://tug.org/texlive/trunk@2444 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/context/perl')
-rw-r--r-- | Master/texmf-dist/scripts/context/perl/makempy.pl | 6 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/perl/mptopdf.pl | 165 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/perl/pdftrimwhite.pl | 525 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/perl/texexec.pl | 74 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/perl/texexec.rme | 2 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/perl/texshow.pl | 82 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/context/perl/texutil.pl | 32 |
7 files changed, 756 insertions, 130 deletions
diff --git a/Master/texmf-dist/scripts/context/perl/makempy.pl b/Master/texmf-dist/scripts/context/perl/makempy.pl index 49fd9bbd21a..f263dd4259d 100644 --- a/Master/texmf-dist/scripts/context/perl/makempy.pl +++ b/Master/texmf-dist/scripts/context/perl/makempy.pl @@ -46,8 +46,6 @@ my $format = "plain" ; # can be "context" for plain users too "force" => \$force , "pdftops" => \$pmethod , "xpdf" => \$pmethod , -# "acrobat" => \$amethod , # nowadays the reader is not that clear about this being permitted - "reader" => \$amethod , "gs" => \$gmethod , "ghostscript" => \$gmethod , "noclean" => \$noclean ) ; @@ -202,15 +200,13 @@ sub show_help_info report ("--force : force processing (ignore checksum)" ) ; report ("--silent : don't show messages" ) ; print "\n" ; - report ("--acrobat : use acrobat (reader) for pdf->ps (on unix)") ; report ("--pdftops : use pdftops (xpdf) pdf->ps") ; report ("--ghostscript : use ghostscript (gs) for pdf->ps") ; print "\n" ; report ("input file : metapost file with graphics") ; report ("programs needed : texexec and english context") ; report (" : pdftops from the xpdf suite, or") ; # page size buggy - report (" : pdf2ps and ghostscript, or") ; - report (" : acrobat reader for unix, and") ; + report (" : pdf2ps and ghostscript, and") ; report (" : pstoedit and ghostscript") ; report ("output file : metapost file with pictures") ; exit } diff --git a/Master/texmf-dist/scripts/context/perl/mptopdf.pl b/Master/texmf-dist/scripts/context/perl/mptopdf.pl index efbc5ba0122..f85c36891b9 100644 --- a/Master/texmf-dist/scripts/context/perl/mptopdf.pl +++ b/Master/texmf-dist/scripts/context/perl/mptopdf.pl @@ -5,7 +5,7 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $ #D \module #D [ file=mptopdf.pl, -#D version=2005.10.31, +#D version=2000.05.29, #D title=converting MP to PDF, #D subtitle=\MPTOPDF, #D author=Hans Hagen, @@ -22,6 +22,7 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $ use Config ; use Getopt::Long ; use strict ; +use File::Basename ; $Getopt::Long::passthrough = 1 ; # no error message $Getopt::Long::autoabbrev = 1 ; # partial switch accepted @@ -36,88 +37,118 @@ my $PassOn = '' ; "passon" => \$PassOn, "latex" => \$Latex ) ; -my $program = "MPtoPDF 1.3" ; -my $pattern = $ARGV[0] ; +my $program = "MPtoPDF 1.3.2" ; +my $pattern = "@ARGV" ; # was $ARGV[0] +my $miktex = 0 ; my $done = 0 ; my $report = '' ; my $texlatexswitch = " --tex=latex --format=latex " ; my $mplatexswitch = " --tex=latex " ; -my $dosish = ($Config{'osname'} =~ /^(ms)?dos|^os\/2|^(ms|cyg)win/i) ; -my $miktex = ($ENV{"TEXSYSTEM"} =~ /miktex/io); -my $escapeshell = ( ($ENV{'SHELL'}) && ($ENV{'SHELL'} =~ m/sh/i )); +my $dosish = ($Config{'osname'} =~/^(ms)?dos|^os\/2|^mswin/i) ; +my $escapeshell = (($ENV{'SHELL'}) && ($ENV{'SHELL'} =~ m/sh/i )); + +if ($ENV{"TEXSYSTEM"}) { + $miktex = ($ENV{"TEXSYSTEM"} =~ /miktex/io) ; +} my @files ; my $command = my $mpbin = '' ; -sub CopyFile # agressive copy, works for open files like in gs - { my ($From,$To) = @_ ; - return unless open(INP,"<$From") ; binmode INP ; - return unless open(OUT,">$To") ; binmode OUT ; - while (<INP>) { print OUT $_ } +# agressive copy, works for open files like in gs + +sub CopyFile { + my ($From,$To) = @_ ; + return unless open(INP,"<$From") ; + return unless open(OUT,">$To") ; + binmode INP ; + binmode OUT ; + while (<INP>) { + print OUT $_ ; + } close (INP) ; - close (OUT) } - -if (($pattern eq '')||($Help)) - { print "\n$program : provide MP output file (or pattern)\n" ; - exit } -elsif ($pattern =~ /\.mp$/io) - { shift @ARGV ; my $rest = join(" ", @ARGV) ; - if (open(INP,$pattern)) - { while (<INP>) - { if (/(documentstyle|documentclass|begin\{document\})/io) - { $Latex = 1 ; last } } - close (INP) } - if ($RawMP) - { if ($Latex) - { $rest .= " $mplatexswitch" } + close (OUT) ; +} + +if (($pattern eq '')||($Help)) { + print "\n$program : provide MP output file (or pattern)\n" ; + exit ; +} elsif ($pattern =~ /\.mp$/io) { + shift @ARGV ; my $rest = join(" ", @ARGV) ; + if (open(INP,$pattern)) { + while (<INP>) { + if (/(documentstyle|documentclass|begin\{document\})/io) { + $Latex = 1 ; last ; + } + } + close (INP) ; + } + if ($RawMP) { + if ($Latex) { + $rest .= " $mplatexswitch" ; + } if ($MetaFun) { - $mpbin = 'mpost --mem=metafun --progname=mpost' ; + $mpbin = "mpost --progname=mpost --mem=metafun" ; } else { - $mpbin = 'mpost --mem=mpost' ; + $mpbin = "mpost --mem=mpost" ; } + } else { + if ($Latex) { + $rest .= " $texlatexswitch" ; + } + $mpbin = "texexec --mptex $PassOn" ; } - else - { if ($Latex) - { $rest .= " $texlatexswitch" } - $mpbin = 'texexec --mptex $PassOn' } + print "\n$program : running '$mpbin'\n" ; my $error = system ("$mpbin $rest $pattern") ; - if ($error) - { print "\n$program : error while processing mp file\n" ; exit } - else - { $pattern =~ s/\.mp$//io ; - @files = glob "$pattern.*" } } -elsif (-e $pattern) - { @files = ($pattern) } -elsif ($pattern =~ /.\../o) - { @files = glob "$pattern" } -else - { $pattern .= '.*' ; - @files = glob "$pattern" } - -foreach my $file (@files) - { $_ = $file ; - if (s/\.(\d+|mps)$// && -e $file) - { if ($miktex) - { $command = "pdfetex -undump=mptopdf" } - else - { $command = "pdfetex --fmt=mptopdf --progname=context" } - if ($dosish) - { $command = "$command \\relax $file" } - else - { $command = "$command \\\\relax $file" } - #~ print $command ; + if ($error) { + print "\n$program : error while processing mp file\n" ; + exit ; + } else { + $pattern =~ s/\.mp$//io ; + @files = glob "$pattern.*" ; + } +} elsif (-e $pattern) { + @files = ($pattern) ; +} elsif ($pattern =~ /.\../o) { + @files = glob "$pattern" ; +} else { + $pattern .= '.*' ; + @files = glob "$pattern" ; +} + +foreach my $file (@files) { + $_ = $file ; + if (s/\.(\d+|mps)$// && -e $file) { + if ($miktex) { + $command = "pdfetex -undump=mptopdf" ; + } else { + $command = "pdfetex -fmt=mptopdf -progname=context" ; + } + if ($dosish) { + $command = "$command \\relax $file" ; + } else { + $command = "$command \\\\relax $file" ; + } system($command) ; - rename ("$_.pdf", "$_-$1.pdf") ; - if (-e "$_.pdf") { CopyFile ("$_.pdf", "$_-$1.pdf") } - if ($done) { $report .= " +" } + my $pdfsrc = basename($_).".pdf"; + rename ($pdfsrc, "$_-$1.pdf") ; + if (-e $pdfsrc) { + CopyFile ($pdfsrc, "$_-$1.pdf") ; + } + if ($done) { + $report .= " +" ; + } $report .= " $_-$1.pdf" ; - ++$done } } + ++$done ; + } +} -if ($report eq '') - { $report = '*' } +if ($report eq '') { + $report = '*' ; +} -if ($done) - { print "\n$program : $pattern is converted to$report\n" } -else - { print "\n$program : no filename matches $pattern\n" } +if ($done) { + print "\n$program : $pattern is converted to$report\n" ; +} else { + print "\n$program : no filename matches $pattern\n" ; +} diff --git a/Master/texmf-dist/scripts/context/perl/pdftrimwhite.pl b/Master/texmf-dist/scripts/context/perl/pdftrimwhite.pl new file mode 100644 index 00000000000..08c1de5d778 --- /dev/null +++ b/Master/texmf-dist/scripts/context/perl/pdftrimwhite.pl @@ -0,0 +1,525 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' + if 0; + +#D \module +#D [ file=pdftrimwhite.pl, +#D version=2000.07.13, +#D title=PDF postprocessing, +#D subtitle=cropping whitespace from pdf files, +#D author=Hans Hagen, +#D date=\currentdate, +#D copyright=PRAGMA ADE] + +#C This module is part of the \CONTEXT\ macro||package and is +#C therefore copyrighted by \PRAGMA. See readme.pdf for +#C details. + +#D This script can be used to crop margins that contain +#D useless information from a \PDF\ image. It does so by: +#D +#D \startitemize[packed,n] +#D \som cropping the image into an alternative file +#D \som determining the boundingbox of the alternative +#D \som cropping the image into a resulting file +#D \stoppacked +#D +#D In the process, some checks are carried out. Step~1 is +#D taken care of by \PDFTEX, step~2 by \GHOSTSCRIPT, using a +#D file generated by \PDFTOPS, and \PDFTEX\ is responsible +#D for step~3. +#D +#D \startuseMPgraphic{original} +#D numeric n ; n = 1cm ; +#D path p ; p := fullsquare xyscaled (8n,12n) ; +#D path q ; q := fullsquare xyscaled (2n,3n) shifted (n,n) ; +#D path r ; r := ((0,0)--(3n,0)) shifted (0, 5.5n) ; +#D path s ; s := ((0,0)--(3n,0)) shifted (0,-5.5n) ; +#D path t ; t := (-2n,-4n) ; +#D path u ; u := p enlarged -.75n ; +#D path v ; v := p enlarged (-1.75n,-2n) shifted (n,1.25n) ; +#D path w ; w := q enlarged .25n ; +#D fill p withcolor .7white ; +#D fill q withcolor .7green ; +#D draw r withpen pencircle scaled .25n withcolor .7green ; +#D draw s withpen pencircle scaled .25n withcolor .7green ; +#D draw t withpen pencircle scaled .50n withcolor .7green ; +#D draw u withpen pencircle scaled .10n withcolor white ; +#D draw v withpen pencircle scaled .10n withcolor .7red ; +#D draw w withpen pencircle scaled .10n ; +#D verbatimtex \tttf \setupframed[frame=off,align=left] etex ; +#D label (btex \framed{crap} etex, center r) ; +#D label (btex \framed{crap} etex, center s) ; +#D label (btex \framed{crap} etex, center t) ; +#D label (btex \framed{graphic} etex, center q) ; +#D label.urt(btex \framed{page} etex, llcorner p) ; +#D label.urt(btex \framed{crop} etex, llcorner u) ; +#D label.lft(btex \framed{leftcrop\\ +#D rightcrop\\ +#D topcrop\\ +#D bottomcrop} etex, .5[ulcorner v,llcorner v]) ; +#D label.bot(btex \framed{offset} etex, .5[llcorner w,lrcorner w]) ; +#D \stopuseMPgraphic +#D +#D \placefigure +#D [here][fig:cropcrap] +#D {Crops and offsets.} +#D {\useMPgraphic{original}} +#D +#D The \TEX\ part has two alternatives, one using \CONTEXT, and +#D another using plain \TEX. The \CONTEXT\ method is slower but +#D can be extended more easily. +#D +#D The script is executed as follows: +#D +#D \starttyping +#D cropcrap <original> [<result>] [<switches>] +#D \stoptyping +#D +#D The next call crops \type {test.pdf} to its natural +#D boundingbox. +#D +#D \starttyping +#D cropcrap test +#D \stoptyping +#D +#D If the file has some crap at the bottom, you can say: +#D +#D \starttyping +#D cropcrap test --bottomcrop=2cm +#D \stoptyping +#D +#D This clips 2cm from the bottom. You can clip on all sides +#D individually, in combination or at once, like in: +#D +#D \starttyping +#D cropcrap test --bottomcrop=2cm --crop=1cm +#D \stoptyping +#D +#D The final result is a tightly cropped image. In order to get +#D a 5mm margin around this image, you can say: +#D +#D \starttyping +#D cropcrap test --bottomcrop=2cm --offset=5mm +#D \stoptyping +#D +#D By default, the script intercepts logging messages and +#D writes them to a logfile with the same name as the +#D resulting image and the prefix \type {log}. If no name is +#D given, the name \type {cropcrap} is used for all resulting +#D files. +#D +#D By default, \CONTEXT\ is used. When installed properly, you +#D can also use plain \TEX, by adding a switch \type +#D {--plain}. Partial switched are accepted, so the next call +#D is valid: +#D +#D \starttyping +#D cropcrap test result --bot=2cm --off=5mm --plain +#D \stoptyping +#D +#D The current implementation uses an intermediate \POSTSCRIPT\ +#D file. This may change as \GHOSTSCRIPT\ gets more clever with +#D \PDF\ files. +#D +#D In \in {figure} [fig:cropcrap] the green rectangle is the +#D picture we want to keep. Around this picture, we want a +#D margin, represented by the black rectangle, and specified by +#D \type {--offset}. The white rectangle is the cropbox +#D defined by \type {--crop}. That way we get rid of header +#D and footerlines. The red rectangle results from an +#D additional \type {--leftcrop} and \type {-bottomcrop} and +#D takes care of some content, as represented by the green +#D dot. +#D +#D The \type {--verbose} switch can be used to disable the +#D interception of log messages. + +#D We load a few \PERL\ modules \unknown\ + +use Config ; +use Getopt::Long ; + +use strict ; + +#D \unknown\ and initialize them. + +Getopt::Long::Configure + ("auto_abbrev", + "ignore_case", + "pass_through") ; + +#D Before fetching the switches, we initialize the +#D variables. + +my $Crop = "0cm" ; + +my $LeftCrop = "0cm" ; +my $RightCrop = "0cm" ; +my $TopCrop = "0cm" ; +my $BottomCrop = "0cm" ; + +my $Offset = "0cm" ; + +my $GSbin = "" ; +my $Verbose = 0 ; +my $Help = 0 ; +my $UsePlain = 0 ; + +my $Page = 1 ; + +#D On \MSWINDOWS\ and \UNIX\ the following defaults, combined +#D with the check later, should work out okay. + +my $pdfps = "pdftops" ; +my $gs = "gs" ; + +my $thisisunix = $Config{'osname'} !~ /dos|mswin/i ; + +#D When no resulting file is given, we use \type {cropcrap} +#D as name (checked later). + +my $figurefile = "" ; +my $resultfile = "" ; +my $tempfile = "" ; + +my $programname = "cropcrap" ; + +#D Messages are temporarily saved and written to a log file +#D afterwards. + +my $results = "" ; +my $pipe = "" ; +my $result = "" ; + +#D Unfortunately we need this information, first since +#D \PDFTOPS\ does not honor the cropbox, and second because +#D the vertical coordinated are swapped. + +my $pwidth = 597 ; +my $pheight = 847 ; +my $hoffset = 0 ; +my $voffset = 0 ; + +#D A few more variables. + +my $width = my $height = my $llx = my $lly = my $urx = my $ury = 0 ; + +#D Here are the switches we accept. The \type {--gsbin} switch +#D is a bonus one, and the \type {--help} switch comes +#D naturally. + +&GetOptions + ( "leftcrop=s" => \$LeftCrop , + "rightcrop=s" => \$RightCrop , + "topcrop=s" => \$TopCrop , + "bottomcrop=s" => \$BottomCrop, + "crop=s" => \$Crop , + "offset=s" => \$Offset , + "verbose" => \$Verbose , + "gsbin=s" => \$GSbin , + "plain" => \$UsePlain , + "page=i" => \$Page , + "help" => \$Help ) ; + +#D If asked for, or if no file is given, we provide some +#D help information. + +sub PrintHelp + { print "This is PdfTrimWhite\n\n" . + "usage:\n\n" . + "cropcrap [switches] filename result\n\n" . + "switches:\n\n" . + "--crop=<dimen>\n" . + "--offset=<dimen>\n" . + "--leftcrop=<dimen>\n" . + "--rightcrop=<dimen>\n" . + "--topcrop=<dimen>\n" . + "--bottomcrop=<dimen>\n" . + "--gsbin=<string>\n" . + "--page=<number>\n" . + "--plain\n" . + "--verbose\n" } + +#D The preparations: + +sub GetItRight + { if ($Help) + { PrintHelp() ; exit } + $figurefile = $ARGV[0] ; $figurefile =~ s/\.pdf$//oi ; + $resultfile = $ARGV[1] ; $resultfile =~ s/\.pdf$//oi ; + $tempfile = "pdftrimwhite-$resultfile" ; + if ($figurefile eq '') + { PrintHelp() ; exit } + unless ($thisisunix) + { $gs = "gswin32c" } + if ($GSbin ne '') + { $gs = $GSbin } + unless (-e "$figurefile.pdf") + { print "Something is terribly wrong: no file found\n" ; + exit } + if (($resultfile eq '')||($resultfile=~/(^\-|\.)/io)) + { $resultfile = $programname } + $pipe = "2>&1" ; + if ($thisisunix) + { $pipe = "2>&1" } } + +#D Something common. + +sub SavePageData + { return "% saving page data +\\immediate\\openout\\scratchwrite=$figurefile.tmp +\\immediate\\write\\scratchwrite + {\\HOffsetBP\\space\\VOffsetBP\\space + \\FigureWidthBP\\space\\FigureHeightBP} +\\immediate\\closeout\\scratchwrite\n" } + +sub MakePageConTeXt + { return "% the real work +\\definepapersize + [Crap] + [width=\\FigureWidth, + height=\\FigureHeight] +\\setuppapersize + [Crap][Crap] +\\setuplayout + [topspace=0cm,backspace=0pt, + height=middle,width=middle, + header=0pt,footer=0pt] +\\starttext + \\startstandardmakeup + \\clip + [voffset=\\VOffset, + hoffset=\\HOffset, + width=\\FigureWidth, + height=\\FigureHeight] + {\\externalfigure[$figurefile.pdf][page=$Page]\\hss} + \\stopstandardmakeup +\\stoptext\n" } + +sub MakePagePlainTeX + { return "% the real work +\\output{} +\\hoffset=-1in +\\voffset=\\hoffset +\\pdfpageheight=\\FigureHeight +\\pdfpagewidth=\\FigureWidth +\\vbox to \\pdfpageheight + {\\offinterlineskip + \\vskip-\\VOffset + \\hbox to \\pdfpagewidth{\\hskip-\\HOffset\\box0\\hss} + \\vss} +\\end\n" } + +sub CalculateClip + { return "% some calculations +\\dimen0=\\figurewidth +\\dimen2=\\figureheight +\\dimen4=$Crop +\\dimen6=$Crop +\\advance\\dimen4 by $LeftCrop +\\advance\\dimen6 by $TopCrop +\\advance\\dimen0 by -\\dimen4 +\\advance\\dimen0 by -$Crop +\\advance\\dimen0 by -$RightCrop +\\advance\\dimen2 by -\\dimen6 +\\advance\\dimen2 by -$Crop +\\advance\\dimen2 by -$BottomCrop +\\edef\\FigureWidth {\\the\\dimen0} +\\edef\\FigureHeight{\\the\\dimen2} +\\edef\\HOffset {\\the\\dimen4} +\\edef\\VOffset {\\the\\dimen6} +\\ScaledPointsToWholeBigPoints{\\number\\dimen0}\\FigureWidthBP +\\ScaledPointsToWholeBigPoints{\\number\\dimen2}\\FigureHeightBP +\\ScaledPointsToWholeBigPoints{\\number\\dimen4}\\HOffsetBP +\\ScaledPointsToWholeBigPoints{\\number\\dimen6}\\VOffsetBP\n" } + +sub RecalculateClip + { return "% some calculations +\\dimen0=${width}bp +\\dimen2=${height}bp +\\dimen4=${hoffset}bp +\\dimen6=${pheight}bp +\\advance\\dimen0 by $Offset +\\advance\\dimen0 by $Offset +\\advance\\dimen2 by $Offset +\\advance\\dimen2 by $Offset +\\advance\\dimen4 by ${llx}bp +\\advance\\dimen4 by -$Offset +\\advance\\dimen6 by -${lly}bp +\\advance\\dimen6 by $Offset +\\advance\\dimen6 by -\\dimen2 +\\advance\\dimen6 by $TopCrop +\\edef\\FigureWidth {\\the\\dimen0} +\\edef\\FigureHeight{\\the\\dimen2} +\\edef\\HOffset {\\the\\dimen4} +\\edef\\VOffset {\\the\\dimen6}\n" } + +#D The previous scripts could be more sparse, but for the +#D moment we prefer readability. Both scripts save some +#D information in temporary file. We choose between them with +#D the following sub routine. + +#D The first pass: + +sub PrepareConTeXt + { return "% interface=en +\\setupoutput[pdftex] +\\getfiguredimensions[$figurefile.pdf][page=$Page]\n" } + +sub PreparePlainTeX + { return "% plain tex alternative, needs recent supp-mis +\\input supp-mis +\\pdfoutput=1 +\\newdimen\\figurewidth +\\newdimen\\figureheight +\\setbox0=\\hbox + {\\immediate\\pdfximage page $Page {$figurefile.pdf}\\pdfrefximage\\pdflastximage} +\\figurewidth=\\wd0 +\\figureheight=\\ht0\n" } + +sub PrepareFirstPass + { open (TEX, ">$tempfile.tex") ; + if ($UsePlain) + { print TEX + PreparePlainTeX . + CalculateClip . + SavePageData . + MakePagePlainTeX } + else + { print TEX + PrepareConTeXt . + CalculateClip . + SavePageData . + MakePageConTeXt } + close TEX } + +#D The second pass looks much like the first one, but this +#D time we don't save information, use the natural +#D boundingbox, and provide the offset. + +sub SetupConTeXt + { return "% interface=en +\\setupoutput[pdftex]\n" } + +sub SetupPlainTeX + { return "% plain tex alternative +\\pdfoutput=1 +\\setbox0=\\hbox + {\\immediate\\pdfximage page $Page {$figurefile.pdf}\\pdfrefximage\\pdflastximage}\n" } + +sub PrepareSecondPass + { open (TEX, ">$tempfile.tex") ; + if ($UsePlain) + { print TEX + SetupPlainTeX . + RecalculateClip . + MakePagePlainTeX } + else + { print TEX + SetupConTeXt . + RecalculateClip . + MakePageConTeXt } + close TEX } + +#D The information we save in the first pass, is loaded here. + +sub FetchPaperSize + { open (TMP,"$figurefile.tmp") ; + while (<TMP>) + { chomp ; + if (/^(\d+) (\d+) (\d+) (\d+) *$/oi) + { $hoffset = $1 ; + $voffset = $2 ; + $pwidth = $3 ; + $pheight = $4 ; + last } } + close (TMP) } + +#D Here we try to find the natural boundingbox. We need to +#D pick up the page dimensions here. + +sub RunTeX + { if ($UsePlain) + { $result = `pdftex -prog=pdftex -fmt=plain -int=batchmode $tempfile` } + else + { $result = `texexec --batch --once --purge $tempfile` } + print $result if $Verbose ; $results .= "$result\n" } + +sub FindBoundingBox + { $result = `$gs -sDEVICE=bbox -dNOPAUSE -dBATCH $tempfile.pdf $pipe` ; + print $result if $Verbose ; $results .= "$result\n" } + +sub IdentifyCropBox + { RunTeX() ; + FetchPaperSize () ; + FindBoundingBox() } + +#D Just to be sure, we check if there is some image data, so +#D that we can retry if something went wrong. Unfortunately we cannot +#D safely check on a high res boundingbox. + +my $digits = '([\-\d\.]+)' ; + +sub ValidatedCropBox + { if ($result =~ /BoundingBox:\s*$digits\s+$digits\s+$digits\s+$digits\s*/mois) + { $llx = $1 ; $lly = $2 ; $urx = $3 ; $ury = $4 } + else + { print "Something is terribly wrong: no boundingbox:\n$result\n" ; exit } + $width = abs($urx - $llx) ; + $height = abs($ury - $lly) ; + if ($width&&$height) + { return 1 } + else + { unless ($width) + { print "Something seems wrong: no width\n" ; + $LeftCrop = "0cm" ; $RightCrop = "0cm" ; $Crop = "0cm" } + unless ($height) + { print "Something seems wrong: no height\n" ; + $TopCrop = "0cm" ; $BottomCrop = "0cm" ; $Crop = "0cm" } + return 0 } } + +#D This is the main cropping routine. + +sub FixCropBox + { RunTeX() } + +#D For error tracing we save the log information in a file. + +sub RenameResult + { unlink "$resultfile.pdf" ; + rename "$tempfile.pdf", "$resultfile.pdf" } + +sub SaveLogInfo + { open (LOG, ">$resultfile.log") ; + print LOG $results ; + close (LOG) } + +#D We remove all temporary files. + +sub CleanUp + { unless ($Verbose) + { unlink "$tempfile.tex" ; + unlink "$tempfile.tuo" ; + unlink "$tempfile.tui" ; + unlink "$figurefile.tmp" } } + +#D Here it all comes together. + +GetItRight() ; + +PrepareFirstPass() ; + +IdentifyCropBox () ; + +unless (ValidatedCropBox()) + { PrepareFirstPass() ; + IdentifyCropBox () } + +if (ValidatedCropBox()) + { PrepareSecondPass() ; + FixCropBox() } + +RenameResult() ; +SaveLogInfo() ; + +CleanUp () ; diff --git a/Master/texmf-dist/scripts/context/perl/texexec.pl b/Master/texmf-dist/scripts/context/perl/texexec.pl index 2f3b89e0461..fb564bbd5ed 100644 --- a/Master/texmf-dist/scripts/context/perl/texexec.pl +++ b/Master/texmf-dist/scripts/context/perl/texexec.pl @@ -11,7 +11,7 @@ eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' && eval 'exec perl -w - #D copyright={PRAGMA / Hans Hagen \& Ton Otten}] #C #C This module is part of the \CONTEXT\ macro||package and is -#C therefore copyrighted by \PRAGMA. See licen-en.pdf for +#C therefore copyrighted by \PRAGMA. See readme.pdf for #C details. # Thanks to Tobias Burnus for the german translations. @@ -151,6 +151,7 @@ my $PdfCombine = 0; my $PdfOpen = 0; my $PdfClose = 0; my $AutoPdf = 0; +my $UseXPdf = 0; my $PrintFormat = 'standard'; my $ProducePdfT = 0; my $ProducePdfM = 0; @@ -255,6 +256,7 @@ my $MakeMpy = ''; "once" => \$RunOnce, "output=s" => \$OutputFormat, "pages=s" => \$Pages, + "paper=s" => \$PaperFormat, "paperformat=s" => \$PaperFormat, "passon=s" => \$PassOn, "path=s" => \$InpPath, @@ -275,6 +277,7 @@ my $MakeMpy = ''; "selection=s" => \$Selection, "combination=s" => \$Combination, "noduplex" => \$NoDuplex, + "offset=s" => \$PaperOffset, "paperoffset=s" => \$PaperOffset, "backspace=s" => \$BackSpace, "topspace=s" => \$TopSpace, @@ -310,6 +313,7 @@ my $MakeMpy = ''; "pdfclose" => \$PdfClose, "pdfopen" => \$PdfOpen, "autopdf" => \$AutoPdf, + "xpdf" => \$UseXPdf, "modefile=s" => \$ModeFile, # additional modes file "globalfile" => \$GlobalFile, "nomapfiles" => \$NoMapFiles, @@ -351,6 +355,12 @@ if ( $ARGV[0] && $ARGV[0] =~ /\.mpx$/io ) { # catch -tex=.... bug in mpost #### +if ($Version) { + $Purge = 1 ; + } + +#### + if ($Paranoid) { $ENV{shell_escape} = 'f' ; $ENV{openout_any} = 'p' ; @@ -406,6 +416,16 @@ if ($AutoPdf) { $PdfOpen = $PdfClose = 1 ; } +my $PdfOpenCall = "" ; + +if ($PdfOpen) { + $PdfOpenCall = "pdfopen --file" ; +} + +if ($UseXPdf && !$dosish) { + $PdfOpenCall = "xpdfopen" ; +} + # this is our hook into paranoid path extensions, assumes that # these three vars are part of path specs in texmf.cnf @@ -900,7 +920,7 @@ $OutputFormats{dviwindo} = "dviwindo"; $OutputFormats{dviview} = "dviview"; -my @ConTeXtFormats = ( "nl", "en", "de", "cz", "uk", "it", "ro", "xx"); +my @ConTeXtFormats = ( "nl", "en", "de", "fr", "cz", "uk", "it", "ro", "xx"); sub SetInterfaces { my ( $short, $long, $full ) = @_; @@ -915,8 +935,9 @@ sub SetInterfaces { SetInterfaces( "nl", "dutch", "dutch" ); SetInterfaces( "en", "english", "english" ); SetInterfaces( "de", "german", "german" ); +SetInterfaces( "fr", "french", "french" ); SetInterfaces( "cz", "czech", "czech" ); -SetInterfaces( "uk", "brittish", "english" ); +SetInterfaces( "uk", "british", "english" ); SetInterfaces( "it", "italian", "italian" ); SetInterfaces( "no", "norwegian", "norwegian" ); SetInterfaces( "ro", "romanian", "romanian" ); @@ -1203,6 +1224,11 @@ sub MakeOptionFile { print OPT "\\setupcolors[\\c!split=$Separation]\n"; } if ($SetupPath) { print OPT "\\setupsystem[\\c!directory=\{$SetupPath\}]\n" } + if ($dosish) { + print OPT "\\setupsystem[\\c!type=mswin]\n" + } else { # no darwin handling in old texexec + print OPT "\\setupsystem[\\c!type=unix]\n" + } print OPT "\\setupsystem[\\c!n=$KindOfRun]\n"; $_ = $PaperFormat; #unless (($PdfArrange)||($PdfSelect)||($PdfCombine)||($PdfCopy)) @@ -1945,11 +1971,11 @@ sub RunConTeXtFile { { unlink "$JobName.$JobSuffix"; } - if ((!$Problems) && ($PdfOpen)) { + if ((!$Problems) && ($PdfOpen) && ($PdfOpenCall)) { if ($Result ne '') { - System("pdfopen --file $Result.pdf") if -f "$Result.pdf" + System("$PdfOpenCall $Result.pdf") if -f "$Result.pdf" } else { - System("pdfopen --file $JobName.pdf") if -f "$JobName.pdf" + System("$PdfOpenCall $JobName.pdf") if -f "$JobName.pdf" } } } @@ -2008,7 +2034,11 @@ sub checktexformatpath { if ($texformats eq '') { if ($UseEnginePath) { if ($dosish) { - $texformats = `kpsewhich --engine=$TeXExecutable --expand-var=\$TEXFORMATS` ; + if ( $TeXShell =~ /MikTeX/io ) { + $texformats = `kpsewhich --alias=$TeXExecutable --expand-var=\$TEXFORMATS` ; + } else { + $texformats = `kpsewhich --engine=$TeXExecutable --expand-var=\$TEXFORMATS` ; + } } else { $texformats = `kpsewhich --engine=$TeXExecutable --expand-var=\\\$TEXFORMATS` ; } @@ -2363,7 +2393,11 @@ sub LocatedFormatPath { # watch out $engine is lowercase in kpse # expanded paths print " assuming engine : $EnginePath\n"; if (($UseEnginePath)&&($EngineDone)) { - $FormatPath = `$kpsewhich --engine=$EnginePath --show-path=fmt` ; + if ( $TeXShell =~ /MikTeX/io ) { + $FormatPath = `$kpsewhich --alias=$EnginePath --show-path=fmt` ; + } else { + $FormatPath = `$kpsewhich --engine=$EnginePath --show-path=fmt` ; + } } else { $FormatPath = `$kpsewhich --show-path=fmt` ; } @@ -2375,7 +2409,11 @@ sub LocatedFormatPath { # watch out $engine is lowercase in kpse if ($FormatPath eq '') { if (($UseEnginePath)&&($EngineDone)) { if ($dosish) { - $FormatPath = `$kpsewhich --engine=$EnginePath --expand-path=\$TEXFORMATS` ; + if ( $TeXShell =~ /MikTeX/io ) { + $FormatPath = `$kpsewhich --alias=$EnginePath --expand-path=\$TEXFORMATS` ; + } else { + $FormatPath = `$kpsewhich --engine=$EnginePath --expand-path=\$TEXFORMATS` ; + } } else { $FormatPath = `$kpsewhich --engine=$EnginePath --expand-path=\\\$TEXFORMATS` ; } @@ -2998,7 +3036,7 @@ sub show_version_info { $contextversion = <IN>; close IN; } - $contextversion =~ s/.*contextversion\{([0-9.]+)\}.*/$1/s; + $contextversion =~ s/.*contextversion\{([0-9\.\:\s]+)\}.*/$1/s; } $EnterBatchMode = 1; $Format = 'cont-en'; @@ -3007,7 +3045,7 @@ sub show_version_info { print " tex : $texengine\n" ; print " context : ver: $contextversion\n" ; print " cont-en : $type\n" ; - foreach my $a (qw(cz de it nl ro uk xx)) { + foreach my $a (qw(cz de fr it nl ro uk xx)) { my $test = Pipe("$kpsewhich -format='fmt' cont-$a") ; if (defined $test && $test) { $Format = 'cont-' . $a; @@ -3063,6 +3101,9 @@ $TotalTime = time - $TotalTime; unless ($HelpAsked) { print "\n total run time : $TotalTime seconds\n" } +print "\n" ; +print " warning : use 'texmfstart texexec' instead\n" ; + if ($Problems) { exit 1 } __DATA__ @@ -3108,8 +3149,9 @@ interface user interface =en English =nl Dutch =de German +=fr French =cz Czech -=uk Brittish +=uk British =it Italian ----------- language main hyphenation language @@ -3136,7 +3178,7 @@ module typeset tex/pl/mp module ----------- mptex run an MetaPost plus btex-etex cycle ----------- -mpxtex generatet an MetaPostmpx file +mpxtex generate an MetaPost mpx file ----------- noarrange process but ignore arrange ----------- @@ -3149,8 +3191,8 @@ automprun MetaPost at runtime when needed once run TeX only once (no TeXUtil either) ----------- output specials to use -=pdftex Han The Than's pdf backend -=dvips Thomas Rokicky's dvi to ps converter +=pdftex Han The Thanh's pdf backend +=dvips Tomas Rokicky's dvi to ps converter =dvipsone YandY's dvi to ps converter =dviwindo YandY's windows previewer =dvipdfm Mark Wicks' dvi to pdf converter @@ -3243,7 +3285,7 @@ verbose shows some additional info ----------- help show this or more, e.g. '--help interface' ----------- -alone bypass utilities (e.g. fmtutil for non-standard fmt's) +alone bypass utilities (e.g. fmtutil for non-standard fmts) ----------- texutil force TeXUtil run ----------- diff --git a/Master/texmf-dist/scripts/context/perl/texexec.rme b/Master/texmf-dist/scripts/context/perl/texexec.rme index f38b4be7fe0..43f142f9da4 100644 --- a/Master/texmf-dist/scripts/context/perl/texexec.rme +++ b/Master/texmf-dist/scripts/context/perl/texexec.rme @@ -120,7 +120,7 @@ for miktex set TeXVirginFlag to --initialize for miktex set TeXPassString to --alias=context --translate-file=natural.tcx for miktex set TeXBatchFlag to --interaction=batchmode for miktex set TeXNonStopFlag to --interaction=nonstopmode -for miktex set MpToTeXExecutable to mptotex +for miktex set MpToTeXExecutable to mpto for miktex set MpVirginFlag to --initialize for miktex set MpPassString to --alias=mpost --translate-file=natural.tcx for miktex set MpBatchFlag to --interaction=batchmode diff --git a/Master/texmf-dist/scripts/context/perl/texshow.pl b/Master/texmf-dist/scripts/context/perl/texshow.pl index 79222c9f03c..629c28f99ec 100644 --- a/Master/texmf-dist/scripts/context/perl/texshow.pl +++ b/Master/texmf-dist/scripts/context/perl/texshow.pl @@ -3,7 +3,7 @@ eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' && eval 'exec perl -w - #D \module #D [ file=texshow.pl, -#D version=2005.01.06, +#D version=2006.08.04, #D title=TeXShow, #D subtitle=showing \CONTEXT\ commands, #D author=Taco Hoekwater, @@ -23,6 +23,12 @@ eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' && eval 'exec perl -w - #D one to be used. #D #D Hans Hagen - Januari 2005 +#D +#D ChangeLog: +#D \startitemize +#D \item Add keyboard bindings for quitting the app: Ctrl-q,Ctrl-x,Alt-F4 (2006/07/19) +#D \item Support for define --resolve (2006/08/04) +#D \stopitemize use strict; use Getopt::Long ; @@ -63,7 +69,7 @@ my %crosslinks; print "\n"; -show('TeXShow-XML 0.2 beta','Taco Hoekwater 2004',"/"); +show('TeXShow-XML 0.3 beta','Taco Hoekwater 2006',"/"); print "\n"; @@ -220,6 +226,11 @@ sub initialize_display { $mainwindow -> bind ( "<BackSpace>", sub { delete_request() } ) ; $mainwindow -> bind ( "<Prior>", sub { prev_command() } ) ; $mainwindow -> bind ( "<Next>", sub { next_command() } ) ; + $mainwindow -> bind ( "<Control-x>", sub { exit(0) } ) ; + $mainwindow -> bind ( "<Control-X>", sub { exit(0) } ) ; + $mainwindow -> bind ( "<Control-q>", sub { exit(0) } ) ; + $mainwindow -> bind ( "<Control-Q>", sub { exit(0) } ) ; + $mainwindow -> bind ( "<Alt-F4>", sub { exit(0) } ) ; } sub show { @@ -312,41 +323,50 @@ sub setups_found { sub load_setup { my ($path,$filename) = @_; + my $localdefs = {}; unless (keys %{$setups{$filename}}) { if (open(IN,"<${path}$filename.xml")) { my $position = 0 ; local $/ = '</cd:command>'; while (my $data= <IN>) { - if ($data =~ /\<\/cd:interface/) { - next; - } - if ($data =~ /\<cd:interface/) { - $data =~ s/^(.*?)\<cd:command/\<cd:command/sm; - my $meta = $1; - } - # - $data =~ s/\s*\n\s*//g; - $data =~ /\<cd:command(.*?)\>/; - my $info = $1; - my ($name,$environment) = ('',''); - while ($info =~ s/^\s*(.*?)\s*=\s*(["'])(.*?)\2\s*//) { - my $a = $1; my $b = $3; - if ($a eq 'name') { - $name = $b; - } elsif ($a eq 'type') { - $environment = $b; + next if $data =~ /\<\/cd:interface/; + if ($data =~ /\<cd:interface/) { + $data =~ s/^(.*?)\<cd:command/\<cd:command/sm; + my $meta = $1; + while ($meta =~ s!<cd:define name=(['"])(.*?)\1>(.*?)</cd:define>!!sm) { + my $localdef = $2; + my $localval = $3; + $localdefs->{$localdef} = $localval; + } + } + # + if (keys %$localdefs) { + while ($data =~ /<cd:resolve/) { + $data =~ s/<cd:resolve name=(['"])(.*?)\1\/>/$localdefs->{$2}/ms; + } + } + $data =~ s/\s*\n\s*//g; + $data =~ /\<cd:command(.*?)\>/; + my $info = $1; + my ($name,$environment) = ('',''); + while ($info =~ s/^\s*(.*?)\s*=\s*(["'])(.*?)\2\s*//) { + my $a = $1; my $b = $3; + if ($a eq 'name') { + $name = $b; + } elsif ($a eq 'type') { + $environment = $b; + } + } + my $cmd = $name; + if ($environment) { + $cmd = "start" . $name; + } + $setups {$filename}{$cmd} = $data ; + $trees {$filename}{$cmd} = undef; + $positions {$filename}{$cmd} = ++$position ; + $crosslinks{$filename}[$position] = $cmd ; } - } - my $cmd = $name; - if ($environment) { - $cmd = "start" . $name; - } - $setups {$filename}{$cmd} = $data ; - $trees {$filename}{$cmd} = undef; - $positions {$filename}{$cmd} = ++$position ; - $crosslinks{$filename}[$position] = $cmd ; - } - close IN; + close IN; # now get explanations as well ... my $explname = $filename; $explname =~ s/cont-/expl-/; diff --git a/Master/texmf-dist/scripts/context/perl/texutil.pl b/Master/texmf-dist/scripts/context/perl/texutil.pl index 0a0d2975354..ca364501584 100644 --- a/Master/texmf-dist/scripts/context/perl/texutil.pl +++ b/Master/texmf-dist/scripts/context/perl/texutil.pl @@ -44,7 +44,7 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $ #D binary version, like scanning illustrations other than \EPS. #D I would suggest to keep an eye on the version number: -$Program = "TeXUtil 9.0.0 - ConTeXt / PRAGMA ADE 1992-2004" ; +$Program = "TeXUtil 9.0.1 - ConTeXt / PRAGMA ADE 1992-2006" ; #D By the way, this is my first \PERL\ script, which means #D that it will be improved as soon as I find new and/or more @@ -54,6 +54,11 @@ $Program = "TeXUtil 9.0.0 - ConTeXt / PRAGMA ADE 1992-2004" ; #D users in english as well as some other languages. One can #D set his favourite language by saying something like: +#D This one has a real old date, 1992. This is because it is +#D a converted modula program that was used in the very early +#D days of our \TEX\ history (macros for proper inclusion of +#D graphics were among the first thatwe wrote). + #D \starttypen #D perl texutil.pl --int=de --fig *.eps *.tif *.pdf *.png *.jpg #D \stoptypen @@ -823,7 +828,7 @@ sub InitializeKeys { my $filename = $ARGV[0] ; return unless (open(TEX,"$filename.tex")) ; for ($i=0;$i<=255;$i++) - { @Filter[$i] = $i } + { $Filter[$i] = $i } if ($TcXPath eq '') { foreach (@paths) { my $p = checked_path($_) . 'kpsewhich' ; @@ -848,7 +853,7 @@ sub InitializeKeys { Report ("LoadedFilter", $Translation) ; while (<ASC>) { if (/^(\d+)\s*(\d+)/) - { @Filter[$2] = $1 } } + { $Filter[$2] = $1 } } close (ASC) } elsif ($TcXPath ne '') { Report ("WrongFilterPath", $TcXPath) } @@ -861,7 +866,7 @@ sub HandleKey { ++$SortN ; $RestOfLine =~ s/\{(.*)\}/$1/o ; my ($lan, $enc, $str, $chr, $map, $alf) = split(/\}\s*\{/, $RestOfLine) ; - if ($str =~ /^(\d+)/) { $str = ''.chr(@Filter[$1]) } + if ($str =~ /^(\d+)/) { $str = ''.chr($Filter[$1]) } $map = chr(ord($MAP[$i])+128) ; $STR[$SortN] = $str ; $CHR[$SortN] = $chr ; @@ -1279,8 +1284,8 @@ sub HandleRegister # the } { makes sure that local {} is ok # if ($Key eq "") { $Key = SanitizedString($Entry) } - if ($SortMethod ne '') - { $ProcessHigh = 0 } + # if ($SortMethod ne '') + # { $ProcessHigh = 0 } if ($ProcessHigh) { $Key = HighConverted($Key) } $KeyTag = substr $Key, 0, 1 ; @@ -2075,7 +2080,7 @@ sub SaveFigurePresets { $Figures[$NOfFigures] .= ",t=\{$FTit\}" } if ($FCre) { $Figures[$NOfFigures] .= ",c=\{$FCre\}" } - $Figures[$NOfFigures] .= ",s=$FSiz]\n" } } + $Figures[$NOfFigures] .= ",s=$FSiz]" } } #D The \EPS\ to \PDF\ conversion pipe to \GHOSTSCRIPT\ is #D inspired by a script posted by Sebastian Ratz at the @@ -2580,8 +2585,10 @@ sub FlushFigures open ( TUF, ">$OutputFile" ) ; print TUF "%\n" . "% $Program / Figures\n" . "%\n" ; print TUF "\\thisisfigureversion\{1996.06.01\}\n" . "%\n" ; + # a joins is nicer for ($n=1 ; $n<=$NOfFigures ; ++$n) - { print TUF $Figures[$n] } + { print TUF "$Figures[$n]%\n" } + print TUF "\\endinput"; close (TUF) ; if ($NOfFigures) { Report("OutputFile", $OutputFile ) } @@ -2772,7 +2779,9 @@ if ($PurgeAllFiles) { push @forsuresuffixes, @texnonesuffixes ; @texnonesuffixes = [] } sub PurgeFiles # no my in foreach - { my $pattern = $ARGV[0] ; my $strippedname, $basename ; + { my $pattern = $ARGV[0] ; + my $strippedname ; + my $basename ; my @files = () ; if ($pattern eq '') { $pattern = "*.*" ; @@ -2895,8 +2904,11 @@ elsif ($PurgeFiles ) { PurgeFiles } elsif ($PurgeAllFiles ) { PurgeFiles } elsif ($AnalyzeFile ) { AnalyzeFile } elsif ($FilterPages ) { FilterPages } -elsif ($SciteApi ) { GenerateSciteApi } elsif ($ProcessHelp ) { ShowHelpInfo } # redundant else { ShowHelpInfo } +print "\n" ; +print " remark : 'texutil' is now part of 'texexec'\n" ; +print " warning : use 'texmfstart texutil' instead\n" ; + #D So far. |