summaryrefslogtreecommitdiff
path: root/support/ltximg
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-08-24 03:02:25 +0000
committerNorbert Preining <norbert@preining.info>2020-08-24 03:02:25 +0000
commitdb172be44b76658fe542ff91f2e6e02550d417b8 (patch)
tree9ef07d5b1cd3011bb4b5450a5ae976e5e0a2a8e4 /support/ltximg
parent16e50bc884ce50f72f1d7b979d6a8272a0cd3798 (diff)
CTAN sync 202008240302
Diffstat (limited to 'support/ltximg')
-rw-r--r--support/ltximg/README.md4
-rw-r--r--support/ltximg/doc/ltximg-doc.pdfbin245484 -> 242217 bytes
-rw-r--r--support/ltximg/doc/ltximg-doc.tex71
-rw-r--r--support/ltximg/script/ltximg.pl265
4 files changed, 192 insertions, 148 deletions
diff --git a/support/ltximg/README.md b/support/ltximg/README.md
index f61e27dd66..c5dc89cd92 100644
--- a/support/ltximg/README.md
+++ b/support/ltximg/README.md
@@ -1,6 +1,6 @@
-## LTXimg &ndash; Extract LaTeX environments to image format and standalone files
+## LTXimg &ndash; LaTeX environments to image format and standalone files
-Release v1.8 \[2020-08-18\]
+Release v1.9 \[2020-08-22\]
## Description
diff --git a/support/ltximg/doc/ltximg-doc.pdf b/support/ltximg/doc/ltximg-doc.pdf
index 6f8418d952..d11504ff8e 100644
--- a/support/ltximg/doc/ltximg-doc.pdf
+++ b/support/ltximg/doc/ltximg-doc.pdf
Binary files differ
diff --git a/support/ltximg/doc/ltximg-doc.tex b/support/ltximg/doc/ltximg-doc.tex
index 782ea159d3..8c625bf24b 100644
--- a/support/ltximg/doc/ltximg-doc.tex
+++ b/support/ltximg/doc/ltximg-doc.tex
@@ -65,8 +65,8 @@
\newcommand{\HP}[1]{\emph{\hyperpage{#1}}\normalsize}
\def\SortIndex#1#2{\index{#1\actualchar#2|HP}}
\indexsetup{level=\section,firstpagestyle=myheader}
-%\makeindex[options=-s gind.ist,columnsep=15pt,title={Index of Documentation}] %noautomatic
-\makeindex[noautomatic,columnsep=15pt,title={Index of Documentation}] %
+\makeindex[options=-q -s gind.ist,columnsep=15pt,title={Index of Documentation}] %noautomatic
+%\makeindex[noautomatic,columnsep=15pt,title={Index of Documentation}] %
% parindent
\setlength{\parindent}{0pt}
@@ -85,8 +85,8 @@
% Identification
\def\myscript{ltximg}
-\def\fileversion{1.8}
-\def\filedate{2020-08-18}
+\def\fileversion{1.9}
+\def\filedate{2020-08-22}
% Logo with fetamont and libertuns font
\ExplSyntaxOn
@@ -720,8 +720,8 @@
\begin{abstract}
\ltximg{} is a \prgname{perl} \emph{script} that automates the process of
-extracting and converting environments provided by \pkgname{tikz}, %
-\pkgname{pstricks} and other packages from \meta[cf=optcolor]{input file} to image
+extracting and converting environments provided by \pkgname{TikZ}, %
+\pkgname{PStricks} and other packages from \meta[cf=optcolor]{input file} to image
formats and standalone files using \prgname{ghostscript} and %
\prgname{poppler-utils}. Generates a file with only extracted environments
and another with all extracted environments converted to \ics{includegraphics}.
@@ -745,7 +745,7 @@ for more details.
\section{Motivation and Acknowledgments}
The original idea was to extend the functionality of the \scriptname{pst2pdf}\cite{pst2pdf}
-script to work with \env{tikzpicture} and other environments. The \pkgname{tikz}\cite{tikz} package
+script to work with \env{tikzpicture} and other environments. The \pkgname{TikZ}\cite{tikz} package
allows to \emph{externalize} the environments, but, the idea was to be able to extend this
to \emph{any type} of environment covering three central points:
@@ -758,12 +758,6 @@ to \emph{any type} of environment covering three central points:
\item Generate a file replacing the environments by \ics{includegraphics}.
\end{enumerate}
-\thispagestyle{plain}
-
-\newpage
-
-\pagestyle{myheader}
-
From the side of \hologo{TeX} there are some packages that cover several of these
points such as the \pkgname{preview}\cite{preview}, \pkgname{xcomment}\cite{xcomment}, \pkgname{extract}\cite{extract}
and \pkgname{cachepic}\cite{cachepic} packages among others, but none covered all points.
@@ -773,6 +767,12 @@ extract and convert environments, but in general they presented problems
when the document contained \emph{\enquote{verbatim style}} code or were only
available for \OSsystem{Linux}.
+\thispagestyle{plain}
+
+\newpage
+
+\pagestyle{myheader}
+
Analysed the situation the best thing was to create a new \emph{\enquote{script}} that
was able to cover the three points and was multi platform, the union of all
these ideas is born \ltximg.
@@ -817,7 +817,7 @@ that everything works correctly, for this we must be clear about some
concepts related to how to work with the \meta[cf=optcolor]{input file}, the \meta{verbatim content}
and the \meta{steps process}.
-\section{The input file}
+\subsection{The input file}
\label{sec:inputfile}
The \meta[cf=optcolor]{input file} must comply with \emph{certain characteristics} in order to
@@ -862,11 +862,12 @@ parts and then processing them:
If for some reason you have an environment \LWenv{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.
\newpage
-\section{Verbatim contents}
+\subsection{Verbatim contents}
\label{sec:verbatim}
One of the greatest capabilities of this script is to \emph{\enquote{skip}}
@@ -882,7 +883,7 @@ three types:
\item Verbatim write.
\end{itemize}
-\subsection{Verbatim in line}
+\subsection*{Verbatim in line}
\label{sec:verbatim:inline}
The small pieces of code written using a \emph{\enquote{verbatim macro}}
@@ -935,7 +936,7 @@ depending on the package you are using. If your \emph{\enquote{verbatim macro}}
supported by default or can not detect, use the options described in \ref%
{sec:optline} and \ref{sec:optfile}.
-\subsection{Verbatim standard}
+\subsection*{Verbatim standard}
\label{sec:verbatim:std}
These are the \emph{\enquote{classic}} environments for \emph{\enquote{writing code}} are considered %
@@ -1011,7 +1012,7 @@ If any of the \meta{verbatim standard} environments is not supported by
default or can not detected, you can use the options described in \ref%
{sec:optline} and \ref{sec:optfile}.
-\subsection{Verbatim write}
+\subsection*{Verbatim write}
\label{sec:verbatim:write}
Some environments have the ability to write \emph{\enquote{external files}}
@@ -1059,7 +1060,7 @@ If any of the \meta{verbatim write} environments is not supported by default
or can not detected, you can use the options described in \ref{sec:optline}
and \ref{sec:optfile}.
-\section{Steps process}
+\subsection{Steps process}
\label{sec:steps:process}
For creation of the image formats, extraction of source code of environments and creation of an
@@ -1097,7 +1098,7 @@ Some text
Some lines that will be ignored by the script
\end{examplecode}
-\subsection{Validating Options}
+\subsection*{Validating Options}
The first step is read and validated \oarg[type=tt,cf=optcolor,sbc=gray,ac=lightgray]{options} from the command
line and \sysfile{test.tex}, verifying that \sysfile{test.tex} contains \emph{some} environment to extract,
@@ -1108,7 +1109,7 @@ The entire \sysfile{test.tex} file is loaded into memory and \emph{\enquote{spli
\newpage
-\subsection{Comment and ignore}
+\subsection*{Comment and ignore}
In the second step, once the file \sysfile{test.tex} is loaded and divided in memory,
proceeds (in general terms) as follows:
@@ -1120,7 +1121,7 @@ extract inside the \lstinline|\begin{preview}| \ldots \lstinline|\end{preview}|.
At this point \emph{\enquote{all}} the code you want to extract is inside \lstinline|\begin{preview}|\ldots\lstinline|\end{preview}|.
-\subsection{Creating files and extracting}
+\subsection*{Creating files and extracting}
In the third step, the script generate \meta{standalone} files: \sysfile{test-fig-1.tex},
\sysfile{test-fig-2.tex}, \dots{} and saved in \sysdir{./images} then proceed in two ways
@@ -1164,7 +1165,7 @@ in a temporary file \sysfile{test-fig-1981.tex} in \enquote{\sysdir{./}}.
If \cmdopt{norun} is passed, the temporary file \sysfile{test-fig-1981.tex}
is renamed to \sysfile{test-fig-all.tex} and moved to \sysdir{./images}.
-\subsection{Generate image formats}
+\subsection*{Generate image formats}
In the fourth step, the script generating the file \sysfile{test-fig-1981.pdf} with all code extracted and croping, running:
\begin{examplecmd}
@@ -1178,10 +1179,10 @@ moved to the \sysdir{./images} and rename to \sysfile{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 \fext{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 \pkgname{minted} or others.
-\subsection{Create output file}
+\subsection*{Create output file}
In the fifth step, the script apply the option \cmdopt{clean}, remove all content betwen \lstinline|%<*remove> ... %</remove>|
and try to detect whether the \pkgname{graphicx} package and the \ics{graphicspath} command are in the preamble of the \meta[cf=optcolor]{output file} (in memory).
@@ -1204,7 +1205,7 @@ in \enquote{\sysdir{./}}, then proceed to run:
generating the file \sysfile{test-out.pdf}.
-\subsection{Clean temporary files and dirs}
+\subsection*{Clean temporary files and dirs}
In the sixth step, the script read the files \sysfile{test-fig-1981.fls}
and \sysfile{test-out.fls}, extract the information from the
@@ -1277,7 +1278,7 @@ cannot be passed as an argument to the option \cmdopt{skipenv}{}.
\vspace{0.25\baselineskip}
\DescribeTE{pspicture}
-Environment provide by \pkgname{pstricks}\cite{pstricks} package. The plain \hologo{TeX}
+Environment provide by \pkgname{PStricks}\cite{pstricks} package. The plain \hologo{TeX}
syntax \lstinline|\pspicture ... \endpspicture| its converted to \hologo{LaTeX} syntax
\lstinline|\begin{pspicture} ... \end{pspicture}| if not within the \env{PSTexample} or \env{postscript} environments.
@@ -1291,7 +1292,7 @@ not within the \env{PSTexample} or \env{postscript} environments.
\newpage
\DescribeTE{tikzpicture}
-Environment provide by \pkgname{tikz}\cite{tikz} package. The plain \hologo{TeX} syntax \lstinline|\tikzpicture ... \tikzpicture|
+Environment provide by \pkgname{TikZ}\cite{tikz} package. The plain \hologo{TeX} syntax \lstinline|\tikzpicture ... \tikzpicture|
its converted to \hologo{LaTeX} syntax \lstinline|\begin{tikzpicture} ... \end{tikzpicture}|
but no a short syntax \lstinline|\tikz ... ;|.
@@ -1600,7 +1601,7 @@ Removes specific content in \meta[cf=optcolor]{output file}. Valid values for th
\begin{description}[font=\ttfamily, nosep, noitemsep, leftmargin=0pt]
\item[\textcolor{gray}{doc}] All content after \lstinline+\end{document}+ is removed.
-\item[\textcolor{gray}{pst}] All \lstinline|\psset|\marg[type=tt]{code} and \pkgname{pstricks} package is removed in \meta{preamble} and \meta{body}.
+\item[\textcolor{gray}{pst}] All \lstinline|\psset|\marg[type=tt]{code} and \pkgname{PStricks} package is removed in \meta{preamble} and \meta{body}.
\item[\textcolor{gray}{tkz}] All \lstinline|\tikzset|\marg[type=tt]{code} is removed in \meta{body}.
\item[\textcolor{gray}{all}] Activates \textcolor{gray}{\texttt{doc}}, \textcolor{gray}{\texttt{pst}} and \textcolor{gray}{\texttt{tkz}}.
\item[\textcolor{gray}{off}] Deactivate all.
@@ -1629,7 +1630,7 @@ delete only in \meta{body} of \meta[cf=optcolor]{output file}, if it's the last
passed need \textcolor{optcolor}{\textbf{\texttt{-\/-}}} at the end. The environment \env{document}
is not supported in this option.\par
-\subsection{Passing options from command line}
+\subsection*{Passing options from command line}
An example of usage from command line:
@@ -1696,7 +1697,7 @@ place them inside the \lstinline|%<*remove> ... %</remove>|. Like this:
%</remove>
\end{examplecode}
-\subsection{Passing options from input file}
+\subsection*{Passing options from input file}
Adding the following lines to the beginning of the file \sysfile{file-in.tex}:
@@ -1926,6 +1927,12 @@ versions, both development (devp) and public (ctan).
\begin{description}[font=\small\sffamily,wide=0pt,style=multiline,leftmargin=\descrwidth,nosep,noitemsep]
\item [v\fileversion\ (ctan), \filedate]
\begin{itemize}
+ \item Fix \texttt{graphicx} detection.
+ \item Fix typos in documentation.
+ \item Add more contents to \texttt{.log} file.
+ \end{itemize}
+\item [v1.8 (ctan), 2020-08-18]
+ \begin{itemize}
\item It is now possible to extract any environment.
\item Add \texttt{--log}, \texttt{--runs}, \texttt{--latexmk} and \texttt{--dvilua} options.
\item All calls to the system are captured.
diff --git a/support/ltximg/script/ltximg.pl b/support/ltximg/script/ltximg.pl
index 4cc7440abb..7e703a7bf5 100644
--- a/support/ltximg/script/ltximg.pl
+++ b/support/ltximg/script/ltximg.pl
@@ -40,8 +40,8 @@ my $workdir = cwd;
### Script identification
my $scriptname = 'ltximg';
my $program = 'LTXimg';
-my $nv = 'v1.8';
-my $date = '2020-08-18';
+my $nv = 'v1.9';
+my $date = '2020-08-22';
my $copyright = <<"END_COPYRIGHT" ;
[$date] (c) 2013-2020 by Pablo Gonzalez, pablgonz<at>yahoo.com
END_COPYRIGHT
@@ -1676,6 +1676,7 @@ $bodydoc =~ s/\\begin\{nopreview\}.+?\\end\{nopreview\}(*SKIP)(*F)|
$preamble =~ s/\\begin\{nopreview\}.+?\\end\{nopreview\}(*SKIP)(*F)|
\\begin\{preview\}.+?\\end\{preview\}(*SKIP)(*F)|
($verb_wrt)/\%<\*$dtxverb>$1\%<\/$dtxverb>/gmsx;
+$atbegindoc =~ s/($verb_wrt)/\%<\*$dtxverb>$1\%<\/$dtxverb>/gmsx;
Log("Pass verbatim environments to %<*$dtxverb> ... %</$dtxverb>");
$bodydoc =~ s/\\begin\{nopreview\}.+?\\end\{nopreview\}(*SKIP)(*F)|
@@ -1684,6 +1685,7 @@ $bodydoc =~ s/\\begin\{nopreview\}.+?\\end\{nopreview\}(*SKIP)(*F)|
$preamble =~ s/\\begin\{nopreview\}.+?\\end\{nopreview\}(*SKIP)(*F)|
\\begin\{preview\}.+?\\end\{preview\}(*SKIP)(*F)|
($verb_std)/\%<\*$dtxverb>$1\%<\/$dtxverb>/gmsx;
+$atbegindoc =~ s/($verb_std)/\%<\*$dtxverb>$1\%<\/$dtxverb>/gmsx;
### Check plain TeX syntax
my %plainsyntax = map { $_ => 1 } @extract_env; # anon hash
@@ -1971,7 +1973,7 @@ my $arara_rule = qr /^(?:\%\s{1}arara[:]\s{1}) ($arara_engines) /msx;
### Set options for [compiler], [preview] and [pdfcrop]
if ($compiler eq 'arara') {
Log('Trying to detect some suported [engine] in the rules of arara');
- my @engine = $atbegindoc =~ m/$arara_rule/msx;
+ my @engine = $atbegindoc =~ m/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|$arara_rule/msx;
my %engine = map { $_ => 1 } @engine; # anon hash
if (exists $engine{latex}) {
Log('The [latex] engine was found in arara rule');
@@ -2225,6 +2227,7 @@ $preamout =~ s/^\\usepackage\{\}(?:[\t ]*(?:\r?\n|\r))+/\n/gmsx;
### Remove %<*$dtxverb> ... %</$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
@@ -2487,11 +2490,110 @@ if (!$opts_cmd{boolean}{norun}) {
### Constant
my $findgraphicx = 'true';
+### Add $atbegindoc to $preamble
+$preamble = "$atbegindoc$preamble";
+
+### Replacing the extracted environments with \\includegraphics
+if ($outfile) {
+ my @tag_remove_preamble = $preamble =~ m/(?:^\%<\*remove$tmp>.+?\%<\/remove$tmp>)/gmsx;
+ if (@tag_remove_preamble) {
+ Log("Removing the content between <*remove> ... </remove> tags in preamble for $opts_cmd{string}{output}$outext");
+ $preamble =~ s/^\%<\*remove$tmp>\s*(.+?)\s*\%<\/remove$tmp>(?:[\t ]*(?:\r?\n|\r))?+//gmsx;
+ }
+ Log("Convert standard extracted environments to \\includegraphics for $opts_cmd{string}{output}$outext");
+ my $grap = "\\includegraphics[scale=1]{$name-$opts_cmd{string}{prefix}-";
+ my $close = '}';
+ my $imgNo = 1;
+ $bodydoc =~ s/$BP.+?$EP/$grap@{[$imgNo++]}$close/msg;
+}
+
### pst-exa package
my $pstexa = qr/(?:\\ usepackage) \[\s*(.+?)\s*\] (?:\{\s*(pst-exa)\s*\} ) /x;
my @pst_exa;
my %pst_exa;
+### Search pst-exa package
+@pst_exa = $preamble =~ m/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|$pstexa/gmsx;
+%pst_exa = map { $_ => 1 } @pst_exa;
+
+### If found comment and adjust path for graphic files
+if (@pst_exa and $outfile) {
+ Log("Comment pst-exa package in preamble for $opts_cmd{string}{output}$outext");
+ $findgraphicx = 'false';
+ $preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|
+ (\\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 $opts_cmd{string}{output}$outext");
+ $bodydoc =~ s/(graphic=\{)\[(scale=\d*)\]($opts_cmd{string}{imgdir}\/$name-$opts_cmd{string}{prefix}-exa-\d*)\}/$1$2\}\{$3\}/gsmx;
+ }
+}
+
+### Regex for clean file (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;
+
+### Clean PST content in preamble
+if ($clean{pst} and $outfile) {
+ Log("Remove pstricks packages in preamble for $opts_cmd{string}{output}$outext");
+ $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;
+ if (@pst_exa) {
+ Log("Uncomment pst-exa package in preamble for $opts_cmd{string}{output}$outext");
+ $preamble =~ s/(?:\%)(\\usepackage\[\s*)(swpl|tcb)(,pdf\s*\]\{pst-exa\})/$1$2$3/msxg;
+ }
+ Log("Remove \\psset\{...\} in preamble for $opts_cmd{string}{output}$outext");
+ $preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|
+ \\psset\{(?:\{.*?\}|[^\{])*\}(?:[\t ]*(?:\r?\n|\r))+//gmsx;
+ Log("Remove \\SpecialCoor in preamble for $opts_cmd{string}{output}$outext");
+ $preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|
+ \\SpecialCoor(?:[\t ]*(?:\r?\n|\r))+//gmsx;
+ Log("Remove empty lines in preamble for $opts_cmd{string}{output}$outext");
+ $preamble =~ s/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|
+ ^\\usepackage\{\}(?:[\t ]*(?:\r?\n|\r))+/\n/gmsx;
+}
+
+### 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;
+}
+
+### 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 and $outfile) {
+ Log("Found \\graphicspath in preamble for $opts_cmd{string}{output}$outext");
+ $findgraphicx = 'false';
+ while ($preamble =~ /$graphicspath /pgmx) {
+ my ($pos_inicial, $pos_final) = ($-[0], $+[0]);
+ my $encontrado = ${^MATCH};
+ if ($encontrado =~ /$graphicspath/) {
+ my $argumento = $1;
+ if ($argumento !~ /\{$opts_cmd{string}{imgdir}\/\}/) {
+ $argumento .= "\{$opts_cmd{string}{imgdir}/\}";
+ my $cambio = "\\graphicspath{$argumento}";
+ substr $preamble, $pos_inicial, $pos_final-$pos_inicial, $cambio;
+ pos($preamble) = $pos_inicial + length $cambio;
+ }
+ }
+ }
+}
+
### Possible packages that load graphicx
my @pkgcandidates = qw (
rotating epsfig lyluatex xunicode parsa xepersian-hm gregoriotex teixmlslides
@@ -2522,107 +2624,53 @@ my $pkgcandidates = join q{|}, map { quotemeta } sort { length $a <=> length $b
$pkgcandidates = qr/$pkgcandidates/x;
my @graphicxpkg;
-### \graphicspath
-my $graphicspath= qr/\\ graphicspath \{ ((?: $llaves )+) \}/ix;
-my @graphicspath;
-
-### Replacing the extracted environments with \\includegraphics
-if ($outfile) {
- Log("Convert standard extracted environments to \\includegraphics for $opts_cmd{string}{output}$outext");
- my $grap = "\\includegraphics[scale=1]{$name-$opts_cmd{string}{prefix}-";
- my $close = '}';
- my $imgNo = 1;
- $bodydoc =~ s/$BP.+?$EP/$grap@{[$imgNo++]}$close/msg;
- $preamble = "$atbegindoc$preamble";
- my @tag_remove_preamble = $preamble =~ m/(?:^\%<\*remove$tmp>.+?\%<\/remove$tmp>)/gmsx;
- if (@tag_remove_preamble) {
- Log("Removing the content between <*remove> ... </remove> tags in preamble for $opts_cmd{string}{output}$outext");
- $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;
- # We remove the commented lines
- s/\%.*(?:[\t ]*(?:\r?\n|\r))?+//msg foreach @lineas;
- # 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;
- }
- }
- $preambletmp = join "\n", @lineas; # Join lines in $preambletmp
- $preambletmp =~ s/^(?:[\t ]*(?:\r?\n|\r))?+//gmsx; # We removed the blank lines
- # Now we're trying to capture
- @graphicxpkg = $preambletmp =~ m/($pkgcandidates)/gmsx;
- if (@graphicxpkg) {
- Log("Found graphicx package in preamble for $opts_cmd{string}{output}$outext");
- $findgraphicx = 'false';
- }
- # Second search graphicspath
- @graphicspath = $preambletmp =~ m/graphicspath/msx;
- if (@graphicspath) {
- Log("Found \\graphicspath in preamble for $opts_cmd{string}{output}$outext");
- $findgraphicx = 'false';
- while ($preamble =~ /$graphicspath /pgmx) {
- my ($pos_inicial, $pos_final) = ($-[0], $+[0]);
- my $encontrado = ${^MATCH};
- if ($encontrado =~ /$graphicspath/) {
- my $argumento = $1;
- if ($argumento !~ /\{$opts_cmd{string}{imgdir}\/\}/) {
- $argumento .= "\{$opts_cmd{string}{imgdir}/\}";
- my $cambio = "\\graphicspath{$argumento}";
- substr $preamble, $pos_inicial, $pos_final-$pos_inicial, $cambio;
- pos($preamble) = $pos_inicial + length $cambio;
- }
- }
- }
- }
- # Third 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 $opts_cmd{string}{output}$outext");
- $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 $opts_cmd{string}{output}$outext");
- $bodydoc =~ s/(graphic=\{)\[(scale=\d*)\]($opts_cmd{string}{imgdir}\/$name-$opts_cmd{string}{prefix}-exa-\d*)\}/$1$2\}\{$3\}/gsmx;
- }
+### Now we're trying to capture graphicx package
+@graphicxpkg = $preamble =~ m/\%<\*$dtxverb> .+?\%<\/$dtxverb>(*SKIP)(*F)|($pkgcandidates)/gmsx;
+if (@graphicxpkg and $outfile and $findgraphicx ne 'false') {
+ Log("Found graphicx package in preamble for $opts_cmd{string}{output}$outext");
+ $findgraphicx = 'false';
}
+### Revert changes in preamble for temp <output file>
+my %tmpoutreplace = (
+ 'TMPGRAPHICXTMP' => 'graphicx',
+ 'TMPGRAPHICSPATHTMP' => 'graphicspath',
+);
+
+%replace = (%changes_out,%tmpoutreplace);
+$find = join q{|}, map {quotemeta} sort { length $a <=> length $b } keys %replace;
+
### Capture graphicx.sty in .log of LaTeX file
-if ($findgraphicx eq 'true' and $outfile) {
+if ($findgraphicx ne 'false' and $outfile) {
Log("Couldn't capture the graphicx package for $opts_cmd{string}{output}$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-$opts_cmd{string}{prefix}-$tmp$ext [only preamble]");
if ($verbose) { say "Creating [$name-$opts_cmd{string}{prefix}-$tmp$ext] with only preamble"; }
open my $OUTfile, '>', "$name-$opts_cmd{string}{prefix}-$tmp$ext";
- print {$OUTfile} "$preamble\n\\stop";
+ print {$OUTfile} "$preambletmp\n\\stop";
close $OUTfile;
# Set compiler
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 ($opts_cmd{compiler}{latex}) { $compiler = 'pdflatex'; }
if ($opts_cmd{compiler}{dvilua}) { $compiler = 'lualatex'; }
@@ -2645,49 +2693,27 @@ if ($findgraphicx eq 'true' and $outfile) {
else {
Log("Not found graphicx package in $name-$opts_cmd{string}{prefix}-$tmp.log");
Log("Add \\usepackage\{graphicx\} to preamble of $opts_cmd{string}{output}$outext");
- $preamble= "$preamble\n\\usepackage\{graphicx\}";
+ $preamble= "$preamble\\usepackage\{graphicx\}\n";
}
}
-### Regex for clean file (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;
-
-if ($clean{pst}) {
- Log("Remove pstricks packages in preamble for $opts_cmd{string}{output}$outext");
- $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 $opts_cmd{string}{output}$outext");
- $preamble =~ s/(?:\%)(\\usepackage\[\s*)(swpl|tcb)(,pdf\s*\]\{pst-exa\})/$1$2$3/msxg;
-}
-
### Add last lines
if ($outfile) {
if (!@graphicspath) {
Log("Not found \\graphicspath in preamble for $opts_cmd{string}{output}$outext");
Log("Add \\graphicspath\{\{$opts_cmd{string}{imgdir}/\}\} to preamble for $opts_cmd{string}{output}$ext");
- $preamble= "$preamble\n\\graphicspath\{\{$opts_cmd{string}{imgdir}/\}\}";
+ $preamble= "$preamble\\graphicspath\{\{$opts_cmd{string}{imgdir}/\}\}\n";
}
Log("Add \\usepackage\{grfext\} to preamble for $opts_cmd{string}{output}$ext");
- $preamble = "$preamble\n\\usepackage\{grfext\}";
+ $preamble = "$preamble\\usepackage\{grfext\}\n";
Log("Add \\PrependGraphicsExtensions\*\{\.pdf\} to preamble for $opts_cmd{string}{output}$ext");
- $preamble = "$preamble\n\\PrependGraphicsExtensions\*\{\.pdf\}";
+ $preamble = "$preamble\\PrependGraphicsExtensions\*\{\.pdf\}";
$preamble =~ s/\%<\*$dtxverb>\s*(.+?)\s*\%<\/$dtxverb>/$1/gmsx;
$preamble =~ s/^\\usepackage\{\}(?:[\t ]*(?:\r?\n|\r))+/\n/gmsx;
$preamble =~ s/^(?:[\t ]*(?:\r?\n|\r))?+//gmsx;
}
-### We remove environments from the output file
+### We remove environments from the <output file>
if (%delete_env and $outfile) {
Log("Remove environments in body of $opts_cmd{string}{output}$ext");
%replace = (%delete_env);
@@ -2748,13 +2774,13 @@ if ($outfile) {
my $out_file = $clean{doc} ? "$preamble\n$bodydoc\n\\end\{document\}"
: "$preamble\n$bodydoc\n$enddoc"
;
- # Clean \psset content in output file
+ # Clean \psset{...} content in <output file>
if ($clean{pst}) {
$out_file =~ s/\\begin\{nopreview\}.+?\\end\{nopreview\}(*SKIP)(*F)|
\%<\*$dtxverb> .+? \%<\/$dtxverb>(*SKIP)(*F)|
\\psset\{(?:\{.*?\}|[^\{])*\}(?:[\t ]*(?:\r?\n|\r))?+//gmsx;
}
- # Clean \tikzset content in output file
+ # Clean \tikzset{...} content in <output file>
if ($clean{tkz}) {
$out_file =~ s/\\begin\{nopreview\}.+?\\end\{nopreview\}(*SKIP)(*F)|
\%<\*$dtxverb> .+? \%<\/$dtxverb>(*SKIP)(*F)|
@@ -2812,9 +2838,20 @@ $opt_compiler = $opts_cmd{compiler}{arara} ? '--log'
: "$write18 -interaction=nonstopmode -recorder"
;
-### Now set latexmk
+### Message in command line for compiler
+$msg_compiler = $opts_cmd{compiler}{xetex} ? 'xelatex'
+ : $opts_cmd{compiler}{luatex} ? 'lualatex'
+ : $opts_cmd{compiler}{latex} ? 'pdflatex'
+ : $opts_cmd{compiler}{dvips} ? 'latex>dvips>ps2pdf'
+ : $opts_cmd{compiler}{dvilua} ? 'lualatex'
+ : $opts_cmd{compiler}{dvipdf} ? 'latex>dvipdfmx'
+ : $opts_cmd{compiler}{arara} ? 'arara'
+ : 'latexmk'
+ ;
+
+### Now set message for latexmk
if ($opts_cmd{compiler}{latexmk}) {
- $compiler = $msg_compiler = 'latexmk';
+ $msg_compiler = 'latexmk';
}
### Compiling <output file>