From 89135e7e1b6a211b066867735c41e9a1a4310c5f Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 10 Mar 2013 22:38:10 +0000 Subject: pst2pdf (10mar13) git-svn-id: svn://tug.org/texlive/trunk@29333 c570f23f-e606-0410-a88d-b1316a301751 --- .../source/texk/texlive/linked_scripts/Makefile.am | 2 +- .../source/texk/texlive/linked_scripts/Makefile.in | 2 +- .../texk/texlive/linked_scripts/pst2pdf/pst2pdf | 524 --------- .../texk/texlive/linked_scripts/pst2pdf/pst2pdf.pl | 659 +++++++++++ .../texk/texlive/linked_scripts/texlive/tlmgr.pl | 1231 +++++++++++--------- 5 files changed, 1314 insertions(+), 1104 deletions(-) delete mode 100755 Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf create mode 100755 Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf.pl (limited to 'Build/source') diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.am b/Build/source/texk/texlive/linked_scripts/Makefile.am index a57d828b3be..e4d32e1c757 100644 --- a/Build/source/texk/texlive/linked_scripts/Makefile.am +++ b/Build/source/texk/texlive/linked_scripts/Makefile.am @@ -137,7 +137,7 @@ texmf_dist_other_scripts = \ pkfix/pkfix.pl \ pkfix-helper/pkfix-helper \ pmx/pmx2pdf.lua \ - pst2pdf/pst2pdf \ + pst2pdf/pst2pdf.pl \ purifyeps/purifyeps \ splitindex/perl/splitindex.pl \ sty2dtx/sty2dtx.pl \ diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.in b/Build/source/texk/texlive/linked_scripts/Makefile.in index 5a2eeb4d833..bce3c7105c5 100644 --- a/Build/source/texk/texlive/linked_scripts/Makefile.in +++ b/Build/source/texk/texlive/linked_scripts/Makefile.in @@ -318,7 +318,7 @@ texmf_dist_other_scripts = \ pkfix/pkfix.pl \ pkfix-helper/pkfix-helper \ pmx/pmx2pdf.lua \ - pst2pdf/pst2pdf \ + pst2pdf/pst2pdf.pl \ purifyeps/purifyeps \ splitindex/perl/splitindex.pl \ sty2dtx/sty2dtx.pl \ diff --git a/Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf b/Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf deleted file mode 100755 index da0aba08e4d..00000000000 --- a/Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf +++ /dev/null @@ -1,524 +0,0 @@ -eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' - if 0; - -use strict; # to be sure, that all is safe ... :-) - -# $Id: pst2pdf.pl 611 2011-12-14 08:41:35Z herbert $ -# v. 0.13 simplify the use of PSTricks with pdf -# 2011-12-12 (c) Herbert Voss -# Pablo González Luengo and http://perlenespanol.com -# -# 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 $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 for the png's -my $Iscale = 1; # for \includegraphics -my $noImages = 0; # 1->create no images -my $runBibTeX = 0; # 1->runs bibtex -my $runBiber = 0; # 1->runs biber and sets $runBibTeX=0 -my $ppm = 0; # 1->create .ppm files -my $norun = 0; # 1->runs pdflatex -my $miktex = 0; # 1->runs pdlatex for miktex -my $eps = 0; # 1->create .eps files -#----------------------- User part end --------------------------- -#----------------------- program identification, options and help -my $program = "pst2pdf"; -my $ident = '$Id: pst2pdf.pl 611 2011-12-14 08:41:35Z herbert $'; -my $copyright = < -END_COPYRIGHT -my $licensetxt= < [Options] -pst2pdf 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. See pst2pdf documentation for more info -Options: - --help - display this help and exit - --version - display version information and exit - --license - display license information and exit - --imageDir - the dir for the created images (default images) - --DPI= - the dots per inch for a cretaed ppm files (default 75) - --ppm - create .ppm files - --eps - create .eps files - --Iscale= - the value for [scale=] in \\includegraphics - --verbose - long log - --clear - delete all temp files - --norun - create file-pdf.tex, but, no run pdflatex - --runBibTeX - run bibtex on the aux file, if exists - --runBiber - run biber on the bcf file, if exists - --miktex - for miktex users -enable-write18 -Examples: -* $program test.tex --clear --ppm --eps -* produce test-pdf.tex and .ppm,.eps,.tex and .pdf for all images in image dir -END_OF_USAGE -# -my $result=GetOptions ( - "help", - "version", - "license", - "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 - "runBibTeX" => \$runBibTeX, # flag - "ppm" => \$ppm, # flag - "norun" => \$norun, # flag - "miktex" => \$miktex, # flag - "eps" => \$eps, # flag - "runBiber" => \$runBiber, # flag - "verbose" => \$verbose, -) or die $usage; -# help functions -sub debug { print STDERR "* @_\n" if $::opt_debug; } -sub warning { print STDERR "==> Warning: @_\n"; } -sub error { die "$title!!! Error: @_\n"; } -sub errorUsage { die "Error: @_ (try --help for more information)\n"; } -# options for command line -if ($::opt_help) { - print $usage; - exit (0); -} -if ($::opt_version) { - print $title; - print $copyright; - exit (0); -} -if ($::opt_license) { - print $licensetxt; - exit (0); -} -# open file -my $InputFilename = ""; -if ($::opt_filter) { - @ARGV == 0 or - errorUsage "Input file cannot be used with filter option"; - debug "Filtering: will read standard input"; -} else { - @ARGV > 0 or errorUsage "Input filename missing"; - @ARGV < 2 or errorUsage "Unknown option or too many input files"; - $InputFilename = $ARGV[0]; - debug "Input filename:", $InputFilename; -} -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 -my $TeXfile = "$path$name$ext"; -my $Logfile = "$tempDir/$name.plog"; # our own log file -open (LOGfile,">$Logfile") or die "cannot open $Logfile!"; -LOG ("Parameters:"); -LOG ("==> imageDir = $imageDir"); -LOG ("==> Iext = $Iext"); -LOG ("==> DPI = $DPI"); -LOG ("==> Iscale = $Iscale"); -LOG ("==> tempDir = $tempDir"); -LOG ("==> verbose = $verbose"); -LOG ("==> clear = $clear"); -LOG ("==> noImages = $noImages"); -LOG ("==> runBibTeX= $runBibTeX"); -LOG ("==> runBiber = $runBiber"); -LOG ("==> ppm = $ppm"); -LOG ("==> norun = $norun"); -LOG ("==> miktex = $miktex"); -LOG ("==> eps = $eps"); - -if ($runBibTeX && $runBiber) { - LOG ("!!! you cannot run BibTeX and Biber at the same document ..."); - LOG ("!!! Assuming to run Biber"); - $runBibTeX = 0; -} -if ($ppm) { - LOG ("Generate .ppm files ..."); - $ppm = 1; -} -if ($norun) { - LOG ("no compile file-pdf.tex"); - $norun = 1; -} -if ($miktex) { - LOG ("enable write 18 ..."); - $miktex = 1; -} -if ($eps) { - LOG ("Generate .eps files ..."); - $eps = 1; -} - -my $imgNo = 1; # 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 -if (!$noImages ) { - if (-d $imageDir) { LOG ("$imageDir exists") } - else { mkdir("$imageDir", 0744) || die "cannot mkdir $imageDir: $!"; -LOG ("Imagedir created"); } -LOG ("go to savePreamble ... "); -savePreamble($name); -runBurst("$tempDir"); -LOG ("done!\n go to runFile ..."); -runFile($name); -LOG ("done!"); -close FILE; # close source file -}# !noImages - -#------------ Create filename-pics.pdf, split and generate .ppm -sub runBurst{ -if ($miktex){system("pdflatex -enable-write18 -interaction=nonstopmode $tempDir/$name");} -else{system("pdflatex -shell-escape -interaction=nonstopmode $tempDir/$name");} -system("pdftk $name-pics.pdf burst output $imageDir/$name-tmp-\%1d.pdf"); -if ($ppm){system("pdftoppm -r $DPI $name-pics.pdf $imageDir/$name-tmp"); -# Renaming .ppm neded for windows -if ($^O eq 'MSWin32') { -my $dren = "$tempDir/$imageDir"; -my $fichero = ''; -my $ppmren = ''; -my $renNo = 1; -if(opendir(DIR,$dren)){ - foreach (readdir DIR){ - $fichero = $_; - if ($fichero =~ /([^\d]+)(\d+).ppm/){ - my $renNo=int($2); - my $newname="$1$renNo.ppm"; - $ppmren = rename("$dren/$fichero","$dren/$newname"); - } - } - } - else - { - print "dont open".$dren; - } -closedir DIR; -} -# end renaming -} -} -#------------ end pdftk burst -LOG ("runpdfTeX ... "); -runpdfTeX("$path$name",$name); -LOG ("all finished ... :-)"); -close LOGfile; - -if ( $clear ) { -unlink "$path$name.txt"; -unlink "$path$name.log"; -unlink "$path$name.plog"; -unlink "$path$name.preamble"; -unlink "$path$name.pdf"; - } -# create a preamble file -# if we have a \input command inside the preamble, it doesn't hurt, we need -# it anyway for the postscript files and the pdf one. -sub savePreamble { - my $filename = pop; # get the file name - LOG ("----- Start Preamble -----"); - 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} - close(FILEp); # close preamble - LOG ("----- Close Preamble ------"); - return; - } else { - print FILEp "$_"; # write into preamble - LOG ("$_"); - } - } - close(FILEp); - if ( $verbose ) { LOG("<-----Preamble<----"); } - 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 - if (!$EndDocument) { - 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} - if ( !$iVerb ) { - my $iPS = index($line,"begin{postscript}"); - 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 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 - LOG("PS-Zeile: $line"); - } - elsif ( $iPST > 0 ) { # we have \begin{pspicture} or \pspicture - $type = 1; - $depth++; - $line = substr($line,$iPST-1); # add all unitl pspicture - LOG("PST-Zeile: $line"); - } - } -# we have now \begin{pspicture} or \begin{postscript} - if ($type > 0) { # start Scan, we have an environment - LOG ("searchPS: set \$type=$type"); - $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 - 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 - LOG ("---->PS---->\n@PS\n<----PS<----"); - @PS = (); # start new PS sequence - } # no pspicture env left - } else { push @PS,$line; } # pspicture inside postscript - } elsif ($iPS > 0) { # must be type=1 -> stop Scan - LOG ("searchPS: $line"); - $type = -1; - push @PS,substr($line,0,$iPS+15); # add line - LOG ("searchPS: set \$type=$type"); - push @PStotal,[@PS]; # add PS sequence - LOG ("---->PS---->\n@PS\n<----PS<----"); - @PS =(); # start new PS sequence - } else { push @PS,$line; } # add line - } - my $i = index($line,"end{document}"); - if ($i > 0) { $EndDocument++; LOG("EndDocument in searchPS"); } - } # if ( $iVerb ) - if (( index($line,"end{verbatim}") > 0 ) or ( index($line,"end{lstlisting}") > 0 )) { $iVerb = 0; } - }} - if ( $verbose ) { - LOG("---->PStotal---->"); - for my $aref ( @PStotal ) { - my @a = @$aref; - my $i = 0; - foreach ( @a ) { LOG ($a[$i]); $i++; } - } - LOG ("<----PStotal<----"); - } - close(FILE); - return @PStotal; # return all PS sequences -} - -# Creating subfiles.tex and .eps for images -sub runTeX{ - my $filename = pop; - my $name = "$filename"; - copy("$filename.tex", "$imageDir/$filename-$imgNo.tex") or die "Cannot copy Source file!"; - if ($eps){ - system("pdftops -level3 -eps $imageDir/$filename-$imgNo.pdf $imageDir/$filename-$imgNo.eps"); - } -$imgNo=$imgNo+1; -} - -sub runFile { - my $filename = pop; - my @PSarray = searchPS(); - if ( $verbose ) { - LOG("---->PSarray---->"); - for my $aref ( @PSarray ) { - my @a = @$aref; - my $i = 0; - foreach ( @a ) { print LOG $a[$i]."\n"; $i++; } - } - LOG("<----PSarray<----"); - my $no = @PSarray; - LOG("PS: ".$no." PS sequence(s)"); - } - for my $aref ( @PSarray ) { - 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!"; - while () {print FILEsub $_; } - print FILEsub "\\pagestyle{empty}\n"; - print FILEsub "\\begin{document}\n"; - if ( $verbose ) { LOG("\@PS: $_"); } - foreach ( @PS ) { print FILEsub "$_\n"; } - print FILEsub "\\end{document}\n"; - close (FILEsub); - close (FILEp); - runTeX("$tempDir/$filename-tmp"); - } -} -# Replace files -sub runpdfTeX() { - my ($name,$pdfname) = @_; - open (PDF, ">$tempDir/$pdfname-pdf.tex") or die "cannot open $tempDir/$pdfname-pdf.tex!"; - open (FILE, "<$name.tex") or die "cannot open $name!"; - my $ignore = 0; - my $IMGno = 1; - my $depth = -1; - my $type = -1; - my $EndDocument = 0; # ignore all after \end{document} - my $iVerb = 0; - while () { # scan the input file - if ( !$iVerb ) { - $iVerb = ((index($_,"begin{verbatim}") > 0) or (index($_,"begin{lstlisting}") > 0)); - } # do nothing until \end{verbatim}|| \end{lstlisting} - if ( !$iVerb ) { - my $i = index($_,"end{document}"); - if ($i > 0) { print PDF $_; $EndDocument++; LOG("EndDocument in runpdfTeX"); } - if ( !$EndDocument ) { - my $iPS = index($_,"begin{postscript}"); - if ( $iPS > 0 ) { - $type = 2; - $ignore = 1; - if ($iPS > 1) { print PDF substr($_,0,--$iPS); } # add preceeding text - print PDF "\\includegraphics[scale=$Iscale]{$pdfname-tmp-$IMGno}"; # use pdfname - $IMGno=$IMGno+1; - } # postscript env - if ( $type < 2 ) { - 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; - $type = 1; - $depth++; # pspicture env - LOG("Increase depth: $depth"); - if ( $depth == 0 ) { - if ($iPST > 1) { print PDF substr($_,0,--$iPST); } # add preceeding text - print PDF "\\includegraphics[scale=$Iscale]{$pdfname-tmp-$IMGno}"; # use \graphicspath - $IMGno=$IMGno+1; - LOG("Increase Image counter: $IMGno"); - } - } - } - if ( !$ignore ) { print PDF "$_"; } # default line - if ( $type == 2 ) { # postscript env - my $iPS = index($_,"end{postscript}"); - 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*}"); - 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 - 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; } - } - } - } # if ( !$EndDocument ) - } else { print PDF $_; } # if ( $iVerb ) - if (( index($_,"end{verbatim}") > 0 ) or ( index($_,"end{lstlisting}") > 0 )) { $iVerb = 0; } - } # while () - close (FILE); - close (PDF); -# Coment pst-package - open (IPDF, "<$tempDir/$pdfname-pdf.tex"); - undef $/; # read all file - my ($uno,$dos) = split(/\\begin\{document\}/,,2); - close IPDF; - - my @coment = split /\n/, $uno; # split in two - my @preamb; - - foreach my $line (@coment) { - chomp($line); - $line =~ s/\\usepackage(?:\[.+?\])?\{pst.+?}//g; # delete - $line =~ s/\\usepackage(?:\[.+?\])?\{psfr.+?}//g; # delete - $line =~ s/(\\usepackage(?:\[.+?\])?)\{auto-pst.+?}//g; # delete - $line =~ s/(\\usepackage(?:\[.+?\])?)\{vaucanson-.+?}//g; # delete - $line =~ s/(\\usepackage(?:\[.+?\])?)\{psgo}//g; # delete - $line =~ s/(\\usepackage(?:\[.+?\])?)\{graph/\%$1\{graph/g; # comment - next if $line =~ m/^\s*$/; - push(@preamb,$line); # adding changes -} -my $clean = join("\n", @preamb, "\\usepackage{grfext}\n\\\PrependGraphicsExtensions*{$Iext}\n\\usepackage{graphicx}\n\\graphicspath{{$imageDir/}}\n\\begin{document}\n". $dos); - -open (OPDF,">$tempDir/$pdfname-pdf.tex"); # write changes -print OPDF $clean; -close OPDF; -# close coment pst-package - -my $runAgain = 0; -if ($norun){print "Done\n";} -else {system("pdflatex -interaction=nonstopmode $pdfname-pdf");} -if (-e "$tempDir/$pdfname-pdf.idx") { system("makeindex $tempDir/$pdfname-pdf.idx"); $runAgain++; } -if ($runBibTeX && -e "$tempDir/$pdfname-pdf.aux") { system("bibtex $tempDir/$pdfname-pdf"); $runAgain++; } -if ($runBiber && -e "$tempDir/$pdfname-pdf.bcf") { system("biber $tempDir/$pdfname-pdf"); $runAgain++; } -if ($runAgain) { system("pdflatex $tempDir/$pdfname-pdf"); } -if ( $clear ) { - unlink "$name.txt"; - unlink "$tempDir/$name.aux"; - unlink "$tempDir/$pdfname-pdf.log"; - unlink "$tempDir/$pdfname-pdf.aux"; - unlink "$tempDir/$pdfname-pdf-autopp.txt"; - unlink "$tempDir/$pdfname-pics.pdf"; - unlink "$tempDir/doc_data.txt"; - unlink "$tempDir/$pdfname-tmp.tex"; - } -} - -sub LOG() { - if ( $verbose ) { print LOGfile "@_\n"; } -} -__END__ diff --git a/Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf.pl b/Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf.pl new file mode 100755 index 00000000000..040cdf7e7dd --- /dev/null +++ b/Build/source/texk/texlive/linked_scripts/pst2pdf/pst2pdf.pl @@ -0,0 +1,659 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' + if 0; + +use strict; # to be sure, that all is safe ... :-) + +# $Id: pst2pdf.pl 611 2011-12-14 08:41:35Z herbert $ +# v. 0.14 simplify the use of PSTricks with pdf +# 2011-12-12 (c) Herbert Voss +# Pablo González Luengo +# +# 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 +use autodie; +#----------------------- User part begin ------------------------ +my $imageDir = "images";# where to save the images +my $Iext = ".pdf"; # leave empty, if not a special one +my $tempDir = "."; # temporary directory +my $verbose = 0; # 0 or 1, logfile +my $clear = 0; # 0 or 1, clears all temporary files +my $DPI = 75; # very low value for the png's +my $Iscale = 1; # for \includegraphics +my $noImages = 0; # 1->create no images +my $single = 0; # 1->single create images +my $runBibTeX = 0; # 1->runs bibtex +my $runBiber = 0; # 1->runs biber and sets $runBibTeX=0 +my $ppm = 0; # 1->create .ppm files +my $norun = 0; # 1->runs pdflatex +my $eps = 0; # 1->create .eps files +my $files = 0; # 1->create image files .tex +my $all = 0; # 1->create all images and files for type +my $nopdftk = 0; # 1->create all images and files for type in single mode +my $xetex = 0; # 1->Using XeLaTeX for compilation. +#----------------------- User part end --------------------------- +#-------------- program identification, options and help --------- +my $program = "pst2pdf"; +my $ident = '$Id: pst2pdf.pl 611 2011-12-14 08:41:35Z herbert $'; +my $copyright = < +END_COPYRIGHT +my $licensetxt= < [Options] +pst2pdf run a TeX source, and convert all PS-related part as + single images (pdf or eps or ppm, default pdf) + and then runs pdflatex. See pst2pdf documentation for more info +Options: + --help - display this help and exit + --version - display version information and exit + --license - display license information and exit + --imageDir - the dir for the created images (default images) + --DPI= - the dots per inch for a cretaed ppm files (default 75) + --ppm - create .ppm files + --eps - create .eps files + --Iscale= - the value for [scale=] in \\includegraphics + --noImages - generate files without compile (need -norun) + --verbose - creates long log + --clear - delete all temp files + --norun - create file-pdf.tex, but, no run pdflatex + --runBibTeX - run bibtex on the aux file, if exists + --runBiber - run biber on the bcf file, if exists + --files - create images files (.tex) for all pst enviroment + --single - create images whitout pdftk and auto-pst-pdf + --all - create all image type and images.tex + --nopdftk - create all image type and images.tex in single mode + --xetex - using XeLaTeX for compilation. +Examples: +* $program test.tex --all +* produce test-pdf.tex and ppm,eps,tex and pdf for pst-enviroment in image dir +END_OF_USAGE +# +my $result=GetOptions ( + "help", + "version", + "license", + "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 + "single" => \$single, # flag + "runBibTeX" => \$runBibTeX, # flag + "ppm" => \$ppm, # flag + "norun" => \$norun, # flag + "eps" => \$eps, # flag + "files" => \$files, # flag + "all" => \$all, # flag + "nopdftk" => \$nopdftk, # flag + "xetex" => \$xetex, # flag + "runBiber" => \$runBiber, # flag + "verbose" => \$verbose, +) or die $usage; +#---------------- help functions -------------------------------- +sub errorUsage { die "Error: @_ (try --help for more information)\n"; } +# options for command line +if ($::opt_help) { +print $usage; + exit (0); +} +if ($::opt_version) { + print $title; + print $copyright; + exit (0); +} +if ($::opt_license) { + print $licensetxt; + exit (0); +} +# open file +my $InputFilename = ""; + @ARGV > 0 or errorUsage "Input filename missing"; + @ARGV < 2 or errorUsage "Unknown option or too many input files"; + $InputFilename = $ARGV[0]; + +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 +my $TeXfile = "$path$name$ext"; +open my $LOGfile,'>', "$tempDir/$name.plog"; # our own log file + LOG ("Parameters:"); + LOG ("==> imageDir = $imageDir"); + LOG ("==> Iext = $Iext"); + LOG ("==> DPI = $DPI"); + LOG ("==> Iscale = $Iscale"); + LOG ("==> tempDir = $tempDir"); + LOG ("==> verbose = $verbose"); + LOG ("==> clear = $clear"); + LOG ("==> noImages = $noImages"); + LOG ("==> single = $single"); + LOG ("==> runBibTeX= $runBibTeX"); + LOG ("==> runBiber = $runBiber"); + LOG ("==> ppm = $ppm"); + LOG ("==> norun = $norun"); + LOG ("==> eps = $eps"); + LOG ("==> files = $files"); + LOG ("==> xetex = $xetex"); + +if ($runBibTeX && $runBiber) { + LOG ("!!! you cannot run BibTeX and Biber at the same document ..."); + LOG ("!!! Assuming to run Biber"); + $runBibTeX = 0; +} +if ($ppm) { + LOG ("Generate .ppm files ..."); + $ppm = 1; +} +if ($norun) { + LOG ("no compile $name-pdf.tex"); + $norun = 1; +} +if ($eps) { + LOG ("Generate .eps files ..."); + $eps = 1; +} +if ($files) { + LOG ("Generate .tex images files ..."); + $files=1; +} +if ($all) { + LOG ("Generate all images files ..."); + $files=$eps = $ppm = $clear = 1; +} +if ($nopdftk) { + LOG ("single mode generate all images files ..."); + $single=$files=$eps = $ppm = $clear = 1; +} +if ($xetex) { + LOG ("Compiling using XeLaTeX ..."); + $xetex=1; +} + +my $imgNo = 1; # internal image counter +#----------- single mode no need pdftk and auto-pst-pdf ---------------------- +if ($single) { +LOG ("Running on [$path][$name][$ext]"); +open my $FILE,'<', "$TeXfile" ; # the source +LOG ("single mode generate images..."); +if (-d $imageDir) { LOG ("$imageDir exists") } +else { mkdir("$imageDir", 0744) ;} +savePreamble($name); +runFile($name); +close $FILE; # close source file +close $LOGfile; +} +#---------------- end single -------------- +else{ +LOG ("Running on [$path][$name][$ext]"); +open my $FILE,'<', "$TeXfile" ; # the source +if (!$noImages ) { +if (-d $imageDir) { LOG ("$imageDir exists") } +else { mkdir("$imageDir", 0744) ; +LOG ("Imagedir created"); } +LOG ("go to savePreamble ... "); +runBurst($tempDir); +savePreamble($name); +runFile($name); +LOG ("done!\n go to runFile ..."); +LOG ("done!"); +close $FILE; # close source file +close $LOGfile; +}# !noImages +} +#------------ Create filename-pics.pdf, split and generate .ppm +sub runBurst{ +if ($single){ print "single mode";} +else{ +my $entrada = "$TeXfile"; +my $salida = "$name-pics.tex"; + open my $ENTRADA,'<', "$entrada"; + open my $SALIDA,'>',"$salida"; + print $SALIDA "\\AtBeginDocument\{\n"; +if ($xetex){ + print $SALIDA "\\RequirePackage\[xetex,active,tightpage\]\{preview\}\n";} +else{ + print $SALIDA "\\RequirePackage\[active,dvips,tightpage\]\{preview\}\n";} + print $SALIDA "\\renewcommand\\PreviewBbAdjust\{-600pt -600pt 600pt 600pt\}\n"; + print $SALIDA "\\newenvironment{postscript}{}{}\n"; + print $SALIDA "\\PreviewEnvironment\{postscript\}\n"; + print $SALIDA "\\PreviewEnvironment\{pspicture\}\}\n"; + while ( my $linea = <$ENTRADA> ) { + print $SALIDA $linea;} + close $ENTRADA; + close $SALIDA; +# --------------------Compiling File -------------------------- +if ($xetex){ + system("xelatex -interaction=batchmode $tempDir/$name-pics.tex"); + system("pdfcrop -xetex $tempDir/$name-pics.pdf $tempDir/$name-pics.pdf");} +else{ + system("latex -interaction=batchmode $tempDir/$name-pics.tex"); + system("dvips $tempDir/$name-pics.dvi"); + system("ps2pdf -dProcessColorModel=/DeviceCMYK -dPDFSETTINGS=/prepress $tempDir/$name-pics.ps"); + system("pdfcrop $tempDir/$name-pics.pdf $tempDir/$name-pics.pdf");} + system("pdftk $tempDir/$name-pics.pdf burst output $imageDir/$name-fig-\%1d.pdf"); +if ($ppm){ + system("pdftoppm -r $DPI $tempDir/$name-pics.pdf $imageDir/$name-fig");} + } +} +#------------ end pdftk burst +LOG ("runpdfTeX ... "); +runpdfTeX("$path$name",$name); +LOG ("all finished ... :-)"); +# create a preamble file +# if we have a \input command inside the preamble, it doesn't hurt, we need +# it anyway for the postscript files and the pdf one. +# ----------------- Save Preamble ---------------------------------------- +sub savePreamble { +my $filename = pop; # get the file name + LOG ("----- Start Preamble -----"); +open my $FILEp,'>',"$tempDir/$filename.preamble"; +open my $FILE, '<', "$name.tex"; + while (<$FILE>) { # read all until \begin{document} + my $i = index($_,"begin{document}"); + if ($i > 0) { + if ($i > 1) { print $FILEp substr($_,0,--$i); } # write all until \begin{document} + if ($single) { + print $FILEp "\\newenvironment{postscript}{}{}\n"; + print $FILEp "\\pagestyle{empty}\n"; + } +close $FILEp; # close preamble + LOG ("----- Close Preamble ------"); + return; + } +else { + print $FILEp "$_"; # write into preamble + LOG ("$_"); + } +} +close $FILE; +close $FILEp; + if ( $verbose ) { LOG("<-----Preamble<----"); } + 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 + open my $FILE, '<', "$name.tex"; + while (<$FILE>) { # scan the input file + if (!$EndDocument) { + chomp; # delete EOL character + my $line = $_; # save line + if ( !$iVerb ) { + $iVerb = ((index($line,"begin{verbatim}") > 0) + or (index($line,"begin{lstlisting}") > 0) + or (index($line,"begin{Verbatim}") > 0) + or (index($line,"begin{verbatim*}") > 0)); + } # do nothing until \end{verbatim} + if ( !$iVerb ) { + my $iPS = index($line,"begin{postscript}"); + 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 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 + LOG("PS-Zeile: $line"); + } + elsif ( $iPST > 0 ) { # we have \begin{pspicture} or \pspicture + $type = 1; + $depth++; + $line = substr($line,$iPST-1);# add all unitl pspicture + LOG("PST-Zeile: $line"); + } + } +# we have now \begin{pspicture} or \begin{postscript} + if ($type > 0) { # start Scan, we have an environment + LOG ("searchPS: set \$type=$type"); + $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 + 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 + LOG ("---->PS---->\n@PS\n<----PS<----"); + @PS = (); # start new PS sequence + } # no pspicture env left + } else { push @PS,$line; } # pspicture inside postscript + } elsif ($iPS > 0) { # must be type=1 -> stop Scan + LOG ("searchPS: $line"); + $type = -1; + push @PS,substr($line,0,$iPS+15); # add line + LOG ("searchPS: set \$type=$type"); + push @PStotal,[@PS]; # add PS sequence + LOG ("---->PS---->\n@PS\n<----PS<----"); + @PS =(); # start new PS sequence + } else { push @PS,$line; } # add line + } + my $i = index($line,"end{document}"); + if ($i > 0) { $EndDocument++; LOG("EndDocument in searchPS"); } + } # if ( $iVerb ) + if (( index($line,"end{verbatim}") > 0 ) + or ( index($line,"end{lstlisting}") > 0 ) + or ( index($line,"end{Verbatim}") > 0 ) + or ( index($line,"end{verbatim*}") > 0 )) { $iVerb = 0; } + }} + if ( $verbose ) { + LOG("---->PStotal---->"); + for my $aref ( @PStotal ) { + my @a = @$aref; + my $i = 1; + foreach ( @a ) { LOG ($a[$i]); $i=$i+1; } + } + LOG ("<----PStotal<----"); + } + close $FILE; + return @PStotal; # return all PS sequences +} +# Creating ifile.tex and eps, pdf and ppm for images +if ($single){ +sub runsingle{ + my $filename = pop; + if ($xetex){ + system("xelatex -interaction=batchmode $tempDir/$filename-fig"); + system("pdfcrop -xetex $tempDir/$filename-fig.pdf $imageDir/$filename-fig-$imgNo.pdf");} + else{ + system("latex -interaction=batchmode $tempDir/$filename-fig"); + system("dvips $tempDir/$filename-fig"); + system("ps2pdf -dProcessColorModel=/DeviceCMYK -dPDFSETTINGS=/prepress $tempDir/$filename-fig.ps"); + system("pdfcrop $tempDir/$filename-fig.pdf $imageDir/$filename-fig-$imgNo.pdf");} + if ($files){ + copy("$filename-fig.tex", "$imageDir/$filename-fig-$imgNo.tex");} + system("pdfcrop $tempDir/$filename-fig.pdf $imageDir/$filename-fig-$imgNo.pdf"); + if ($eps) { + system("pdftops -level3 -eps $imageDir/$filename-fig-$imgNo.pdf $imageDir/$filename-fig-$imgNo.eps");} + if ($ppm) { + system("pdftoppm -r $DPI $imageDir/$filename-fig-$imgNo.pdf $imageDir/$filename-fig-$imgNo");} + $imgNo=$imgNo+1; + } +} +else{ +#----------------- Creating files.tex and .eps for images -------------- +sub runTeX{ + my $filename = pop; + if ($eps){ + system("pdftops -level3 -eps $imageDir/$filename-$imgNo.pdf $imageDir/$filename-$imgNo.eps"); + } + if ($files){ + copy("$filename.tex", "$imageDir/$filename-$imgNo.tex"); +} + $imgNo=$imgNo+1; +} +} +sub runFile { + my $filename = pop; + my @PSarray = searchPS(); + if ( $verbose ) { + LOG("---->PSarray---->"); + for my $aref ( @PSarray ) { + my @a = @$aref; + my $i = 1; + foreach ( @a ) { print LOG $a[$i]."\n"; $i=$i+1; } + } + LOG("<----PSarray<----"); + my $no = @PSarray; + LOG("PS: ".$no." PS sequence(s)"); + } + for my $aref ( @PSarray ) { + my @PS = @$aref; + open my $FILEp,'<',"$tempDir/$filename.preamble"; + open my $FILEsub,'>',"$tempDir/$filename-fig.tex"; + while (<$FILEp>) {print $FILEsub $_; } + print $FILEsub "\\begin{document}\n"; + if ( $verbose ) { LOG("\@PS: $_"); } + foreach ( @PS ) { print $FILEsub "$_\n"; } + print $FILEsub "\\end{document}"; + close $FILEsub; + close $FILEp; + if ($single) { + runsingle("$name"); + } + else{ + runTeX("$tempDir/$name-fig"); + } +} +} +# ----------------Renaming ppm need for correct name +if(!$noImages){ + my $dren = "$tempDir/$imageDir"; + my $fichero = ''; + my $ppmren = ''; + my $renNo = 1; + if(opendir(DIR,$dren)){ + foreach (readdir DIR){ + $fichero = $_; + if ( $fichero =~ /($name-fig-)(\d+|\d+[-]\d+).ppm/) { + my $renNo = int($2); + my $newname="$1$renNo.ppm"; + $ppmren = rename("$dren/$fichero","$dren/$newname"); + } + } +} +closedir DIR; +}# end renaming +#--------------------------- Replace files---------------------- +sub runpdfTeX() { + my ($name,$pdfname) = @_; + open my $PDF,'>',"$tempDir/$pdfname-pdf.tex"; + open my $FILE,'<',"$name.tex"; + my $ignore = 0; + my $IMGno = 1; + my $depth = -1; + my $type = -1; + my $EndDocument = 0; # ignore all after \end{document} + my $iVerb = 0; + while (<$FILE>) { # scan the input file + if ( !$iVerb ) { + $iVerb = ((index($_,"begin{verbatim}") > 0) + or (index($_,"begin{lstlisting}") > 0) + or (index($_,"begin{Verbatim}") > 0) + or (index($_,"begin{verbatim*}") > 0)); + } # do nothing until \end{verbatim}|| \end{lstlisting} + if ( !$iVerb ) { + my $i = index($_,"end{document}"); + if ($i > 0) { print $PDF $_; $EndDocument++; LOG("EndDocument in runpdfTeX"); } + if ( !$EndDocument ) { + my $iPS = index($_,"begin{postscript}"); + if ( $iPS > 0 ) { + $type = 2; + $ignore = 1; + if ($iPS > 1) { print $PDF substr($_,0,--$iPS); } # add preceeding text + print $PDF "\\includegraphics[scale=$Iscale]{$pdfname-fig-$IMGno}"; # use pdfname + $IMGno=$IMGno+1; + } # postscript env + if ( $type < 2 ) { + my $iPST = index($_,"begin{pspicture*}"); + if ($iPST < 0) { $iPST = index($_,"begin{pspicture}"); } # alternative ... + if ($iPST < 0) { $iPST = index($_,"\\pspicture"); } # alternative \\pspicture... + if ( $iPST >= 0 ) { # start Scan + $ignore = 1; + $type = 1; + $depth++; # pspicture env + LOG("Increase depth: $depth"); + if ( $depth == 0 ) { + if ($iPST > 1) { print $PDF substr($_,0,--$iPST); } # add preceeding text + print $PDF "\\includegraphics[scale=$Iscale]{$pdfname-fig-$IMGno}"; # use \graphicspath + $IMGno=$IMGno+1; + LOG("Increase Image counter: $IMGno"); + } + } + } + if ( !$ignore ) { print $PDF "$_"; } # default line + if ( $type == 2 ) { # postscript env + my $iPS = index($_,"end{postscript}"); + 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*}"); + 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 + 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; } + } + } + } # if ( !$EndDocument ) + } + else { print $PDF $_; } # if ( $iVerb ) + if (( index($_,"end{verbatim}") > 0 ) + or ( index($_,"end{lstlisting}") > 0 ) + or ( index($_,"end{Verbatim}") > 0 ) + or ( index($_,"end{verbatim*}") > 0 )) { $iVerb = 0; } + } # while (<$FILE>) + close $FILE; + close $PDF; +#------------------- Coment pst-package for pdfLaTeX -------------------- + open my $IPDF,'<', "$tempDir/$pdfname-pdf.tex"; + undef $/; # read all file + my ($uno,$dos) = split(/\\begin\{document\}/,<$IPDF>,2); + close $IPDF; + + my @coment = split /\n/, $uno; # split in two + my @preamb; + + foreach my $line (@coment) { + chomp($line); + if(!$xetex){ + $line =~ s/\\usepackage(?:\[.+?\])?\{pst.+?}//g; # delete + $line =~ s/\\usepackage(?:\[.+?\])?\{psfr.+?}//g; # delete + $line =~ s/(\\usepackage(?:\[.+?\])?)\{auto-pst.+?}//g; # delete + $line =~ s/(\\usepackage(?:\[.+?\])?)\{vaucanson-.+?}//g; # delete + $line =~ s/(\\usepackage(?:\[.+?\])?)\{psgo}//g; # delete + } + $line =~ s/(\\usepackage(?:\[.+?\])?)\{graph/\%$1\{graph/g; # comment + next if $line =~ m/^\s*$/; + push(@preamb,$line);} # adding changes + +my $clean = join("\n", @preamb, "\\usepackage{grfext}\n\\\PrependGraphicsExtensions*{$Iext}\n\\usepackage{graphicx}\n\\graphicspath{{$imageDir/}}\n\\begin{document}". $dos); + + open my $OPDF,'>',"$tempDir/$pdfname-pdf.tex"; # write changes + print $OPDF $clean; + close $OPDF; +# ------------------------- close coment pst-package ------------------------------ +my $runAgain = 0; + if ($norun){print "Done\n";} + else { + if($xetex){ + system("xelatex -interaction=batchmode $tempDir/$pdfname-pdf"); print "Done\n";} + else{ + system("pdflatex -interaction=batchmode $tempDir/$pdfname-pdf"); print "Done\n";} + } + if (-e "$tempDir/$pdfname-pdf.idx") { + system("makeindex $tempDir/$pdfname-pdf.idx"); $runAgain++;} + if ($runBibTeX && -e "$tempDir/$pdfname-pdf.aux") { + system("bibtex $tempDir/$pdfname-pdf"); $runAgain++; } + if ($runBiber && -e "$tempDir/$pdfname-pdf.bcf") { + system("biber $tempDir/$pdfname-pdf"); $runAgain++; } + if ($runAgain){ + if($xetex){ + system("xelatex -interaction=batchmode $tempDir/$pdfname-pdf");} + else{ + system("pdflatex -interaction=batchmode $tempDir/$pdfname-pdf");} + } + if ($ppm){ + print "If you need to create jpg/png/svg type cd $imageDir and run\n"; + print "mogrify -format [ext] *.ppm\n"; + } + if ($clear) { + if ($norun){} + if ($single) { + unlink "$tempDir/$name-fig.pdf"; + if(!$xetex){ + unlink "$tempDir/$name-fig.dvi"; + unlink "$tempDir/$name-fig.ps"; + } + unlink "$tempDir/$name-fig.aux"; + unlink "$tempDir/$name-fig.log"; + unlink "$tempDir/$name-fig.tex"; + if(!$verbose) { + unlink "$tempDir/$name.plog"; + } + unlink "$tempDir/$name.preamble"; + unlink "$tempDir/$name-pdf.aux"; + unlink "$tempDir/$name-pdf.log"; + } + else{ + if(!$verbose) { + unlink "$tempDir/$name.plog"; + } + unlink "$tempDir/$name.preamble"; + unlink "$tempDir/$name-pdf.aux"; + unlink "$tempDir/$name-pdf.log"; + unlink "$tempDir/$name-pics.pdf"; + unlink "$tempDir/$name-pics.tex"; + unlink "$tempDir/$name-pics.aux"; + if(!$xetex){ + unlink "$tempDir/$name-pics.dvi"; + unlink "$tempDir/$name-pics.ps";} + unlink "$tempDir/$name-pics.log"; + unlink "$tempDir/$name-fig.tex"; + } + } + } + +sub LOG() { + if ( $verbose ) { print $LOGfile "@_\n"; } + } +__END__ diff --git a/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl b/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl index dfcf2a0e483..51580081030 100755 --- a/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl +++ b/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl @@ -1,12 +1,12 @@ #!/usr/bin/env perl -# $Id: tlmgr.pl 28995 2013-01-31 00:45:52Z preining $ +# $Id: tlmgr.pl 29313 2013-03-08 13:24:40Z preining $ # -# Copyright 2008, 2009, 2010, 2011, 2012 Norbert Preining +# Copyright 2008-2013 Norbert Preining # This file is licensed under the GNU General Public License version 2 # or any later version. -my $svnrev = '$Revision: 28995 $'; -my $datrev = '$Date: 2013-01-31 01:45:52 +0100 (Thu, 31 Jan 2013) $'; +my $svnrev = '$Revision: 29313 $'; +my $datrev = '$Date: 2013-03-08 14:24:40 +0100 (Fri, 08 Mar 2013) $'; my $tlmgrrevision; my $prg; if ($svnrev =~ m/: ([0-9]+) /) { @@ -24,6 +24,7 @@ our $loadmediasrcerror; our $packagelogfile; our $packagelogged; our $tlmgr_config_file; +our $pinfile; BEGIN { $^W = 1; @@ -161,6 +162,7 @@ sub main { "dry-run|n" => 1 }, "paper" => { "list" => 1 }, "path" => { "w32mode" => "=s" }, + "pinning" => { "all" => 1 }, "platform" => { "dry-run|n" => 1 }, "postaction" => { "w32mode" => "=s", "all" => 1, @@ -3510,7 +3512,76 @@ sub show_list_of_packages { # tlmgr pinning remove [, ...] # tlmgr pinning remove --all sub action_pinning { - tlwarn("Not implemented by now, sorry!\n"); + my $what = shift @ARGV; + $what || ($what = 'show'); + init_local_db(); + init_tlmedia_or_die(); + if (!$remotetlpdb->is_virtual) { + tlwarn("tlmgr: not a virtual database, no pinning actions supported!\n"); + return; + } + my $pinref = $remotetlpdb->virtual_pindata(); + my $pf = $remotetlpdb->virtual_pinning(); + my @pins = @$pinref; + if ($what =~ m/^show$/i) { + print "Defined pinning data:\n"; + for my $p (@pins) { + print " ", $p->{'repo'}, ":", $p->{'glob'}, "\n"; + } + } elsif ($what =~ m/^check$/i) { + tlwarn("Not implemented by now, sorry!\n"); + return 0; + } elsif ($what =~ m/^add$/i) { + # we need at least two more arguments + if ($#ARGV < 1) { + tlwarn("missing arguments to pinning add\n"); + return; + } + my $repo = shift @ARGV; + my @ov = $pf->value($repo); + push @ov, @ARGV; + $pf->value($repo, @ov); + $remotetlpdb->virtual_update_pins(); + $pf->save; + info("Added/Updated pinning data for $repo\n"); + return 1; + } elsif ($what =~ m/^remove$/i) { + my $repo = shift @ARGV; + if (!defined($repo)) { + tlwarn("missing arguments to pinning add\n"); + return; + } + my $pf = $remotetlpdb->virtual_pinning(); + if ($opts{'all'}) { + if ($#ARGV >= 0) { + tlwarn("no additional argument allowed when --all is given\n"); + return; + } + $pf->delete_key($repo); + $remotetlpdb->virtual_update_pins(); + $pf->save; + return; + } + # complicated case, we want to remove only one setting + my @ov = $pf->value($repo); + my @nv; + for my $pf (@ov) { + push @nv, $pf if (!member($pf, @ARGV)); + } + $pf->value($repo, @nv); + $remotetlpdb->virtual_update_pins(); + $pf->save; + info("Removed pinning data for $repo\n"); + return 1; + } else { + tlwarn("Unknown argument to pinning action: $what\n"); + return 0; + } + # $pin{'repo'} = $repo; + # $pin{'glob'} = $glob; + # $pin{'re'} = $re; + # $pin{'line'} = $line; # for debug/warning purpose + return 0; } # REPOSITORY @@ -5185,24 +5256,19 @@ sub init_tlmedia # now check/setup pinning # TODO for now no default pinning file! - if ($opts{"pin-file"}) { - my @pins = read_pinning_file($opts{"pin-file"}); - if (@pins) { - $remotetlpdb->virtual_pinning(@pins); - } - } else { + if (!$opts{"pin-file"}) { # check for pinning file in TEXMFLOCAL/tlpkg/pinning.txt chomp (my $TEXMFLOCAL = `kpsewhich -var-value=TEXMFLOCAL`); debug("trying to load pinning file $TEXMFLOCAL/tlpkg/pinning.txt\n"); if (-r "$TEXMFLOCAL/tlpkg/pinning.txt") { - my @pins = read_pinning_file("$TEXMFLOCAL/tlpkg/pinning.txt"); - if (@pins) { - info("tlmgr: using pinning file $TEXMFLOCAL/tlpkg/pinning.txt\n"); - $remotetlpdb->virtual_pinning(@pins); - } + $opts{"pin-file"} = "$TEXMFLOCAL/tlpkg/pinning.txt"; } } - + if ($opts{"pin-file"} && -r $opts{"pin-file"}) { + # $pinfile is global var + $pinfile = TeXLive::TLConfFile->new($opts{"pin-file"}, "#", ":", 'multiple'); + $remotetlpdb->virtual_pinning($pinfile); + } # this "location-url" line should not be changed since GUI programs # depend on it: print "location-url\t$locstr\n" if $::machinereadable; @@ -5419,26 +5485,6 @@ FROZEN return($remotetlpdb); } -sub read_pinning_file { - my $pf = shift; - my @pins; - my $pfh; - if (!open($pfh, "<$pf")) { - tlwarn("Pinning file $pf cannot be read: $!\n"); - return; - } - debug("Reading pinning file $pf\n"); - while (my $l = TeXLive::TLUtils::get_full_line($pfh)) { - chomp($l); - # comments and empty lines are allowed - next if ($l =~ m/^\s*#/); - next if ($l =~ m/^\s*$/); - my ($a, $b) = split(/:/, $l); - push @pins, $remotetlpdb->make_pin_data_from_line($l); - } - close($pfh); - return @pins; -} # finish handles the -pause option (wait for input from stdin), @@ -5878,420 +5924,392 @@ Gives version information (same as C<--version>). If C<-v> has been given the revisions of the used modules are reported, too. -=head2 gui - -Start the graphical user interface. See B below. +=head2 backup [--clean[=I]] [--backupdir I] [--all | I]... +If the C<--clean> option is not specified, this action makes a backup of +the given packages, or all packages given C<--all>. These backups are +saved to the value of the C<--backupdir> option, if that is an existing and +writable directory. If C<--backupdir> is not given, the C +option setting in the TLPDB is used, if present. If both are missing, +no backups are made. -=head2 install [I