From c2ae311de5e0399bcc8c2e2a92f9d01375bf0bc7 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 7 Jan 2010 22:17:46 +0000 Subject: missed commit git-svn-id: svn://tug.org/texlive/trunk@16632 c570f23f-e606-0410-a88d-b1316a301751 --- .../source/texk/texlive/linked_scripts/Makefile.am | 4 +- .../source/texk/texlive/linked_scripts/Makefile.in | 2 +- .../texk/texlive/linked_scripts/pst2pdf/pst2pdf | 168 +++++++++++++-------- 3 files changed, 109 insertions(+), 65 deletions(-) (limited to 'Build') diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.am b/Build/source/texk/texlive/linked_scripts/Makefile.am index f9209cdb0aa..19cb9fef659 100644 --- a/Build/source/texk/texlive/linked_scripts/Makefile.am +++ b/Build/source/texk/texlive/linked_scripts/Makefile.am @@ -1,6 +1,6 @@ ## Makefile.am for the TeX Live subdirectory texk/texlive/linked_scripts/ ## -## Copyright (C) 2009 Peter Breitenlohner +## Copyright (C) 2009, 2010 Peter Breitenlohner ## You may freely use, modify and/or distribute this file. ## ## TeX Live's extra scripts. @@ -82,7 +82,7 @@ nobase_dist_script_SCRIPTS = \ ppower4/pdfthumb.tlu \ ppower4/ppower4.tlu \ pst-pdf/ps4pdf \ - pst2pdf/pst2pdf.pl \ + pst2pdf/pst2pdf \ purifyeps/purifyeps \ splitindex/perl/splitindex.pl \ svn-multi/svn-multi.pl \ diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.in b/Build/source/texk/texlive/linked_scripts/Makefile.in index 4b62823180a..a89091550b7 100644 --- a/Build/source/texk/texlive/linked_scripts/Makefile.in +++ b/Build/source/texk/texlive/linked_scripts/Makefile.in @@ -231,7 +231,7 @@ nobase_dist_script_SCRIPTS = \ ppower4/pdfthumb.tlu \ ppower4/ppower4.tlu \ pst-pdf/ps4pdf \ - pst2pdf/pst2pdf.pl \ + pst2pdf/pst2pdf \ purifyeps/purifyeps \ splitindex/perl/splitindex.pl \ svn-multi/svn-multi.pl \ diff --git a/Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf b/Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf index 2262e9e15a2..238757135d0 100755 --- a/Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf +++ b/Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf @@ -3,43 +3,61 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $ use strict; # to be sure, that all is safe ... :-) -# v. 0.06 simplify the use of PSTricks with pdf -# 2007-08-28 (c) hvoss@tug.org +# v. 0.10 simplify the use of PSTricks with pdf +# 2010-01-04 (c) Herbert Voss +# $Id: pst2pdf.pl 239 2010-01-01 17:23:13Z herbert $ +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# use File::Path; # creating/removing dirs +use File::Copy; # copying files use File::Basename; # scan argument use IO::File; # simple IO operation use Getopt::Long; # read parameter #----------------------- User part begin ------------------------ my $imageDir = "images"; # where to save the images -#my @imageType = ("eps","pdf","png"); # all image types (png only for Linux) my @imageType = ("eps","pdf"); # all image types -my $Iext = ".png"; # leave empty, if not a special one +push (@imageType, "png") if $^O ne 'MSWin32'; +my $Iext = ".pdf"; # leave empty, if not a special one my $tempDir = "."; # temporary directory my $verbose = 1; # 0 or 1, logfile my $clear = 0; # 0 or 1, clears all temporary files -my $DPI = 75; # very low value +my $DPI = 75; # very low value for the png's my $Iscale = 1; # for \includegraphics my $noImages = 0; # 1->create no images #----------------------- User part end --------------------------- @ARGV == 0 && die "file name expected!\n"; -my @SuffixList = (".tex","",".ltx"); # possible extensions +my @SuffixList = (".tex","",".ltx"); # possible extensions my ($name,$path,$ext) = fileparse($ARGV[0],@SuffixList); -if ( $ext eq "" ) { $ext = ".tex"; } # me need the extension as well +if ( $ext eq "" ) { $ext = ".tex"; } # me need the extension as well my $TeXfile = "$path$name$ext"; -my $Logfile = "$tempDir/$name.plog"; # our own log file +my $Logfile = "$tempDir/$name.plog"; # our own log file open (LOGfile, ">$Logfile") or die "cannot open $Logfile!"; -my $result = GetOptions ("DPI=i" => \$DPI, # numeric - "Iscale=f" => \$Iscale, # real - "imageDir=s" => \$imageDir, # string - "tempDir=s" => \$tempDir, # string - "Iext=s" => \$Iext, # string - "clear" => \$clear, # flag - "noImages" => \$noImages, # flag - "verbose" => \$verbose); # flag +my $result = GetOptions ("DPI=i" => \$DPI, # numeric + "Iscale=f" => \$Iscale, # real + "imageDir=s" => \$imageDir, # string + "tempDir=s" => \$tempDir, # string + "Iext=s" => \$Iext, # string + "clear" => \$clear, # flag + "noImages" => \$noImages, # flag + "verbose" => \$verbose); # flag LOG ("Parameters:"); LOG ("==> imageDir = $imageDir"); @@ -52,6 +70,7 @@ LOG ("==> clear = $clear"); LOG ("==> noImages = $noImages"); my $imgNo = 0; # internal image counter +my $pstExaLoaded = 0; # Document loads pst-exa LOG ("Running on [$path][$name][$ext]"); open (FILE, "<$TeXfile") or die "cannot open source file $TeXfile!"; # the source @@ -93,9 +112,11 @@ sub savePreamble { # create a preamble file open (FILEp, ">$tempDir/$filename.preamble") or die "cannot open preamble file $tempDir/$filename.preamble!"; while () { # read all until \begin{document} + $pstExaLoaded = index($_,"usepackage{pst-exa}"); my $i = index($_,"begin{document}"); if ($i > 0) { if ($i > 1) { print FILEp substr($_,0,--$i); } # write all until \begin{document} + print FILEp "\n\\usepackage{pst-exa}\n"; close(FILEp); # close preamble LOG ("----- Close Preamble ------"); return; @@ -109,32 +130,33 @@ sub savePreamble { # create a preamble file return; } -sub searchPS { # search the PostScript parts - my @PS = (); # single PS sequence - my @PStotal = (); # all PS sequences as list of arrays - my $depth = -1; # counts nested macros - my $type = -1; # -1-> none; 1->PST; 2->PS; - my $EndDocument = 0; # ignore all after \end{document} - my $iVerb = 0; # test for verbatim or lstlisting environment, must be ignored - while () { # scan the input file +sub searchPS { # search the PostScript parts + my @PS = (); # single PS sequence + my @PStotal = (); # all PS sequences as list of arrays + my $depth = -1; # counts nested macros + my $type = -1; # -1-> none; 1->PST; 2->PS; + my $EndDocument = 0; # ignore all after \end{document} + my $iVerb = 0; # test for verbatim or lstlisting environment, must be ignored + while () { # scan the input file if (!$EndDocument) { - chomp; - my $line = $_; + chomp; # delete EOL character + my $line = $_; # save line if ( !$iVerb ) { $iVerb = ((index($line,"begin{verbatim}") > 0) or (index($line,"begin{lstlisting}") > 0)); - } # do nothing until \end{verbatim} + } # do nothing until \end{verbatim} if ( !$iVerb ) { my $iPS = index($line,"begin{postscript}"); - my $iPST = index($line,"begin{pspicture}"); + my $iPST = index($line,"begin{pspicture*}"); + if ($iPST < 0) { $iPST = index($line,"begin{pspicture}"); } # alternative if ($iPST < 0) { $iPST = index($line,"pspicture"); } # alternative \pspicture... - if (($iPS > 0) && ( $type == 1 )){ print "postscript environment must be outer level!\n"; exit 1; } + if (($iPS > 0) && ( $type == 1 )){ print "postscript environment must be of outer level!\n"; exit 1; } if ( $type < 0 ) { # no active environment if ($iPS > 0) { # we have \begin{postscript} $type = 2; - $line = substr($line,$iPS-1); # add rest of the line + $line = substr($line,$iPS-1); # add rest of the line LOG("PS-Zeile: $line"); } - elsif ( $iPST > 0 ) { # we have \begin{pspicture} or \pspicture + elsif ( $iPST > 0 ) { # we have \begin{pspicture} or \pspicture $type = 1; $depth++; $line = substr($line,$iPST-1); # add all unitl pspicture @@ -142,19 +164,22 @@ sub searchPS { # search the PostScript parts } } # we have now \begin{pspicture} or \begin{postscript} - if ($type > 0) { # start Scan, we have an environment + if ($type > 0) { # start Scan, we have an environment LOG ("searchPS: set \$type=$type"); - $iPST = index($line,"end{pspicture}"); + $iPST = index($line,"end{pspicture*}"); + if ($iPST < 0) { $iPST = index($line,"end{pspicture}"); } # alternative if ($iPST < 0) { $iPST = index($line,"endpspicture"); } # alternative \endpspicture... $iPS = index($line,"end{postscript}"); - if ($iPST > 0) { # test, we can have postscript and pspicture in one line - if ( $type < 2) { # found end of pspicture environment + if ($iPST > 0) { # test, we can have postscript and pspicture in one line + if ( $type < 2) { # found end of pspicture environment LOG ("searchPS: $line"); $depth--; if ($depth < 0) { $type = -1; if (index($line,"endpspicture") > 0) # add line, depends to type { push @PS,substr($line,0,$iPST+12); } # \endpspicture + elsif (index($line,"pspicture*") > 0) + { push @PS,substr($line,0,$iPST+15); } # \end{pspicture} else { push @PS,substr($line,0,$iPST+14); } # \end{pspicture} LOG ("searchPS: set \$type=$type"); push @PStotal,[@PS]; # add PS sequence @@ -192,17 +217,18 @@ sub searchPS { # search the PostScript parts sub runTeX { my $filename = pop; - system("latex $filename"); - system("dvips $filename"); - system("ps2pdf $filename.ps"); + system("latex $filename"); # or die "Error in the LaTeX run from file $filename!"; + system("dvips $filename"); # or die "Error in the dvips run from file $filename!"; + system("ps2pdf $filename.ps");# or die "Error in the ps2pdf run from file $filename!"; + copy("$filename.tex", "$imageDir/$filename-$imgNo.tex") or die "Cannot copy Source file!";; for my $Itype ( @imageType ) { if ($Itype eq "pdf") { system("pdfcrop $filename.pdf $imageDir/$filename-$imgNo.pdf"); } - if ($Itype eq "eps") { system("pdftops -f 1 -l 1 -eps $imageDir/$filename-$imgNo.pdf $imageDir/$filename-$imgNo.eps"); } if ($Itype eq "png") { system("pdftoppm -f 1 -l 1 -r $DPI $imageDir/$filename-$imgNo.pdf $imageDir/"); - system("convert $imageDir/-000001.ppm $imageDir/$filename-$imgNo.png"); - system("rm $imageDir/-00001.ppm"); + system("convert $imageDir/-1.ppm $imageDir/$filename-$imgNo.png"); + system("rm $imageDir/-1.ppm"); } + if ($Itype eq "eps") { system("pdftops -f 1 -l 1 -eps $imageDir/$filename-$imgNo.pdf $imageDir/$filename-$imgNo.eps"); } } $imgNo++; } @@ -225,9 +251,11 @@ sub runFile { my @PS = @$aref; open (FILEp, "<$tempDir/$filename.preamble") or die "cannot open $tempDir/$filename.preamble!"; open (FILEsub, ">$tempDir/$filename-tmp.tex") or die "cannot open $tempDir/$filename-tmp.tex!"; +# print FILEsub "\\RequirePackage{listings}\n"; while () { print FILEsub $_; } print FILEsub "\\pagestyle{empty}\n"; print FILEsub "\\newenvironment{postscript}{}{}\n"; + print FILEsub "\\providecommand\\IncludeGraphics[2][]{}\n"; print FILEsub "\\begin{document}\n"; if ( $verbose ) { LOG("\@PS: $_"); } foreach ( @PS ) { print FILEsub "$_\n"; } @@ -243,8 +271,10 @@ sub runpdfTeX() { open (PDF, ">$tempDir/$pdfname-pdf.tex") or die "cannot open $tempDir/$pdfname-pdf.tex!"; open (FILE, "<$name.tex") or die "cannot open $name!"; print PDF "\\RequirePackage{graphicx}\n"; + if ($pstExaLoaded < 1) { + print PDF "\\let\\IncludeGraphics\\includegraphics\n"; } # print PDF "\\setkeys{Gin}{scale=0.25}\n"; - print PDF "\\RequirePackage[pdftex]{xcolor}\n"; +# print PDF "\\providecommand\\psset[1]{}\n"; # print PDF "\\graphicspath{{$imageDir/}}\n"; my $ignore = 0; my $IMGno = 0; @@ -265,12 +295,12 @@ sub runpdfTeX() { $type = 2; $ignore = 1; if ($iPS > 1) { print PDF substr($_,0,--$iPS); } # add preceeding text - print PDF "\\includegraphics[scale=$Iscale]{$imageDir/$name-tmp-$IMGno$Iext}"; -# print PDF "\\includegraphics{$name-tmp-$IMGno$Iext}"; # use \graphicspath + print PDF "\\IncludeGraphics[scale=$Iscale]{$imageDir/$name-tmp-$IMGno$Iext}"; $IMGno++; } # postscript env if ( $type < 2 ) { - my $iPST = index($_,"begin{pspicture}"); + my $iPST = index($_,"begin{pspicture*}"); + if ($iPST < 0) { $iPST = index($_,"begin{pspicture}"); } # alternative ... if ($iPST < 0) { $iPST = index($_,"\\pspicture"); } # alternative \endpspicture... if ( $iPST >= 0 ) { # start Scan $ignore = 1; @@ -279,8 +309,8 @@ sub runpdfTeX() { LOG("Increase depth: $depth"); if ( $depth == 0 ) { if ($iPST > 1) { print PDF substr($_,0,--$iPST); }# add preceeding text - print PDF "\\includegraphics[scale=$Iscale]{$imageDir/$name-tmp-$IMGno$Iext}"; -# print PDF "\\includegraphics{$name-tmp-$IMGno$Iext}"; # use \graphicspath + print PDF "\\IncludeGraphics[scale=$Iscale]{$imageDir/$name-tmp-$IMGno$Iext}"; +# print PDF "\\IncludeGraphics{$name-tmp-$IMGno$Iext}"; # use \graphicspath $IMGno++; LOG("Increase Image counter: $IMGno"); } @@ -292,14 +322,18 @@ sub runpdfTeX() { if ($iPS > 0) { print PDF substr($_,$iPS+15); # rest of line $ignore = 0; + $type=-1; } # end Scan } elsif ( $type == 1 ) { # pspicture env - my $iPST = index($_,"end{pspicture}"); + my $iPST = index($_,"end{pspicture*}"); + if ($iPST < 0) { $iPST = index($_,"end{pspicture}"); }# alternative ... if ($iPST < 0) { $iPST = index($_,"endpspicture"); } # alternative \endpspicture... if ($iPST > 0) { # end Scan if (index($_,"endpspicture") > 0) # add rest of line, depends to type { print PDF substr($_,$iPST+12); } # \endpspicture - else { print PDF substr($_,$iPST+14); } # \end{pspicture} + elsif (index($_,"pspicture*") > 0) + { print PDF substr($_,$iPST+15); } # \end{pspicture*} + else { print PDF substr($_,$iPST+14); } # \end{pspicture} $depth--; LOG("Decrease depth: $depth"); if ($depth < 0) { $ignore = 0; } @@ -329,12 +363,12 @@ __END__ =head1 NAME -B - run a TeX source, and convert all PS-related part as single images - (pdf and eps) +B - run a TeX source, and convert all PS-related part as single images + (pdf and/or eps and/or png and/or ...) and then runs pdflatex. =head1 SYNOPSIS - PSTpdf + pst2pdf.pl [Options] TODO @@ -344,14 +378,25 @@ runs latex and pdflatex on the TeX =head1 OPTIONS ---imageDir ---Iext=<.ext> ---DPI= ---Iscale= ---tempDir= ---verbose ---clear ---noImages +=over + +=item --imageDir - the dir for the created images + +=item --Iext=<.ext> - the extension for \includegraphics, can be empty + +=item --DPI= - the dots per inch for a cretaed png file + +=item --Iscale= - the value for \scale= in \includegraphics + +=item --tempDir= - temporary directory for the temp files + +=item --verbose - long log + +=item --clear - delete all temp files + +=item --noImages - create no images, build only pdf + +=back =head1 AUTHORS @@ -359,7 +404,7 @@ Herbert Voss =head1 COPYRIGHT -Copyright (c) 2007 Herbert Voss +Copyright (c) 2007-2009 Herbert Voss This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -374,4 +419,3 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -1;6H \ No newline at end of file -- cgit v1.2.3