summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Master/texmf-dist/doc/latex/tikzscale/3Dplot.tikz10
-rw-r--r--Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.pdfbin156394 -> 177022 bytes
-rw-r--r--Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.tex7
-rw-r--r--Master/texmf-dist/doc/latex/tikzscale/tikzscale.pdfbin365963 -> 375085 bytes
-rw-r--r--Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx237
-rw-r--r--Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty101
6 files changed, 276 insertions, 79 deletions
diff --git a/Master/texmf-dist/doc/latex/tikzscale/3Dplot.tikz b/Master/texmf-dist/doc/latex/tikzscale/3Dplot.tikz
new file mode 100644
index 00000000000..2875de72c2e
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/tikzscale/3Dplot.tikz
@@ -0,0 +1,10 @@
+\tdplotsetmaincoords{77}{-8}%
+\begin{tikzpicture}[tdplot_main_coords]
+ x={(2 cm, 2 cm)},%
+ y={(2 cm, 2 cm)},%
+ z={(2 cm, 2 cm)}%
+ ]%
+ \draw [->] (0,0,0) -- (1,0,0) node[below] {$x_1$};%
+ \draw [->] (0,0,0) -- (0,0,1) node[left] {$x_2$};%
+ \draw [->] (0,0,0) -- (0,1,0) node[left] {$x_3$};%
+\end{tikzpicture}% \ No newline at end of file
diff --git a/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.pdf b/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.pdf
index 4691263c711..3822448fc38 100644
--- a/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.pdf
+++ b/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.tex b/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.tex
index 5682c7a4356..efcfd66d551 100644
--- a/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.tex
+++ b/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.tex
@@ -4,6 +4,7 @@
\usepackage{tikzscale}
\usepackage{tikz}
\usepackage{pgfplots}
+\usepackage{tikz-3dplot}
\usepackage{currfile}
\usepackage{lmodern}
% Use the package ifpdf to share one test document between pdflatex and latex
@@ -13,8 +14,8 @@
\usetikzlibrary{external}
\tikzexternalize
-% \tikzexternaldisable % activate this line and test without "shell-escape" and withouth \tikzexternalenable below
% \tikzexternalize[mode=list and make]
+% \tikzexternaldisable % activate this line and test without "shell-escape" and without \tikzexternalenable below
\ifpdf
\else
\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"; dvips -o "\image".ps "\image".dvi}}
@@ -87,7 +88,9 @@
\fi
\item Use includegraphics with a histogram of a normal distribution\\%
\includegraphics[width=\linewidth,height=0.5\linewidth]{histogramNormal}%
- \item {Use \texttt{\textbackslash graphicspath} with superfluous space\graphicspath{{somefolder} }
+ \item {Use \texttt{\textbackslash graphicspath} with superfluous space\graphicspath{{somefolder} } (only defined locally for the current item)
\includegraphics{testRectangle.tikz}}%
+ \item Use a tikz-3Dplot, which is known to have a different size after externalization compared to the measurements without externalization and is thus rebuilt every time if the counter-measurements are not successful.\\%
+ \includegraphics[width=\linewidth]{3Dplot}
\end{itemize}
\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/doc/latex/tikzscale/tikzscale.pdf b/Master/texmf-dist/doc/latex/tikzscale/tikzscale.pdf
index 8de4c571b77..8702f0ba8e0 100644
--- a/Master/texmf-dist/doc/latex/tikzscale/tikzscale.pdf
+++ b/Master/texmf-dist/doc/latex/tikzscale/tikzscale.pdf
Binary files differ
diff --git a/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx b/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx
index 23c66b0d1c4..2eee518e3fa 100644
--- a/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx
+++ b/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx
@@ -94,7 +94,7 @@ and the derived files tikzscale.ins,
%</internal>
%<*package>
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{tikzscale}[2013/03/30 v0.2.5 tikzscale LaTeX package]
+\ProvidesPackage{tikzscale}[2013/05/22 v0.2.6 tikzscale LaTeX package]
\RequirePackage{graphicx}
\RequirePackage{etoolbox}
\RequirePackage{pgfkeys}
@@ -192,6 +192,7 @@ and the derived files tikzscale.ins,
%\changes{v0.2.3}{2013/01/23}{Fix graphicspath bug; fix endlinechar bug, improve compatibility with beamer}
%\changes{v0.2.4}{2013/03/10}{Fix another graphicspath bug; support Beamer's \cmd{\pause} command}
%\changes{v0.2.5}{2013/03/30}{Do not accidently activate externalization}
+%\changes{v0.2.6}{2013/05/22}{Fix whitespace issue; correctly scale with externalization even if it scales incorrectly}
% \section{Introduction}
% When dealing with graphics, there are different scaling demands. For \emph{absolute} scaling, a width and/or height is given. Opposed to that, for relativ scaling, a horizontal and/or vertical scaling factor is needed. This package only is about absolute scaling of tikzpicture environments. The different absolute scaling demands and their solutions are shown in table \ref{scalingDemands}.
% \begin{table}
@@ -381,6 +382,8 @@ and the derived files tikzscale.ins,
%
% \section{Further Ideas}
% \begin{itemize}
+% \item With careful considerations, it should be possible to reduce the average number of needed figure renderings, which should speed-up runs with very complicated figures.
+% \item Add the external file optimization loop to axis ratio and pgfplots, as well.
% \item It might be a good idea to use the file names as figure names, but probably only if the name was not already set by the user. Additionally, there must be taken care to not try to write into a directory where there is no write access (e.g. reading a graphic from a system wide TeX installation)
% \item if graphic files are located in a subdirectory, the externalized files should also be in that subdirectory.
% \item allow in-file graphics by redefining the tikzpicture environment and accepting tikzscale and tikz options. The tikzscale options are evaluated using key filtering (tikz library) and the tikz options are forwarded.
@@ -489,6 +492,18 @@ and the derived files tikzscale.ins,
% \end{macrocode}
%\end{macro}
%
+%\begin{macro}{\ifedefequal}
+% \xcmd\ifedefequal{first expression}{second expression}{true}{false}
+% This is a general command, which might be useful for inclusion into the etoolbox package. It executes the true code if both expressions expand to the same and otherwise the false code. This test is often wanted, as the order of the arguments is not important and it does not matter if the user saves a value in another macro without expanding it.
+% \begin{macrocode}
+\def\ifedefequal#1#2{%
+ \edef\etoolbox@ifedefequal@first{#1}%
+ \edef\etoolbox@ifedefequal@second{#2}%
+ \ifdefequal{\etoolbox@ifedefequal@first}{\etoolbox@ifedefequal@second}%
+}
+% \end{macrocode}
+%\end{macro}
+%
%\begin{macro}{\edocsvlist}
% This is a general command, which might be useful for inclusion into the etoolbox package. It works similar to \cmd{\docsvlist} but expands its argument similar to \cmd{\def} vs.\ \cmd{\edef}, which is useful if the list is stored in a macro/variable.
% \begin{macrocode}
@@ -648,6 +663,16 @@ and the derived files tikzscale.ins,
% \end{macrocode}
%\end{macro}
%
+%\begin{macro}{\tikzscale@debug}
+% Activate and deactivate debugging by commenting and uncommenting the folowing code.
+% \begin{macrocode}
+% \def\tikzscale@debug#1{%
+% \PackageWarning{tikzscale}{#1}%
+% }
+\def\tikzscale@debug#1{}%
+% \end{macrocode}
+%\end{macro}
+%
%\begin{macro}{\activatetikzscale}
% \begin{macrocode}
\AtEndPreamble{%
@@ -731,14 +756,9 @@ and the derived files tikzscale.ins,
\tikzscale@externalend@storeshifts{#1}%
\ifpgfexternal@info
% \end{macrocode}
- % The axis ratio can only be saved, if it has been specified. Thus, the existence of the variable in the dpth file indicates if the axis ratio has been given in the last run.
+ % Write the axis ratio into the dpth file into variable \cmd{\tikzscale@oldAxisRatio}. The existence of the variable in the dpth file indicates if the axis ratio has been given in the last run.
% \begin{macrocode}
- \ifdef{\requestedAxisRatio}{%
-% \end{macrocode}
- % Write the axis ratio into the dpth file into variable \cmd{\tikzscale@oldAxisRatio} as in the macro \cmd{\pgf@externalend@storeshifts} from file pgfcoreexternal.code.tex.
-% \begin{macrocode}
- \immediate\write#1{\noexpand\pgfexternal@restore{\noexpand\def\noexpand\tikzscale@oldAxisRatio{\requestedAxisRatio}}}%
- }{}%
+ \tikzscale@writeToDpth{#1}{\tikzscale@oldAxisRatio}{\requestedAxisRatio}%
\fi
}%
}{}%
@@ -748,6 +768,20 @@ and the derived files tikzscale.ins,
% \end{macrocode}
%\end{macro}
%
+%\begin{macro}{\tikzscale@writeToDpth}
+% Write the value of the third argument, if it exists, into the dpth file (write handle in the first argument) of the current figure, accessible by the second argument. The second and the third argument must contain macro names (including the backslash).
+% \begin{macrocode}
+\def\tikzscale@writeToDpth#1#2#3{%
+ \ifdef{#3}{%
+% \end{macrocode}
+ % This is copied from the macro \cmd{\pgf@externalend@storeshifts} from file pgfcoreexternal.code.tex.
+% \begin{macrocode}
+ \immediate\write#1{\noexpand\pgfexternal@restore{\noexpand\def\noexpand#2{#3}}}%
+ }{}%
+}
+% \end{macrocode}
+%\end{macro}
+%
%\begin{macro}{\includegraphics}
% \begin{macrocode}
\NewDocumentCommand{\tikzscale@includegraphics}{O{}m}{%
@@ -999,7 +1033,8 @@ and the derived files tikzscale.ins,
% If externalization library has been loaded and is active, draw and scale the graphic if it is to be externalized.
% \begin{macrocode}
\tikzifexternalizingnext{%
- \tikzscale@includetikzUnexternalized[#1]{#2}%
+ \tikzscale@debug{Externalizing the file #2}%
+ \tikzscale@includetikzUnexternalized{#2}%
}{%
\tikzscale@includetikzWithExternalization{#2}%
}%
@@ -1007,7 +1042,7 @@ and the derived files tikzscale.ins,
% \end{macrocode}
% Always draw and scale the graphic if externalization library has not been loaded or is deactivated.
% \begin{macrocode}
- \tikzscale@includetikzUnexternalized[#1]{#2}%
+ \tikzscale@includetikzUnexternalized{#2}%
}%
}
% \end{macrocode}
@@ -1015,24 +1050,24 @@ and the derived files tikzscale.ins,
%
%\begin{macro}{\tikzscale@includetikzUnexternalized}
% \begin{macrocode}
-\NewDocumentCommand{\tikzscale@includetikzUnexternalized}{O{}m}{%
+\def\tikzscale@includetikzUnexternalized#1{%
\elseif{test {\ifundef{\requestedWidth}} and test {\ifundef{\requestedHeight}} and test {\ifundef{\requestedAxisRatio}}}{%
-% \PackageWarning{tikzscale}{no option given}
+ \tikzscale@debug{no option given}%
% \end{macrocode}
% If no option is given, directly load the content, as nothing should get scaled.
% \begin{macrocode}
- \tikzscale@trim{\input{#2}}%
+ \tikzscale@trim{\input{#1}}%
}{test {\ifdef{\requestedWidth}} and test {\ifdef{\requestedHeight}}}{%
-% \PackageWarning{tikzscale}{width and height given}
+ \tikzscale@debug{width and height given}%
% \end{macrocode}
% If width and height are given, the content must be a pgfplot, so scale it. The plot currently only had approximately the given size without calling the resizeTo macro, due to a (known) bug in PGFPlots.
% \begin{macrocode}
- \tikzscale@resizePlotTo{#2}%
+ \tikzscale@resizePlotTo{#1}%
}{test {\ifdef{\requestedAxisRatio}}}{%
-% \PackageWarning{tikzscale}{axis ratio given}
- \tikzscale@includeAxisRatio{#2}%
+ \tikzscale@debug{axis ratio given}%
+ \tikzscale@includeAxisRatio{#1}%
}{test {\ifundef{\requestedAxisRatio}}}{%
-% \PackageWarning{tikzscale}{width or height given}
+ \tikzscale@debug{width or height given}%
% \end{macrocode}
% Use this test as a check if PGFPlots has been loaded.
% \begin{macrocode}
@@ -1041,17 +1076,17 @@ and the derived files tikzscale.ins,
% If only either width or height is given it can be a normal tikzpicture or a plot with axisratio=1. Let's guess that it is a plot with default axisratio. If the guess is wrong, the called function detects that scaling the plot does not work and automatically calls \cmd{\tikzscale@includeNormalTikzpicture}.
% \begin{macrocode}
\def\requestedAxisRatio{1}%
- \tikzscale@includeAxisRatio{#2}%
+ \tikzscale@includeAxisRatio{#1}%
}{%
-% \PackageWarning{tikzscale}{no pgfplots loaded}
+ \tikzscale@debug{no pgfplots loaded}%
% \end{macrocode}
% If PGFPlots has not been loaded, it can only be a TikZPicture.
% \begin{macrocode}
- \tikzscale@includeNormalTikzpicture{#2}%
+ \tikzscale@includeNormalTikzpicture{#1}%
}%
}{%
% Everything else results in an error.
- \tikzscale@invalidKeyError{#2}%
+ \tikzscale@invalidKeyError{#1}%
}%
}
% \end{macrocode}
@@ -1072,6 +1107,9 @@ and the derived files tikzscale.ins,
\IfFileExists{\tikzscale@externalizationName.dpth}{%
\tikzscale@checkRequestedSizeChanges
}{}%
+% \end{macrocode}
+ % The figure is either remade or the PDF is included with the following call. The former is correct if the file has been changed, the latter is correct if the last run was correct and nothing has changed since then. The only case left is if the figure has neither changed, nor is the exported size correct, as the file is then regenerated repeating the same error as last time. To change something, the new externalisation would need the result of the old externalization, but as the externalization is processed in a separate LaTeX process, it's non-trivial to push the information there.
+% \begin{macrocode}
\tikzscale@trim{\input{#1}}%
}
% \end{macrocode}
@@ -1087,35 +1125,38 @@ and the derived files tikzscale.ins,
\ifdef{\pgfexternalwidth}{%
\tikzscale@ifSizeDifference{\requestedWidth - \pgfexternalwidth}{%
\tikzset{external/remake next}%
-% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of width difference \MessageBreak (requestedWidth: \requestedWidth, pgfexternalwidth: \pgfexternalwidth)}%
+ \tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of width difference \MessageBreak (requestedWidth=\requestedWidth, pgfexternalwidth=\pgfexternalwidth)}%
% \tikzscale@warnIfSizeDifference{\requestedWidth}{\pgfexternalwidth}{current file}%
+% \end{macrocode}
+ % It would be possible to calculate a new size, if the old size did not fit, but this information would be needed to push into the externalization process, what is hard. The idea were requested = requested + measuredOld - fileSize.
+% \begin{macrocode}
}{}%
}{%
\tikzset{external/remake next}%
-% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of no external width}%
+ \tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of no external width}%
}%
}{}%
\ifdef{\requestedHeight}{%
\ifdef{\pgfexternalheight}{%
\tikzscale@ifSizeDifference{\requestedHeight - \pgfexternalheight}{%
\tikzset{external/remake next}%
-% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of height difference \MessageBreak (requestedHeight: \requestedHeight, pgfexternalheight: \pgfexternalheight)}%
+ \tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of height difference \MessageBreak (requestedHeight=\requestedHeight, pgfexternalheight=\pgfexternalheight)}%
}{}%
}{%
\tikzset{external/remake next}%
-% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of no external height}%
+ \tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of no external height}%
}%
}{}%
\ifdef{\requestedAxisRatio}{%
\ifdef{\tikzscale@oldAxisRatio}{%
\tikzscale@ifSizeDifference{\requestedAxisRatio - \tikzscale@oldAxisRatio}{%
\tikzset{external/remake next}%
-% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of axis ratio difference \MessageBreak (requestedAxisRatio: \requestedAxisRatio, oldAxisRatio: \tikzscale@oldAxisRatio)}%
+ \tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of axis ratio difference \MessageBreak (requestedAxisRatio=\requestedAxisRatio, oldAxisRatio=\tikzscale@oldAxisRatio)}%
}{}%
\undef{\tikzscale@oldAxisRatio}%
}{%
\tikzset{external/remake next}%
- \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of no external axis ratio}%
+ \tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of no external axis ratio}%
}%
}{}%
}
@@ -1192,6 +1233,7 @@ and the derived files tikzscale.ins,
% The first argument determines if a specific width or a specific height should be achieved by scaling.
% \begin{macrocode}
\NewDocumentCommand{\tikzscale@scaleTikzpictureTo}{mmm}{%
+ \tikzscale@debug{At beginning scale, requestedWidth=\requestedWidth}%
% \end{macrocode}
% Deactivate the externalization, as the measurements to determine the correct size should not be externalized.
% \begin{macrocode}
@@ -1236,40 +1278,116 @@ and the derived files tikzscale.ins,
\foreach \l in {1,...,\maxTestIterations}{%
\tikzscale@measureSize{\measuredIntermediate}{#1}{#2}%
% \end{macrocode}
- % Optimize until the absolute difference is small enough, although the (relative) size ratios are used to calculate a new scaling factor.
+ % Optimize until the absolute difference is small enough, although the (relative) size ratios are used to calculate a new scaling factor.
% \begin{macrocode}
\tikzscale@ifSizeDifference{\measuredIntermediate-\requestedSize}{%
% \end{macrocode}
% First divide before multiply to avoid overflowing (at 16384).
% \begin{macrocode}
\pgfmathsetmacro{\errorRatio}{\measuredIntermediate/\requestedSize}%
-% \PackageWarning{tikzscale}{errorRatio \errorRatio\MessageBreak for #3}%
+ \tikzscale@debug{errorRatio=\errorRatio\MessageBreak for #3}%
\pgfmathsetglobalmacro{\tikzscale@scale}{\tikzscale@scale/\errorRatio}%
}{%
\breakforeach%
}%
}%
% \end{macrocode}
- % Externalize the graphic with the final size.
-% \begin{macrocode}
- \tikzscale@conditionalEnableExternalization{#3}%
-% \end{macrocode}
- % Finally, include the picture. Do it via a new measurement to be able to warn if it does not fit good enough.
+ % Do a last measurement to be able to warn if the size does not fit good enough. This measurement has to be done before possibly reactivating the externalization, as measurements with activated externalization can lead to wrong measurement results (possibly due to calling \cmd{\shipout} inside of the measurement). The assumption is, that the real graphic size does not change if the externalization gets activated, which all tests seem to confirm.
% \begin{macrocode}
\tikzscale@measureSize{\measuredFinal}{#1}{#2}%
- \usebox{\tikzscale@measuredSize}%
\tikzscale@warnIfSizeDifference{\measuredFinal}{\requestedSize}{#3}%
+ \tikzscale@testGraphicFileForRetry{#1}{#2}{#3}{\measuredFinal}%
}{%
+ \tikzscale@testGraphicFileForRetry{#1}{#2}{#3}{\measuredSecond}%
+ }%
+}
% \end{macrocode}
- % Externalize the graphic with the final size.
+%\end{macro}
+%
+%\begin{macro}{\tikzscale@testGraphicFileForRetry}
+% The macro tests the size of the generated graphic file. If the size is not as the requested size, the optimization is redone with an adapted optimization criterion to compensate the error done in the last run.
+%
+% \xcmd\tikzscale@testGraphicFileForRetry{\cmd{\wd} or \cmd{\ht}}{to-be-scaled content}{file name}{last measurement}
+%
% \begin{macrocode}
- \tikzscale@conditionalEnableExternalization{#3}%
- #2%
- }%
+\def\tikzscale@testGraphicFileForRetry#1#2#3#4{%
+% \end{macrocode}
+ % Reactivate externalization to prepare the figure to be really rendered.
+% \begin{macrocode}
+ \tikzscale@conditionalEnableExternalization{#3}%
+% \end{macrocode}
+ % Before externalizing the file, save the current externalization file name to be possibly used later. This code must be run after the reactivation of the externalization and before the rendering itself.
+% \begin{macrocode}
+ \tikzscale@ifExternalizationActive{%
+ \tikzexternalgetnextfilename{\tikzscale@externalizationName}%
+ }{}%
+% \end{macrocode}
+ % Finally, externalize and include the graphic with the final size. The graphic must not be included by reusing the measuredSize-box, as this leads to a subtly wrong behaviour when generating the PDF files. It can be observed by running the test suite with externalization and checking that no file is regenerated in the second run. Reusing the box can also lead to compile errors, if the problematic graphic is the last graphic in the document.
+% \begin{macrocode}
+ #2%
+% \end{macrocode}
+ % If the externalization is active, it might happen, that a figure was scaled correctly according to the request, but the externalized figure has a different size. The reason for that behaviour is unknown. The only chance we have is to calculate the error, rewind everything and try again with the compensated error.
+% \begin{macrocode}
+ \tikzscale@ifExternalizationActive{%
+% \end{macrocode}
+ % Read the size of the saved PDF file and save it on \cmd{\pgfexternalsize}.
+% \begin{macrocode}
+ \pgfexternalreaddpth{\tikzscale@externalizationName}%
+ \tikzscale@ifIsWidth{#1}{%
+ \edef\pgfexternalsize{\pgfexternalwidth}%
+ }{%
+ \edef\pgfexternalsize{\pgfexternalheight}%
+ }%
+% \end{macrocode}
+ % Save the \cmd{\requestedSize} from the user in \cmd{\originalRequestedSize}, as the former value has to be overwritten for the next try. Do not use \cmd{\def}, as that would later be expanded to the current and not to the original value.
+% \begin{macrocode}
+ \ifundef{\originalRequestedSize}{%
+ \let\originalRequestedSize\requestedSize
+ }{}%
+ \tikzscale@debug{originalRequestedSize=\originalRequestedSize, requestedSize=\requestedSize, pgfexternalsize=\pgfexternalsize}%
+% \end{macrocode}
+ % If a size difference is left, compensate it, decrease the counter and try the scaling again.
+% \begin{macrocode}
+ \tikzscale@ifSizeDifference{\originalRequestedSize-\pgfexternalsize}{%
+ \pgfmathsetmacro{\requestedSize}{\requestedSize + #4 - \pgfexternalsize}%
+ \tikzscale@decreaseFigureCounter
+ \tikzscale@scaleTikzpictureTo{#1}{#2}{#3}%
+ }{}%
+ }{}%
}
% \end{macrocode}
%\end{macro}
%
+%\begin{macro}{\tikzscale@decreaseFigureCounter}
+% Decrease the externalization figure counter. This way the last externalized figure will be overwritten when the next figure is externalized. This is useful if the same figure should be externalized again. This code is a modified copy of \cmd{\tikzexternal@getnextfilename@advancecount} from file tikzexternalshared.code.tex.
+% \begin{macrocode}
+\def\tikzscale@decreaseFigureCounter{%
+% \end{macrocode}
+% Use a group, so that the used counter register is not changed outside of this macro. This is necessary, as the global figure counter is not saved in a counter as one might think, but in a macro, so it must be copied to a local counter in order to be easily modified.
+% \begin{macrocode}
+ \begingroup
+% \end{macrocode}
+ % Get the name of the macro holding the figure counter value.
+% \begin{macrocode}
+ \edef\macroName{c@tikzext@no@\pgfkeysvalueof{/tikz/external/figure name}}%
+% \end{macrocode}
+ % Use a TeX counter and store the figure counter value therein.
+% \begin{macrocode}
+% \c@pgf@counta=\csname\macroName\endcsname\relax
+ \c@pgf@counta=\csuse{\macroName}\relax
+% \end{macrocode}
+ % Decrease the value of the local counter.
+% \begin{macrocode}
+ \advance\c@pgf@counta -1\relax
+% \end{macrocode}
+ % Save the value of the local counter back to the global counter macro.
+% \begin{macrocode}
+ \expandafter\xdef\csname\macroName\endcsname{\the\c@pgf@counta}%
+ \endgroup
+}%
+% \end{macrocode}
+%\end{macro}
+%
%\begin{macro}{\tikzscale@resizePlotTo}
%\xcmd\tikzscale@resizePlotTo{file name}
% \begin{macrocode}
@@ -1314,16 +1432,16 @@ and the derived files tikzscale.ins,
}%
}%
% \end{macrocode}
- % Externalize the graphic with the final size.
-% \begin{macrocode}
- \tikzscale@conditionalEnableExternalization{\fileName}%
-% \end{macrocode}
- % Finally, include the picture. Do it via a new measurement to be able to warn if it does not fit good enough.
+ % Do a last measurement to be able to warn if the size does not fit good enough. This measurement has to be done before possibly reactivating the externalization, as measurements with activated externalization can lead to wrong measurement results (possibly due to calling \cmd{\shipout} inside of the measurement). The assumption is, that the real graphic size does not change if the externalization gets activated, which all tests seem to confirm.
% \begin{macrocode}
\sbox{\tikzscale@measuredSize}{\content}%
- \usebox{\tikzscale@measuredSize}%
\tikzscale@warnIfSizeDifference{\requestedWidth}{\wd\tikzscale@measuredSize}{\fileName's width}%
\tikzscale@warnIfSizeDifference{\requestedHeight}{\ht\tikzscale@measuredSize}{\fileName's height}%
+% \end{macrocode}
+ % Finally, externalize and include the graphic with the final size. The graphic must not be include by reusing the measuredSize-box, as this leads to a subtly wrong behaviour when generating the PDF files. It can be observed by running the test suite with externalization and checking that no file is regenerated in the second run. Reusing the box can also lead to compile errors, if the problematic graphic is the last graphic in the document.
+% \begin{macrocode}
+ \tikzscale@conditionalEnableExternalization{\fileName}%
+ \content%
}
% \end{macrocode}
%\end{macro}
@@ -1361,7 +1479,7 @@ and the derived files tikzscale.ins,
% Optimize if the absolute difference is too large.
% \begin{macrocode}
\tikzscale@ifSizeDifference{\sizeDifference}{%
- \ifdefstring{\dimension}{\wd}{%
+ \tikzscale@ifIsWidth{\dimension}{%
\pgfmathsetglobalmacro{\tikzscale@width}{\tikzscale@width - \sizeDifference}%
\pgfmathsetglobalmacro{\tikzscale@height}{\tikzscale@width / \requestedAxisRatio}%
}{%
@@ -1387,21 +1505,30 @@ and the derived files tikzscale.ins,
\global\undef\tikzscale@alreadyIncluded%
}{%
% \end{macrocode}
- % Externalize the graphic with the final size.
-% \begin{macrocode}
- \tikzscale@conditionalEnableExternalization{\fileName}%
-% \end{macrocode}
- % Finally, include the picture. Do it via a new measurement to be able to warn if it does not fit good enough.
+ % Do a last measurement to be able to warn if the size does not fit good enough. This measurement has to be done before possibly reactivating the externalization, as measurements with activated externalization can lead to wrong measurement results (possibly due to calling \cmd{\shipout} inside of the measurement). The assumption is, that the real graphic size does not change if the externalization gets activated, which all tests seem to confirm.
% \begin{macrocode}
\tikzscale@measureSize{\measuredFinal}{\dimension}{\content}%
- \usebox{\tikzscale@measuredSize}%
\tikzscale@warnIfSizeDifference{\measuredFinal}{\requestedSize}{\fileName}%
+% \end{macrocode}
+ % Finally, externalize and include the graphic with the final size. The graphic must not be include by reusing the measuredSize-box, as this leads to a subtly wrong behaviour when generating the PDF files. It can be observed by running the test suite with externalization and checking that no file is regenerated in the second run. Reusing the box can also lead to compile errors, if the problematic graphic is the last graphic in the document.
+% \begin{macrocode}
+ \tikzscale@conditionalEnableExternalization{\fileName}%
+ \content%
}%
}
% \end{macrocode}
%\end{macro}
%
-%\begin{macro}{\tikzscale@measuredSize}
+%\begin{macro}{\tikzscale@ifIsWidth}
+% \xcmd\tikzscale@ifIsWidth{condition}{true}{false}
+% \begin{macrocode}
+\def\tikzscale@ifIsWidth#1{%
+ \ifedefequal{#1}{\wd}%
+}
+% \end{macrocode}
+%\end{macro}
+%
+%\begin{macro}{\tikzscale@measureSize}
% \begin{macrocode}
\newsavebox{\tikzscale@measuredSize}
% \end{macrocode}
@@ -1446,7 +1573,7 @@ and the derived files tikzscale.ins,
\tikzscale@ifExternalizationActive{%
\tikzexternaldisable
\def\tikzscale@externalizationWasDisabled{}%
- }{}
+ }{}%
% \end{macrocode}
% Restore the endlinechar here and not in the general \cmd{\tikzexternaldisable} code, as it should only be restored if \cmd{\includegraphics} had been called and not if a tikzpicture was called directly without using \cmd{\includegraphics}. If the externalization has not been loaded, the endlinechar would be redefined twice (which would probably also do not much harm).
% \begin{macrocode}
diff --git a/Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty b/Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty
index 3359cd5db86..fac78df85a3 100644
--- a/Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty
+++ b/Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty
@@ -13,7 +13,7 @@
%% ----------------------------------------------------------------
%%
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{tikzscale}[2013/03/30 v0.2.5 tikzscale LaTeX package]
+\ProvidesPackage{tikzscale}[2013/05/22 v0.2.6 tikzscale LaTeX package]
\RequirePackage{graphicx}
\RequirePackage{etoolbox}
\RequirePackage{pgfkeys}
@@ -35,6 +35,11 @@
\def\ifExternalizationLoaded#1#2{%
\ifTikzLibraryLoaded{external}{#1}{#2}%
}
+\def\ifedefequal#1#2{%
+\edef\etoolbox@ifedefequal@first{#1}%
+\edef\etoolbox@ifedefequal@second{#2}%
+\ifdefequal{\etoolbox@ifedefequal@first}{\etoolbox@ifedefequal@second}%
+}
\def\edocsvlist#1{%
\edef\tikzscale@edocsvlist{#1}%
\expandafter\docsvlist\expandafter{\tikzscale@edocsvlist}%
@@ -124,6 +129,7 @@
#2%
}%
}%
+\def\tikzscale@debug#1{}%
\AtEndPreamble{%
\def\tikzscale@tikzFileExtensions{.tikz,.TIKZ,.TikZ,.pgf,.PGF}%
\DeclareGraphicsExtensions{\tikzscale@tikzFileExtensions,\Gin@extensions}%
@@ -154,13 +160,16 @@
\def\pgf@externalend@storeshifts#1{%
\tikzscale@externalend@storeshifts{#1}%
\ifpgfexternal@info
-\ifdef{\requestedAxisRatio}{%
-\immediate\write#1{\noexpand\pgfexternal@restore{\noexpand\def\noexpand\tikzscale@oldAxisRatio{\requestedAxisRatio}}}%
-}{}%
+\tikzscale@writeToDpth{#1}{\tikzscale@oldAxisRatio}{\requestedAxisRatio}%
\fi
}%
}{}%
}
+\def\tikzscale@writeToDpth#1#2#3{%
+\ifdef{#3}{%
+\immediate\write#1{\noexpand\pgfexternal@restore{\noexpand\def\noexpand#2{#3}}}%
+}{}%
+}
\NewDocumentCommand{\tikzscale@includegraphics}{O{}m}{%
\begingroup
\LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}%
@@ -262,30 +271,36 @@ axisratio/.value required
\pgfkeys{/tikzscale, #1}%
\tikzscale@ifExternalizationActive{%
\tikzifexternalizingnext{%
-\tikzscale@includetikzUnexternalized[#1]{#2}%
+\tikzscale@debug{Externalizing the file #2}%
+\tikzscale@includetikzUnexternalized{#2}%
}{%
\tikzscale@includetikzWithExternalization{#2}%
}%
}{%
-\tikzscale@includetikzUnexternalized[#1]{#2}%
+\tikzscale@includetikzUnexternalized{#2}%
}%
}
-\NewDocumentCommand{\tikzscale@includetikzUnexternalized}{O{}m}{%
+\def\tikzscale@includetikzUnexternalized#1{%
\elseif{test {\ifundef{\requestedWidth}} and test {\ifundef{\requestedHeight}} and test {\ifundef{\requestedAxisRatio}}}{%
-\tikzscale@trim{\input{#2}}%
+\tikzscale@debug{no option given}%
+\tikzscale@trim{\input{#1}}%
}{test {\ifdef{\requestedWidth}} and test {\ifdef{\requestedHeight}}}{%
-\tikzscale@resizePlotTo{#2}%
+\tikzscale@debug{width and height given}%
+\tikzscale@resizePlotTo{#1}%
}{test {\ifdef{\requestedAxisRatio}}}{%
-\tikzscale@includeAxisRatio{#2}%
+\tikzscale@debug{axis ratio given}%
+\tikzscale@includeAxisRatio{#1}%
}{test {\ifundef{\requestedAxisRatio}}}{%
+\tikzscale@debug{width or height given}%
\ifdef{\pgfplotsset}{%
\def\requestedAxisRatio{1}%
-\tikzscale@includeAxisRatio{#2}%
+\tikzscale@includeAxisRatio{#1}%
}{%
-\tikzscale@includeNormalTikzpicture{#2}%
+\tikzscale@debug{no pgfplots loaded}%
+\tikzscale@includeNormalTikzpicture{#1}%
}%
}{%
-\tikzscale@invalidKeyError{#2}%
+\tikzscale@invalidKeyError{#1}%
}%
}
@@ -302,29 +317,34 @@ axisratio/.value required
\ifdef{\pgfexternalwidth}{%
\tikzscale@ifSizeDifference{\requestedWidth - \pgfexternalwidth}{%
\tikzset{external/remake next}%
+\tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of width difference \MessageBreak (requestedWidth=\requestedWidth, pgfexternalwidth=\pgfexternalwidth)}%
}{}%
}{%
\tikzset{external/remake next}%
+\tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of no external width}%
}%
}{}%
\ifdef{\requestedHeight}{%
\ifdef{\pgfexternalheight}{%
\tikzscale@ifSizeDifference{\requestedHeight - \pgfexternalheight}{%
\tikzset{external/remake next}%
+\tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of height difference \MessageBreak (requestedHeight=\requestedHeight, pgfexternalheight=\pgfexternalheight)}%
}{}%
}{%
\tikzset{external/remake next}%
+\tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of no external height}%
}%
}{}%
\ifdef{\requestedAxisRatio}{%
\ifdef{\tikzscale@oldAxisRatio}{%
\tikzscale@ifSizeDifference{\requestedAxisRatio - \tikzscale@oldAxisRatio}{%
\tikzset{external/remake next}%
+\tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of axis ratio difference \MessageBreak (requestedAxisRatio=\requestedAxisRatio, oldAxisRatio=\tikzscale@oldAxisRatio)}%
}{}%
\undef{\tikzscale@oldAxisRatio}%
}{%
\tikzset{external/remake next}%
-\PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of no external axis ratio}%
+\tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of no external axis ratio}%
}%
}{}%
}
@@ -366,6 +386,7 @@ axisratio/.value required
}%
}
\NewDocumentCommand{\tikzscale@scaleTikzpictureTo}{mmm}{%
+\tikzscale@debug{At beginning scale, requestedWidth=\requestedWidth}%
\tikzscale@conditionalDisableExternalization
\def\tikzscale@scale{1}%
\tikzscale@measureSize{\measuredFirst}{#1}{#2}%
@@ -382,20 +403,52 @@ axisratio/.value required
\tikzscale@measureSize{\measuredIntermediate}{#1}{#2}%
\tikzscale@ifSizeDifference{\measuredIntermediate-\requestedSize}{%
\pgfmathsetmacro{\errorRatio}{\measuredIntermediate/\requestedSize}%
+\tikzscale@debug{errorRatio=\errorRatio\MessageBreak for #3}%
\pgfmathsetglobalmacro{\tikzscale@scale}{\tikzscale@scale/\errorRatio}%
}{%
\breakforeach%
}%
}%
-\tikzscale@conditionalEnableExternalization{#3}%
+ % Do a last measurement to be able to warn if the size does not fit good enough. This measurement has to be done before possibly reactivating the externalization, as measurements with activated externalization can lead to wrong measurement results (possibly due to calling \cmd{\shipout} inside of the measurement). The assumption is, that the real graphic size does not change if the externalization gets activated, which all tests seem to confirm.
\tikzscale@measureSize{\measuredFinal}{#1}{#2}%
-\usebox{\tikzscale@measuredSize}%
\tikzscale@warnIfSizeDifference{\measuredFinal}{\requestedSize}{#3}%
+\tikzscale@testGraphicFileForRetry{#1}{#2}{#3}{\measuredFinal}%
}{%
+\tikzscale@testGraphicFileForRetry{#1}{#2}{#3}{\measuredSecond}%
+}%
+}
+\def\tikzscale@testGraphicFileForRetry#1#2#3#4{%
\tikzscale@conditionalEnableExternalization{#3}%
+\tikzscale@ifExternalizationActive{%
+\tikzexternalgetnextfilename{\tikzscale@externalizationName}%
+}{}%
#2%
+\tikzscale@ifExternalizationActive{%
+\pgfexternalreaddpth{\tikzscale@externalizationName}%
+\tikzscale@ifIsWidth{#1}{%
+\edef\pgfexternalsize{\pgfexternalwidth}%
+}{%
+\edef\pgfexternalsize{\pgfexternalheight}%
}%
+\ifundef{\originalRequestedSize}{%
+\let\originalRequestedSize\requestedSize
+}{}%
+\tikzscale@debug{originalRequestedSize=\originalRequestedSize, requestedSize=\requestedSize, pgfexternalsize=\pgfexternalsize}%
+\tikzscale@ifSizeDifference{\originalRequestedSize-\pgfexternalsize}{%
+\pgfmathsetmacro{\requestedSize}{\requestedSize + #4 - \pgfexternalsize}%
+\tikzscale@decreaseFigureCounter
+\tikzscale@scaleTikzpictureTo{#1}{#2}{#3}%
+}{}%
+}{}%
}
+\def\tikzscale@decreaseFigureCounter{%
+\begingroup
+\edef\macroName{c@tikzext@no@\pgfkeysvalueof{/tikz/external/figure name}}%
+\c@pgf@counta=\csuse{\macroName}\relax
+\advance\c@pgf@counta -1\relax
+\expandafter\xdef\csname\macroName\endcsname{\the\c@pgf@counta}%
+\endgroup
+}%
\NewDocumentCommand{\tikzscale@resizePlotTo}{m}{%
\def\fileName{#1}%
\def\content{\tikzscale@trim{\input{#1}}}%
@@ -414,11 +467,11 @@ axisratio/.value required
\breakforeach
}%
}%
-\tikzscale@conditionalEnableExternalization{\fileName}%
\sbox{\tikzscale@measuredSize}{\content}%
-\usebox{\tikzscale@measuredSize}%
\tikzscale@warnIfSizeDifference{\requestedWidth}{\wd\tikzscale@measuredSize}{\fileName's width}%
\tikzscale@warnIfSizeDifference{\requestedHeight}{\ht\tikzscale@measuredSize}{\fileName's height}%
+\tikzscale@conditionalEnableExternalization{\fileName}%
+\content%
}
\NewDocumentCommand{\tikzscale@resizePlotWithAxesRatioTo}{mmmm}{%
@@ -433,7 +486,7 @@ axisratio/.value required
\tikzscale@measureSize{\measuredSize}{\dimension}{\content}%
\pgfmathsetmacro{\sizeDifference}{\measuredSize - \requestedSize}%
\tikzscale@ifSizeDifference{\sizeDifference}{%
-\ifdefstring{\dimension}{\wd}{%
+\tikzscale@ifIsWidth{\dimension}{%
\pgfmathsetglobalmacro{\tikzscale@width}{\tikzscale@width - \sizeDifference}%
\pgfmathsetglobalmacro{\tikzscale@height}{\tikzscale@width / \requestedAxisRatio}%
}{%
@@ -455,12 +508,16 @@ axisratio/.value required
\ifdef{\tikzscale@alreadyIncluded}{%
\global\undef\tikzscale@alreadyIncluded%
}{%
-\tikzscale@conditionalEnableExternalization{\fileName}%
+ % Do a last measurement to be able to warn if the size does not fit good enough. This measurement has to be done before possibly reactivating the externalization, as measurements with activated externalization can lead to wrong measurement results (possibly due to calling \cmd{\shipout} inside of the measurement). The assumption is, that the real graphic size does not change if the externalization gets activated, which all tests seem to confirm.
\tikzscale@measureSize{\measuredFinal}{\dimension}{\content}%
-\usebox{\tikzscale@measuredSize}%
\tikzscale@warnIfSizeDifference{\measuredFinal}{\requestedSize}{\fileName}%
+\tikzscale@conditionalEnableExternalization{\fileName}%
+\content%
}%
}
+\def\tikzscale@ifIsWidth#1{%
+\ifedefequal{#1}{\wd}%
+}
\newsavebox{\tikzscale@measuredSize}
\def\tikzscale@measureSize#1#2#3{%
\sbox{\tikzscale@measuredSize}{#3}%
@@ -484,7 +541,7 @@ axisratio/.value required
\tikzscale@ifExternalizationActive{%
\tikzexternaldisable
\def\tikzscale@externalizationWasDisabled{}%
-}{}
+}{}%
\ifExternalizationLoaded{%
\tikzscale@addRestoreEndLineCharToTikzpicture
}{}%