From dfbdba4c53651477b0d82164c0126e0f41f8bdb1 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 25 Aug 2020 03:02:50 +0000 Subject: CTAN sync 202008250302 --- graphics/pstricks/scripts/pst2pdf/Changes | 5 +- graphics/pstricks/scripts/pst2pdf/doc/Makefile | 47 ++++ .../pstricks/scripts/pst2pdf/doc/pst2pdf-doc.bib | 40 +-- .../pstricks/scripts/pst2pdf/doc/pst2pdf-doc.pdf | Bin 154083 -> 132936 bytes .../pstricks/scripts/pst2pdf/doc/pst2pdf-doc.tex | 14 +- .../pstricks/scripts/pst2pdf/doc/test1-pdf.pdf | Bin 136593 -> 136602 bytes .../pstricks/scripts/pst2pdf/doc/test2-pdf.pdf | Bin 108349 -> 108348 bytes .../pstricks/scripts/pst2pdf/doc/test3-pdf.pdf | Bin 62819 -> 62821 bytes .../pstricks/scripts/pst2pdf/script/pst2pdf.pl | 282 +++++++++++---------- 9 files changed, 229 insertions(+), 159 deletions(-) create mode 100644 graphics/pstricks/scripts/pst2pdf/doc/Makefile (limited to 'graphics/pstricks/scripts') diff --git a/graphics/pstricks/scripts/pst2pdf/Changes b/graphics/pstricks/scripts/pst2pdf/Changes index ad60992278..95ee0eea16 100644 --- a/graphics/pstricks/scripts/pst2pdf/Changes +++ b/graphics/pstricks/scripts/pst2pdf/Changes @@ -1,5 +1,8 @@ pst2pdf.pl -------- -0.19 2020-08-08 - Add new options to CLI +0.20 2020-08-24 - Fix graphicx detection + - Fix typo in documentation + - Remove unused vars +0.19 2020-08-17 - Add new options to CLI - Remove deprecate code - Rewrite documentation - Remove unused options diff --git a/graphics/pstricks/scripts/pst2pdf/doc/Makefile b/graphics/pstricks/scripts/pst2pdf/doc/Makefile new file mode 100644 index 0000000000..852c7ab5e5 --- /dev/null +++ b/graphics/pstricks/scripts/pst2pdf/doc/Makefile @@ -0,0 +1,47 @@ +# `Makefile' for `pst2pdf.pdf', hv, 2017/08/11 + +.SUFFIXES : .tex .ltx .dvi .ps .pdf .eps + +PACKAGE = pst2pdf + +MAIN = $(PACKAGE)-doc + +LATEX = xelatex + +ARCHNAME = $(MAIN)-$(shell date +%y%m%d) + +ARCHFILES = $(PACKAGE).sty $(PACKAGE).tex $(PACKAGE).pro $(MAIN).tex README Changes Makefile + +TDS = ~/PSTricks/PSTricks-TDS + +all : doc clean + +doc: + $(LATEX) --shell-escape $(MAIN) + biber $(MAIN) + $(LATEX) --shell-escape $(MAIN) + $(LATEX) --shell-escape $(MAIN) + +clean : + $(RM) $(addprefix $(MAIN), .log .aux .glg .glo .gls .ilg .idx .ind .tmp .toc .out ) + $(RM) $(addprefix $(MAIN), .dvi .ps .bbl .bcf .blg .run.xml) + +veryclean : clean + $(RM) $(addprefix $(MAIN), .pdf .bbl .blg) + +arch : + zip $(ARCHNAME).zip $(ARCHFILES) + +#tds: +# cp -u Changes $(TDS)/scripts/$(PACKAGE)/ +# cp -u README $(TDS)/scripts/$(PACKAGE)/ +# cp -u doc/$(MAIN).pdf $(TDS)/scripts/$(PACKAGE)/ +# cp -u doc/$(MAIN).tex $(TDS)/scripts/$(PACKAGE)/ +# cp -u doc/$(MAIN).bib $(TDS)/scripts/$(PACKAGE)/ +# cp -u Makefile $(TDS)/scripts/$(PACKAGE)/ +# cp -u doc/test?.tex $(TDS)/scripts/$(PACKAGE)/ +# cp -u doc/test?-pdf.pdf $(TDS)/scripts/$(PACKAGE)/ +# cp -u script/pst2pdf.pl $(TDS)/scripts/$(PACKAGE)/ + + +# EOF diff --git a/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.bib b/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.bib index 49d7274d35..81ec2771ce 100644 --- a/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.bib +++ b/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.bib @@ -43,10 +43,10 @@ pages = {239-246} } -@Manual{pstricks, +@online{pstricks, Title = {PSTricks - {\PS} macros for generic {\TeX}}, Author = {{Timothy van} Zandt}, - Address = {\url{http://www.tug.org/application/PSTricks}}, + url = {http://www.tug.org/application/PSTricks}, year = 1993 } @@ -75,75 +75,75 @@ address = {Cambridge} } -@Manual{pst-tools, +@online{pst-tools, author = {Herbert Voß}, title = {\texttt{pst-tools} -- Helper functions}, publisher = {CTAN}, year = {2012}, - address = {\url{CTAN:/graphics/pstricks/contrib/pst-tools}} + url = {https://www.ctan.org/pkg/pst-tools} } -@Manual{preview, +@online{preview, author = {David Kastrup}, title = {The \texttt{preview} package for \hologo{LaTeX}}, publisher = {CTAN}, year = {2017}, - address = {\url{https://www.ctan.org/pkg/preview}} + url = {https://www.ctan.org/pkg/preview} } -@Manual{pst-pdf, +@online{pst-pdf, author = {Rolf Niepraschk}, title = {The \texttt{pst-pdf} package}, publisher = {CTAN}, year = {2019}, - address = {\url{https://www.ctan.org/pkg/pst-pdf}} + url = {https://www.ctan.org/pkg/pst-pdf} } -@Manual{auto-pst-pdf, +@online{auto-pst-pdf, author = {Will Robertson}, title = {The \texttt{auto-pst-pdf} package}, publisher = {CTAN}, year = {2009}, - address = {\url{https://www.ctan.org/pkg/auto-pst-pdf}} + url = {https://www.ctan.org/pkg/auto-pst-pdf} } -@Manual{auto-pst-pdf-lua, +@online{auto-pst-pdf-lua, author = {Herbert Voß}, title = {The \texttt{auto-pst-pdf-lua} package - Using \hologo{LuaLaTeX} with \texttt{PSTricks}}, publisher = {CTAN}, year = {2018}, - address = {\url{https://www.ctan.org/pkg/auto-pst-pdf-lua}} + url = {https://www.ctan.org/pkg/auto-pst-pdf-lua} } -@Manual{pst-exa, +@online{pst-exa, author = {Herbert Voß}, title = {\texttt{pst-exa} - Typeset \texttt{PSTricks} examples, with \hologo{pdfTeX}}, publisher = {CTAN}, year = {2017}, - address = {\url{https://www.ctan.org/pkg/pst-exa}} + url = {https://www.ctan.org/pkg/pst-exa} } -@Manual{graphicx, +@online{graphicx, author = {The \hologo{LaTeX3} Project}, title = {\texttt{graphics} - Enhanced support for graphics}, publisher = {CTAN}, year = {2017}, - address = {\url{https://www.ctan.org/pkg/graphicx}} + url = {https://www.ctan.org/pkg/graphicx} } -@Manual{grfext, +@online{grfext, author = {Heiko Oberdiek}, title = {The \texttt{grfext} package}, publisher = {CTAN}, year = {2017}, - address = {\url{https://www.ctan.org/pkg/grfext}} + url = {https://www.ctan.org/pkg/grfext} } -@Manual{pst-plot, +@online{pst-plot, author = {{Timothy van} Zandt and Herbert Voß}, title = {\texttt{pst-plot} - Plot data using \texttt{PSTricks}}, publisher = {CTAN}, year = {2019}, - address = {\url{https://www.ctan.org/pkg/pst-plot}} + url = {https://www.ctan.org/pkg/pst-plot} } diff --git a/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.pdf b/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.pdf index ea2ceb21c4..4c12fc0f45 100644 Binary files a/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.pdf and b/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.pdf differ diff --git a/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.tex b/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.tex index ab85cde896..b1df6bb901 100644 --- a/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.tex +++ b/graphics/pstricks/scripts/pst2pdf/doc/pst2pdf-doc.tex @@ -38,8 +38,8 @@ % Identification \def\myscript{pst2pdf} -\def\fileversion{0.19} -\def\filedate{2020-08-17} +\def\fileversion{0.20} +\def\filedate{2020-08-22} % Config hyperref \hypersetup{ @@ -327,7 +327,7 @@ keywords=[8]{graphicx,grfext,article,document,preview,libertinus,pst-pdf},% % Important words 9, files used in examples keywordstyle=[10]{\color{OrangeRed}},% - keywords=[10]{test-fig-all.pdf,test-fig-1981.tex,test-fig-1981.pdf, test-fig-1,test-fig-2,test-out,test-in.ltx,% + keywords=[10]{test.ltx,test-fig-all.pdf,test-fig-1981.tex,test-fig-1981.pdf, test-fig-1,test-fig-2,test-out,test-in.ltx,% test-fig-1981.tex,test-out.tex,file-in.tex,file-out,test.tex,test-fig-all.dvi,test-fig-1.svg,test-fig-all.tex},% }[keywords,tex,comments,strings]% end languaje @@ -551,7 +551,8 @@ parts and then processing them: If for some reason you have an environment \Lenv{filecontens} before \lstinline|\documentclass| or in the preamble of the \meta{input file} that contains a \emph{sub-document} or \emph{environment} -you want to extract, the script will ignore them. +you want to extract, the script will ignore them. Similarly, the content after \lstinline|\end{document}| +is ignored in the extraction process. \subsection{Verbatim contents} \label{sec:verbatim} @@ -858,12 +859,9 @@ Now move \LFile{test-fig-1981.pdf} to \texttt{/tmp/hG45uVklv9} and rename to \LF and \LFile{test-fig-2.pdf} and copy to \texttt{./images}, if the image files exist, they will be rewritten each time you run the script. The file \LFile{test-fig-1981.tex} is moved to the \texttt{./images} and rename to \LFile{test-fig-all.tex}. - - - Note the options passed to \meta[type=tt,cf=ForestGreen,ac=lightgray]{compiler} always use \prgopt*{no-shell-escape} and \prgopt*{recorder}, to generate the \Lext{fls} file which is used to delete temporary files and directories after -the process is completed and. The \cmdopt{shell} option activates \prgopt*{shell-escape} for compatibility with packages +the process is completed. The \cmdopt{shell} option activates \prgopt*{shell-escape} for compatibility with packages such as \LPack{minted} or others. \subsubsection{Create output file} diff --git a/graphics/pstricks/scripts/pst2pdf/doc/test1-pdf.pdf b/graphics/pstricks/scripts/pst2pdf/doc/test1-pdf.pdf index 9766af2cb7..e8bc6d3ef4 100644 Binary files a/graphics/pstricks/scripts/pst2pdf/doc/test1-pdf.pdf and b/graphics/pstricks/scripts/pst2pdf/doc/test1-pdf.pdf differ diff --git a/graphics/pstricks/scripts/pst2pdf/doc/test2-pdf.pdf b/graphics/pstricks/scripts/pst2pdf/doc/test2-pdf.pdf index a1dedfef29..93a0b12ae6 100644 Binary files a/graphics/pstricks/scripts/pst2pdf/doc/test2-pdf.pdf and b/graphics/pstricks/scripts/pst2pdf/doc/test2-pdf.pdf differ diff --git a/graphics/pstricks/scripts/pst2pdf/doc/test3-pdf.pdf b/graphics/pstricks/scripts/pst2pdf/doc/test3-pdf.pdf index 99f28c3025..ac794dad4f 100644 Binary files a/graphics/pstricks/scripts/pst2pdf/doc/test3-pdf.pdf and b/graphics/pstricks/scripts/pst2pdf/doc/test3-pdf.pdf differ diff --git a/graphics/pstricks/scripts/pst2pdf/script/pst2pdf.pl b/graphics/pstricks/scripts/pst2pdf/script/pst2pdf.pl index 3b33bdbf91..a0cf34c638 100644 --- a/graphics/pstricks/scripts/pst2pdf/script/pst2pdf.pl +++ b/graphics/pstricks/scripts/pst2pdf/script/pst2pdf.pl @@ -2,8 +2,7 @@ use v5.26; ############################# LICENCE ################################## -# $Id: pst2pdf.pl 119 2014-09-24 12:04:09Z herbert $ # -# v0.19 2020-08-16 simplify the use of PSTricks with pdf # +# v0.20 2020-08-24 simplify the use of PSTricks with pdf # # (c) Herbert Voss # # Pablo González L # # # @@ -51,7 +50,6 @@ my $norun = 0; # 1->no create images my $noprew = 0; # 1->create images in nopreview mode my $runbibtex = 0; # 1->runs bibtex my $runbiber = 0; # 1->runs biber and sets $runbibtex=0 -my $all = 0; # 1->create all images and files for type my $xetex = 0; # 1->Using (Xe)LaTeX for compilation. my $luatex = 0; # 1->Using dvilualatex for compilation. my $latexmk = 0; # 1->Using latexmk for compiler output file. @@ -81,9 +79,9 @@ my %opts_cmd; # hash to store options for Getopt::Long and log ### Script identification my $scriptname = 'pst2pdf'; -my $nv = 'v0.19'; -my $date = '2020-08-17'; -my $ident = '$Id: pst2pdf.pl 119 2020-08-16 12:04:09Z herbert $'; +my $nv = 'v0.20'; +my $date = '2020-08-22'; +my $ident = '$Id: pst2pdf.pl 119 2020-08-22 12:04:09Z herbert $'; ### Log vars my $LogFile = "$scriptname.log"; @@ -347,7 +345,7 @@ my $result=GetOptions ( 'imgdir=s' => \$imgdir, # string 'myverb=s' => \$myverb, # string 'ignore=s' => \$tmpverbenv, # string - 'c|clear' => \$clear, # flag + 'c|clear' => \$clear, # flag (unused) 'ni|norun|noimages' => \$norun, # flag 'np|noprew|single' => \$noprew, # flag 'bibtex' => \$runbibtex,# flag @@ -368,7 +366,6 @@ my $result=GetOptions ( 's|svg' => \$opts_cmd{image}{svg}, # pdftocairo 'e|eps' => \$opts_cmd{image}{eps}, # pdftops 'P|ppm' => \$opts_cmd{image}{ppm}, # pdftoppm - 'a|all' => \$all, # flag 'x|xetex' => \$xetex, # flag 'luatex' => \$luatex, # flag 'ns|nosource' => \$nosource, # flag @@ -1153,14 +1150,15 @@ if (@env_preview) { ### Pass verbatim write environments to dtxtag Log("Pass verbatim write environments to %<*$dtxverb> ... %"); -$document =~ s/\\begin\{nopreview\}.+?\\end\{nopreview\}(*SKIP)(*F)| - ($verb_wrt)/\%<\*$dtxverb>$1\%<\/$dtxverb>/gmsx; +$document =~ s/\\begin\{nopreview\}.+?\\end\{nopreview\}(*SKIP)(*F)| + ($verb_wrt)/\%<\*$dtxverb>$1\%<\/$dtxverb>/gmsx; +$atbegindoc =~ s/($verb_wrt)/\%<\*$dtxverb>$1\%<\/$dtxverb>/gmsx; ### Pass verbatim environments to dtxtag Log("Pass verbatim environments to %<*$dtxverb> ... %"); -$document =~ s/\\begin\{nopreview\}.+?\\end\{nopreview\}(*SKIP)(*F)| - \%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| - ($verb_std)/\%<\*$dtxverb>$1\%<\/$dtxverb>/gmsx; +$document =~ s/\\begin\{nopreview\}.+?\\end\{nopreview\}(*SKIP)(*F)| + \%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| + ($verb_std)/\%<\*$dtxverb>$1\%<\/$dtxverb>/gmsx; ### Pass %CleanPST to dtxtag Log("Pass %CleanPST ... %CleanPST to %<*remove$tmp> ... %"); @@ -1409,9 +1407,7 @@ if (!$norun) { } ### Set -q for system command line (gs, poppler-utils, dvips) -my $quiet = $verbose ? q{} - : '-q' - ; +my $quiet = $verbose ? q{} : '-q'; ### Set options for ghostscript my %opt_gs_dev = ( @@ -1590,6 +1586,7 @@ $preamout =~ s/^\\usepackage\{\}(?:[\t ]*(?:\r?\n|\r))+/\n/gmsx; ### Remove %<*$dtxverb> ... % in tmpbodydoc and preamout $tmpbodydoc =~ s/\%<\*$dtxverb>(.+?)\%<\/$dtxverb>/$1/gmsx; $preamout =~ s/\%<\*$dtxverb>(.+?)\%<\/$dtxverb>/$1/gmsx; +$atbeginout =~ s/\%<\*$dtxverb>(.+?)\%<\/$dtxverb>/$1/gmsx; ### Adjust nopreview environments $tmpbodydoc =~ s/\\begin\{nopreview\}\%$tmp @@ -1848,45 +1845,6 @@ if (!$norun) { ### Constant my $findgraphicx = 'true'; -### Suport for pst-exa package -my $pstexa = qr/(?:\\ usepackage) \[\s*(.+?)\s*\] (?:\{\s*(pst-exa)\s*\} ) /x; -my @pst_exa; -my %pst_exa; - -### Possible packages that load graphicx -my @pkgcandidates = qw ( - rotating epsfig lyluatex xunicode parsa xepersian-hm gregoriotex teixmlslides - teixml fotex hvfloat pgfplots grfpaste gmbase hep-paper postage schulealt - schule utfsym cachepic abc doclicense rotating epsfig semtrans mgltex - graphviz revquantum mpostinl cmpj cmpj2 cmpj3 chemschemex register papercdcase - flipbook wallpaper asyprocess draftwatermark rutitlepage dccpaper-base - nbwp-manual mandi fmp toptesi isorot pinlabel cmll graphicx-psmin ptmxcomp - countriesofeurope iodhbwm-templates fgruler combinedgraphics pax pdfpagediff - psfragx epsdice perfectcut upmethodology-fmt ftc-notebook tabvar vtable - teubner pas-cv gcard table-fct pdfpages keyfloat pdfscreen showexpl simplecd - ifmslide grffile reflectgraphics markdown bclogo tikz-page pst-uml realboxes - musikui csbulobalka lwarp mathtools sympytex mpgraphics miniplot.sty:77 - dottex pdftricks2 feupphdteses tex4ebook axodraw2 hagenberg-thesis dlfltxb - hu-berlin-bundle draftfigure quicktype endofproofwd euflag othelloboard - pdftricks unswcover breqn pdfswitch latex-make figlatex repltext etsvthor - cyber xcookybooky xfrac mercatormap chs-physics-report tikzscale ditaa - pst-poker gmp CJKvert asypictureb hletter tikz-network powerdot-fuberlin - skeyval gnuplottex plantslabels fancytooltips ieeepes pst-vectorian - phfnote overpic xtuformat stubs graphbox ucs pdfwin metalogo mwe - inline-images asymptote UNAMThesis authorarchive amscdx pst-pdf adjustbox - trimclip fixmetodonotes incgraph scanpages pst-layout alertmessage - svg quiz2socrative realhats autopdf egplot decorule figsize tikzexternal - pgfcore frontespizio textglos graphicx tikz tcolorbox pst-exa - ); - -my $pkgcandidates = join q{|}, map { quotemeta } sort { length $a <=> length $b } @pkgcandidates; -$pkgcandidates = qr/$pkgcandidates/x; -my @graphicxpkg; - -### \graphicspath -my $graphicspath= qr/\\ graphicspath \{ ((?: $llaves )+) \}/ix; -my @graphicspath; - ### Replacing the extracted environments with \includegraphics Log("Convert pstricks extracted environments to \\includegraphics for $name-pdf$ext"); my $grap = "\\includegraphics[scale=1]{$name-fig-"; @@ -1900,49 +1858,84 @@ $preamble = "$atbegindoc$preamble"; ### Remove content in preamble my @tag_remove_preamble = $preamble =~ m/(?:^\%<\*remove$tmp>.+?\%<\/remove$tmp>)/gmsx; if (@tag_remove_preamble) { - Log("Removing the content between <*remove> ... tags in preamble for $name-pdf$ext"); + Log("Removing the content between %CleanPST ... %CleanPST in preamble for $name-pdf$ext"); $preamble =~ s/^\%<\*remove$tmp>\s*(.+?)\s*\%<\/remove$tmp>(?:[\t ]*(?:\r?\n|\r))?+//gmsx; } -### To be sure that the package is in the main document and not in a -### verbatim write environment we make the changes using the hash and -### range operator in a copy -my %tmpreplace = ( - 'graphicx' => 'TMPGRAPHICXTMP', - 'pst-exa' => 'TMPPSTEXATMP', - 'graphicspath' => 'TMPGRAPHICSPATHTMP', -); - -my $findtmp = join q{|}, map { quotemeta } sort { length $a <=> length $b } keys %tmpreplace; -my $preambletmp = $preamble; -my @lineas = split /\n/, $preambletmp; +### Suport for pst-exa package +my $pstexa = qr/(?:\\ usepackage) \[\s*(.+?)\s*\] (?:\{\s*(pst-exa)\s*\} ) /x; +my @pst_exa; +my %pst_exa; -### We remove the commented lines -s/\%.*(?:[\t ]*(?:\r?\n|\r))?+//msg foreach @lineas; +### Search pst-exa package +@pst_exa = $preamble =~ m/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|$pstexa/gmsx; +%pst_exa = map { $_ => 1 } @pst_exa; -### We make the changes in the environments verbatim write -my $DEL; -for (@lineas) { - if (/\\begin\{($verbatim_w\*?)(?{ $DEL = "\Q$^N" })\}/ .. /\\end\{$DEL\}/) { - s/($findtmp)/$tmpreplace{$1}/g; +### If found comment and adjust path for graphic files +if (@pst_exa) { + Log("Comment pst-exa package in preamble for $name-pdf$ext"); + $findgraphicx = 'false'; + $preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| + (\\usepackage\[)\s*(swpl|tcb)\s*(\]\{pst-exa\})/\%$1$2,pdf$3/msxg; + # Change for [tcb] option (path for graphic files) + if (exists $pst_exa{tcb}) { + Log("Suport for \\usepackage[tcb,pdf]\{pst-exa\} for $name-pdf$ext"); + $bodydoc =~ s/(graphic=\{)\[(scale=\d*)\]($imgdir\/$name-fig-exa-\d*)\}/$1$2\}\{$3\}/gsmx; } } -### Join lines in $preambletmp -$preambletmp = join "\n", @lineas; +### Regex for remove (pst-?) packages in preamble +$PALABRAS = qr/\b (?: pst-\w+ | pstricks (?: -add | -pdf )? | psfrag |psgo |vaucanson-g| auto-pst-pdf(?: -lua )? )/x; +$FAMILIA = qr/\{ \s* $PALABRAS (?: \s* [,] \s* $PALABRAS )* \s* \}(\%*)?/x; + +Log("Remove pstricks packages in preamble for $name-pdf$ext [no pst-exa]"); +$preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| + ^ $USEPACK (?: $CORCHETES )? $FAMILIA \s*//msxg; +$preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| + (?: ^ $USEPACK \{ | \G) [^}]*? \K (,?) \s* $PALABRAS (\s*) (,?) /$1 and $3 ? ',' : $1 ? $2 : ''/gemsx; + +### Uncomment pst-exa package +if (@pst_exa) { + Log("Uncomment pst-exa package in preamble for $name-pdf$ext"); + $preamble =~ s/(?:\%)(\\usepackage\[\s*)(swpl|tcb)(,pdf\s*\]\{pst-exa\})/$1$2$3/msxg; +} + +Log("Remove \\psset\{...\} in preamble for $name-pdf$ext"); +$preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| + \\psset\{(?:\{.*?\}|[^\{])*\}(?:[\t ]*(?:\r?\n|\r))+//gmsx; + +Log("Remove \\SpecialCoor in preamble for $name-pdf$ext"); +$preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| + \\SpecialCoor(?:[\t ]*(?:\r?\n|\r))+//gmsx; -### We removed the blank lines -$preambletmp =~ s/^(?:[\t ]*(?:\r?\n|\r))?+//gmsx; +Log("Remove empty lines in preamble for $name-pdf$ext"); +$preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| + ^\\usepackage\{\}(?:[\t ]*(?:\r?\n|\r))+/\n/gmsx; +$preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| + ^(?:[\t ]*(?:\r?\n|\r))?+//gmsx; -### Now we're trying to capture -@graphicxpkg = $preambletmp =~ m/($pkgcandidates)/gmsx; -if (@graphicxpkg) { - Log("Found graphicx package in preamble for $name-pdf$ext"); - $findgraphicx = 'false'; +### To be sure that the package graphicx and \graphicspath is in the main +### document and not in a verbatim write environment we make the changes +my %tmpreplace = ( + 'graphicx' => 'TMPGRAPHICXTMP', + 'graphicspath' => 'TMPGRAPHICSPATHTMP', +); +my $findtmp = join q{|}, map { quotemeta } sort { length $a <=> length $b } keys %tmpreplace; + +### We go line by line and make the changes [need /p for ${^MATCH}] +while ($preamble =~ /\%<\*$dtxverb>(.+?)\%<\/$dtxverb> | $tmpcomment /pgmsx) { + my ($pos_inicial, $pos_final) = ($-[0], $+[0]); + my $encontrado = ${^MATCH}; + $encontrado =~ s/($findtmp)/$tmpreplace{$1}/g; + substr $preamble, $pos_inicial, $pos_final-$pos_inicial, $encontrado; + pos ($preamble) = $pos_inicial + length $encontrado; } -### Search graphicspath -@graphicspath = $preambletmp =~ m/graphicspath/msx; +### Now we're trying to capture \graphicspath{...} +my $graphicspath= qr/\\ graphicspath \{ ((?: $llaves )+) \}/ix; +my @graphicspath; +@graphicspath = $preamble =~ m/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|($graphicspath)/gmsx; + if (@graphicspath) { Log("Found \\graphicspath in preamble for $name-pdf$ext"); $findgraphicx = 'false'; @@ -1961,19 +1954,53 @@ if (@graphicspath) { } } -### Search pst-exa -@pst_exa = $preambletmp =~ m/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|$pstexa/xg; -%pst_exa = map { $_ => 1 } @pst_exa; -if (@pst_exa) { - Log("Comment pst-exa package in preamble for $name-pdf$ext"); +### Possible packages that load graphicx +my @pkgcandidates = qw ( + rotating epsfig lyluatex xunicode parsa xepersian-hm gregoriotex teixmlslides + teixml fotex hvfloat pgfplots grfpaste gmbase hep-paper postage schulealt + schule utfsym cachepic abc doclicense rotating epsfig semtrans mgltex + graphviz revquantum mpostinl cmpj cmpj2 cmpj3 chemschemex register papercdcase + flipbook wallpaper asyprocess draftwatermark rutitlepage dccpaper-base + nbwp-manual mandi fmp toptesi isorot pinlabel cmll graphicx-psmin ptmxcomp + countriesofeurope iodhbwm-templates fgruler combinedgraphics pax pdfpagediff + psfragx epsdice perfectcut upmethodology-fmt ftc-notebook tabvar vtable + teubner pas-cv gcard table-fct pdfpages keyfloat pdfscreen showexpl simplecd + ifmslide grffile reflectgraphics markdown bclogo tikz-page pst-uml realboxes + musikui csbulobalka lwarp mathtools sympytex mpgraphics miniplot.sty:77 + dottex pdftricks2 feupphdteses tex4ebook axodraw2 hagenberg-thesis dlfltxb + hu-berlin-bundle draftfigure quicktype endofproofwd euflag othelloboard + pdftricks unswcover breqn pdfswitch latex-make figlatex repltext etsvthor + cyber xcookybooky xfrac mercatormap chs-physics-report tikzscale ditaa + pst-poker gmp CJKvert asypictureb hletter tikz-network powerdot-fuberlin + skeyval gnuplottex plantslabels fancytooltips ieeepes pst-vectorian + phfnote overpic xtuformat stubs graphbox ucs pdfwin metalogo mwe + inline-images asymptote UNAMThesis authorarchive amscdx adjustbox + trimclip fixmetodonotes incgraph scanpages alertmessage + svg quiz2socrative realhats autopdf egplot decorule figsize tikzexternal + pgfcore frontespizio textglos graphicx tikz tcolorbox + ); + +my $pkgcandidates = join q{|}, map { quotemeta } sort { length $a <=> length $b } @pkgcandidates; +$pkgcandidates = qr/$pkgcandidates/x; +my @graphicxpkg; + +### Now we're trying to capture graphicx package +@graphicxpkg = $preamble =~ m/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|($pkgcandidates)/gmsx; + +if (@graphicxpkg and $findgraphicx ne 'false') { + Log("Found graphicx package in preamble for $name-pdf$ext"); $findgraphicx = 'false'; - $preamble =~ s/(\\usepackage\[)\s*(swpl|tcb)\s*(\]\{pst-exa\})/\%$1$2,pdf$3/msxg; -} -if (exists $pst_exa{tcb}) { - Log("Suport for \\usepackage[tcb,pdf]\{pst-exa\} for $name-pdf$ext"); - $bodydoc =~ s/(graphic=\{)\[(scale=\d*)\]($imgdir\/$name-fig-exa-\d*)\}/$1$2\}\{$3\}/gsmx; } +### Revert changes in preamble for temp +my %tmpoutreplace = ( + 'TMPGRAPHICXTMP' => 'graphicx', + 'TMPGRAPHICSPATHTMP' => 'graphicspath', +); + +%replace = (%changes_out,%tmpoutreplace); +$find = join q{|}, map {quotemeta} sort { length $a <=> length $b } keys %replace; + ### Try to capture arara:compiler in preamble of my @arara_engines = qw (latex pdflatex lualatex xelatex luahbtex); my $arara_engines = join q{|}, map { quotemeta} sort { length $a <=> length $b } @arara_engines; @@ -1981,28 +2008,36 @@ $arara_engines = qr/\b(?:$arara_engines)/x; my $arara_rule = qr /^(?:\%\s{1}arara[:]\s{1}) ($arara_engines) /msx; ### Capture graphicx.sty in .log of LaTeX file -if ($findgraphicx eq 'true') { +if ($findgraphicx ne 'false') { Log("Couldn't capture the graphicx package for $name-pdf$ext in preamble"); my $ltxlog; my @graphicx; my $null = devnull(); + # Copy preamble and revert changes + my $preambletmp = $preamble; + $preambletmp =~ s/($find)/$replace{$1}/g; + $preambletmp =~ s/\%<\*$dtxverb>(.+?)\%<\/$dtxverb>/$1/gmsx; Log("Creating $name-fig-$tmp$ext [only preamble]"); if ($verbose) { say "Creating [$name-fig-$tmp$ext] with only preamble"; } open my $OUTfile, '>', "$name-fig-$tmp$ext"; - print {$OUTfile} "$preamble\n\\stop"; + print {$OUTfile} "$preambletmp\n\\stop"; close $OUTfile; - # Set compiler + # Set compiler for arara if ($opts_cmd{compiler}{arara}) { - my @engine = $preamble =~ m/$arara_rule/msx; + my @engine = $atbegindoc =~ m/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|$arara_rule/msx; my %engine = map { $_ => 1 } @engine; if (%engine) { for my $var (@arara_engines) { if (defined $engine{$var}) { + Log("Found engine [$var] for arara"); $compiler = $var; } } } - else { $compiler = 'pdflatex'; } + else { + Log("Not detected engine for arara, use default [pdflatex]"); + $compiler = 'pdflatex'; + } } if ($compiler eq 'latex') { $compiler = 'pdflatex'; } if ($compiler eq 'dvilualatex') { $compiler = 'lualatex'; } @@ -2025,48 +2060,28 @@ if ($findgraphicx eq 'true') { else { Log("Not found graphicx package in $name-fig-$tmp.log"); Log("Add \\usepackage\{graphicx\} to preamble of $name-pdf$ext"); - $preamble= "$preamble\n\\usepackage\{graphicx\}"; + $preamble= "$preamble\\usepackage\{graphicx\}\n"; } } -### Regex for clean (pst-?) in preamble -$PALABRAS = qr/\b (?: pst-\w+ | pstricks (?: -add | -pdf )? | psfrag |psgo |vaucanson-g| auto-pst-pdf(?: -lua )? )/x; -$FAMILIA = qr/\{ \s* $PALABRAS (?: \s* [,] \s* $PALABRAS )* \s* \}(\%*)?/x; - -Log("Remove pstricks packages in preamble for $name-pdf$ext"); -$preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| - ^ $USEPACK (?: $CORCHETES )? $FAMILIA \s*//msxg; -$preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| - (?: ^ $USEPACK \{ | \G) [^}]*? \K (,?) \s* $PALABRAS (\s*) (,?) /$1 and $3 ? ',' : $1 ? $2 : ''/gemsx; -$preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| - \\psset\{(?:\{.*?\}|[^\{])*\}(?:[\t ]*(?:\r?\n|\r))+//gmsx; -$preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)| - \\SpecialCoor(?:[\t ]*(?:\r?\n|\r))+//gmsx; -$preamble =~ s/^\\usepackage\{\}(?:[\t ]*(?:\r?\n|\r))+/\n/gmsx; - -if (@pst_exa) { - Log("Uncomment pst-exa package in preamble for $name-pdf$ext"); - $preamble =~ s/(?:\%)(\\usepackage\[\s*)(swpl|tcb)(,pdf\s*\]\{pst-exa\})/$1$2$3/msxg; -} - ### Add last lines if (!@graphicspath) { Log("Not found \\graphicspath in preamble for $name-pdf$ext"); Log("Add \\graphicspath\{\{$imgdir/\}\} to preamble for $name-pdf$ext"); - $preamble= "$preamble\n\\graphicspath\{\{$imgdir/\}\}"; + $preamble= "$preamble\\graphicspath\{\{$imgdir/\}\}\n"; } + Log("Add \\usepackage\{grfext\} to preamble for $name-pdf$ext"); -$preamble = "$preamble\n\\usepackage\{grfext\}"; +$preamble = "$preamble\\usepackage\{grfext\}\n"; Log("Add \\PrependGraphicsExtensions\*\{\.pdf\} to preamble for $name-pdf$ext"); -$preamble = "$preamble\n\\PrependGraphicsExtensions\*\{\.pdf\}"; +$preamble = "$preamble\\PrependGraphicsExtensions\*\{\.pdf\}"; $preamble =~ s/\%<\*$dtxverb>(.+?)\%<\/$dtxverb>/$1/gmsx; -$preamble =~ s/^\\usepackage\{\}(?:[\t ]*(?:\r?\n|\r))+/\n/gmsx; -$preamble =~ s/^(?:[\t ]*(?:\r?\n|\r))?+//gmsx; ### Create a my $out_file = "$preamble\n$bodydoc\n$enddoc"; -### Clean \psset content in output file +### Clean \psset{...} content in +Log("Remove \\psset\{...\} in body for $name-pdf$ext"); $out_file =~ s/\\begin\{nopreview\}\%$tmp.+?\\end\{nopreview\}\%$tmp(*SKIP)(*F)| \%<\*$dtxverb> .+? \%<\/$dtxverb>(*SKIP)(*F)| \\psset\{(?:\{.*?\}|[^\{])*\}(?:[\t ]*(?:\r?\n|\r))?+//gmsx; @@ -2087,7 +2102,7 @@ $out_file =~ s/\\begin\{nopreview\}%$tmp ### Remove internal mark for verbatim and verbatim write environments $out_file =~ s/\%<\*$dtxverb>(.+?)\%<\/$dtxverb>/$1/gmsx; -%replace = (%changes_out); +%replace = (%changes_out,%tmpoutreplace); $find = join q{|}, map {quotemeta} sort { length $a <=> length $b } keys %replace; $out_file =~ s/($find)/$replace{$1}/g; @@ -2115,13 +2130,20 @@ my $ltxmkopt = $xetex ? "-pdfxe -silent -xelatex=\"xelatex $write18 -recorder % : $luatex ? "-pdflua -silent -lualatex=\"lualatex $write18 -recorder %O %S\"" : "-pdf -silent -pdflatex=\"pdflatex $write18 -recorder %O %S\"" ; + ### Set options for compiler $opt_compiler = $arara ? '--log' : $latexmk ? "$ltxmkopt" : "$write18 -interaction=nonstopmode -recorder" ; -### Set compiler name for arara and latexmk +### Set message in terminal +$msg_compiler = $xetex ? 'xelatex' + : $luatex ? 'lualatex' + : 'pdflatex' + ; + +### Set compiler message and compiler for arara and latexmk if ($arara) { $compiler = $msg_compiler = 'arara'; } if ($latexmk) { $compiler = $msg_compiler = 'latexmk'; } -- cgit v1.2.3