summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-01-03 23:32:34 +0000
committerKarl Berry <karl@freefriends.org>2013-01-03 23:32:34 +0000
commit0742ba6b44d3acf70563c8d4d7611cbb209641d7 (patch)
tree56eef89f369c8a61e17887f024ad40abd696231d /Master
parentc2de5f2979b063faba1573870b6b21419cb8b0fa (diff)
tikzscale (3jan13)
git-svn-id: svn://tug.org/texlive/trunk@28716 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.pdfbin127846 -> 144073 bytes
-rw-r--r--Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.tex14
-rw-r--r--Master/texmf-dist/doc/latex/tikzscale/tikzscale.pdfbin350047 -> 355869 bytes
-rw-r--r--Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx260
-rw-r--r--Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty121
5 files changed, 279 insertions, 116 deletions
diff --git a/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.pdf b/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.pdf
index 16cd3643485..aa4fb0f126f 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 5048b3a76cf..4678563c9d6 100644
--- a/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.tex
+++ b/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.tex
@@ -9,8 +9,8 @@
% Load the MWE package, although its functionality is not needed. The loading highlights, that some graphics used below are part of the MWE package.
\usepackage{mwe}
-% \usepgfplotslibrary{external}
-% \tikzexternalize
+\usetikzlibrary{external}
+\tikzexternalize
% \tikzexternalize[mode=list and make]
\begin{document}
@@ -42,7 +42,7 @@
\includegraphics[width=\linewidth]{example-grid-100x100bp.jpg}%
\item Use \texttt{input} with pgfplots\\%
\input{pgfplots-test.tikz}%
- \item Input a 2D pgfplots
+ \item Input a 2D pgfplots\\
\input{testgraphic2D.tikz}%
\item Use pgfplots without optional parameter\\%
\includegraphics{pgfplots-test}%
@@ -57,7 +57,13 @@
\item Use includegraphics with a scaled two dimensional plot with line width and an axis ratio of 1\\%
\includegraphics[width=\linewidth,axisratio=1]{testgraphic2D.tikz}%
\item Use includegraphics with a scaled two dimensional plot with given height and an axis ratio of 0.5\\%
- \includegraphics[height=1\linewidth,axisratio=0.5]{testgraphic2D.tikz}%
+ \includegraphics[height=\linewidth,axisratio=0.5]{testgraphic2D.tikz}%
+ \item Use includegraphics with a scaled two dimensional plot with given height and an axis ratio of 0.5 and temporarily deactivated externalization\\%
+ \tikzexternaldisable
+ \includegraphics[height=\linewidth,axisratio=0.5]{testgraphic2D.tikz}%
+ \tikzexternalenable
+ \item Use includegraphics with a scaled two dimensional plot with given height and an axis ratio of 0.5 again\\%
+ \includegraphics[height=\linewidth,axisratio=0.5]{testgraphic2D.tikz}%
\item Use includegraphics with a scaled two dimensional plot with line width and a default axis ratio\\%
\includegraphics[width=\linewidth]{testgraphic2D.tikz}%
\item Input a two dimensional plot with a tight frame with width \newlength{\mylen}\settowidth{\mylen}{\frame{\input{testgraphic2D.tikz}}}\the\mylen\\%
diff --git a/Master/texmf-dist/doc/latex/tikzscale/tikzscale.pdf b/Master/texmf-dist/doc/latex/tikzscale/tikzscale.pdf
index adfa36e300f..ffed4140d0d 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 86edfbf42d4..adea32dc79e 100644
--- a/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx
+++ b/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx
@@ -95,7 +95,7 @@ and the derived files tikzscale.ins,
%</internal>
%<*package>
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{tikzscale}[2012/11/03 v0.1.3 tikzscale LaTeX package]
+\ProvidesPackage{tikzscale}[2013/01/02 v0.2 tikzscale LaTeX package]
\RequirePackage{graphicx}
\RequirePackage{etoolbox}
\RequirePackage{pgfkeys}
@@ -187,6 +187,7 @@ and the derived files tikzscale.ins,
%\changes{v0.1.1}{2012/11/02}{Fix some bugs, increase robustness, regenerate externalized files less often}
%\changes{v0.1.2}{2012/11/02}{Fix whitespace issues}
%\changes{v0.1.3}{2012/11/02}{Fix error when loading TikZ but not PGFPlots; Fix error when scaling complicated TikZ graphics}
+%\changes{v0.2}{2013/01/02}{Add default axis ratio; save axis ratio; support \cmd{\externaldisable} and \cmd{\externalenable}; improve robustness; increase speed}
% \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}
@@ -245,9 +246,9 @@ and the derived files tikzscale.ins,
%
% The tikzscale package adds and improves certain forms of absolute scaling for TikZ and PGFPlots, respectively. These scaling methods are the ones which are most useful, maybe even the only ones which are needed. During the scaling, the text sizes and line widths are left unscaled, which avoids inconsistency and visual distraction. PGFPlots itself can scale absolutely, but an approximation is used to achieve that. The tikzscale package uses optimization algorithms and warns if the scaling is not exact.
%
-% Using tikzscale all relevant scaling methods share the same user interface with the well known \cmd{\includegraphics} command, enabling some of its features like automatic file extension detection for TikZ and PGFPlots, too. Furthermore, the \cmd{\includegraphics} is improved to look-up relative paths in the correct subdirectory, if a \LaTeX\ project is organized in subdirectories.
+% Using tikzscale all relevant scaling methods share the same user interface with the well known \cmd{\includegraphics} command, enabling some of its features like automatic file extension detection for TikZ and PGFPlots, too. Furthermore, the \cmd{\includegraphics} command is improved to look-up relative paths in the correct subdirectory, if a \LaTeX\ project is organized in subdirectories.
%
-% Relative scaling methods are mostly useless, as the sizes of the used images are often arbitrary, either determined by some resolution for rastered images or some arbitrary unit vector size for vector images, TikZ and PGFPlots. For traditional images and TikZ pictures, only proportional scaling methods giving either a width or a height make sense, as otherwise they get heavily distorted if the original aspect ratio is changed. As PGFPlots can handle different aspect ratios and aspect ratios are normally not predefined for plots, its requirement is the opposite: A width and a height are needed to avoid getting arbitrary sizes. For some special plots, the axis ratio can be given, as well. These requirements lead to the marked blue colors in table \ref{scalingDemands}.
+% Relative scaling methods are mostly useless, as the sizes of the used images are often arbitrary, either determined by some resolution for rastered images or some arbitrary unit vector size for vector images, TikZ and PGFPlots. For traditional images and TikZ pictures, only proportional scaling methods giving either a width or a height make sense, as otherwise they get heavily distorted if the original aspect ratio is changed. As PGFPlots can handle different aspect ratios and aspect ratios are normally not predefined for plots, its requirement is the opposite: Both width and height are needed to avoid getting arbitrary sizes. For some special plots, the axis ratio can be given, as well. These requirements lead to the marked blue colors in table \ref{scalingDemands}.
%
% \section{Usage and Examples}
% Loading the tikzscale package without loading other packages, does not do anything useful.
@@ -287,7 +288,8 @@ and the derived files tikzscale.ins,
%
% \subsection{PGFPlots}
% \subsubsection{Scaling of width and height}
-% If the pgfplots package is loaded together with the tikzscale package, the user interface is the same. Instead of giving either a width or a height, both have to be given for pgfplots. So
+% If the pgfplots package is loaded together with the tikzscale package, the user interface is the same. Instead of giving either a width or a height, both have to be given for pgfplots. Otherwise a default axis ratio is assumed (see section \ref{axisRatio}).\\
+% So,\nopagebreak
%
% \vspace{0.5em}
% \cmd{\input\{pgfplots-test.tikz\}}
@@ -302,12 +304,12 @@ and the derived files tikzscale.ins,
% \cmd{\includegraphics[width=3cm,height=2cm]\{pgfplots-test.tikz\}}
%
% \vspace{0.5em}
-% \texttt{\cmd{\begin}\{tikzpicture\}\cmd{\begin}\{axis\} \dots}
+% \texttt{\cmd{\begin}\{tikzpicture\}\cmd{\begin}\{axis\} \dots}.
% \vspace{0.5em}
%
% The benefit is a more accurate scaling algorithm, as the scaling with PGFPlots can be quite coarse. Another win is the unified interface, which simplifies the sharing of plots between projects enormously, as one file and thus one plot can be included in different projects with different sizes.
%
-% \subsubsection{Scaling using axis ratio}
+% \subsubsection{Scaling using axis ratio}\label{axisRatio}
% The scaling described in the previous section scales the whole plot including all axis descriptions and legends to the given width and height. It can thus happen, that the plotted figure has a different size ratio than expected, if the x and y descriptions have different sizes as shown in figure \ref{width=height}.
% \begin{figure}
% \centering
@@ -315,7 +317,9 @@ and the derived files tikzscale.ins,
% \caption{Using options \texttt{width=0.4\cmd{\linewidth}} and \texttt{height=0.4\cmd{\linewidth}} results in an overall quadratic graphic with overall width and height set to 40\% of the linewidth.}
% \label{width=height}
% \end{figure}
-% Sometimes, the x-axis and the y-axis should have a specific ratio, e.g. being equal, ignoring the axis description and other things. This is normally achieved by using PGFPlots' option \texttt{scale only axis}. Unfortunately, if this option would be used, a plot might be unsharable between two projects, if they have different requirements for the axis ratio. Thus, this option should not be used in this case. Instead, in \cmd{\includegraphics} there is a new option \texttt{axisratio} which must be used together with either width or height. It scales the whole plot including the axis description to the given width or height as in figure \ref{axisratio} while keeping the graphical part at a given axis ratio, where the ratio is defined by width divided by height. The graphical part is thus not quadratic in general.
+% Sometimes, the x-axis and the y-axis should have a specific ratio, e.g. being equal, ignoring the axis description and other things. This is normally achieved by using PGFPlots' option \texttt{scale only axis}. Unfortunately, if this option would be used, a plot might be unsharable between two projects, if they have different requirements for the axis ratio. Thus, this option should not be used in such a case.
+%
+% Instead, in \cmd{\includegraphics} there is a new option \texttt{axisratio} which must be used together with either width or height. It scales the whole plot including the axis description to the given width or height as in figure \ref{axisratio} while keeping the graphical part at a given axis ratio, where the ratio is defined by width divided by height. The graphical part is thus not quadratic in general. If \texttt{axisratio} is omitted, i.e. only either height or width are given, it is assumed to be \texttt{1}.
% \begin{figure}
% \centering
% \frame{\includegraphics[width=0.4\linewidth,axisratio=1]{testgraphic2D.tikz}}
@@ -326,7 +330,7 @@ and the derived files tikzscale.ins,
%
% \subsection{Hints for TikZ and PGFPlots}
-% The whole tikzpicture environment must be in a separate file. This allows sharing of graphics between different \TeX\ projects and a unified user interface via \cmd{\includegraphics}. Having tikzpicture environments directly in a .tex-file is not supported, i.e.\ they do not benefit from the tikzscale package. Multiple tikzpicture environments in one .tikz-file are not supported, either. Put things which always belong together in a shared tikzpicture environment and things which might be used separately in the future in separate files for code sharing across projects. The file ending may be ommited in the \cmd{\includegraphics} command, if it is one of .tikz, .TIKZ, .TikZ, .pgf or .PGF. At the moment, use only \emph{either} width \emph{or} height for normal (i.e.\ non-PGFPlots) tikzpicture environments and use width \emph{and} height or one of both together with \emph{axisratio} for tikzpicture environments containing a PGFPlots' axis environment.
+% The whole tikzpicture environment must be in a separate file. This allows sharing of graphics between different \TeX\ projects and a unified user interface via \cmd{\includegraphics}. Having tikzpicture environments directly in a .tex-file is not supported, i.e.\ they do not benefit from the tikzscale package. Multiple tikzpicture environments in one .tikz-file are not supported, either. Put things which always belong together in a shared tikzpicture environment and things which might be used separately in the future in separate files for code sharing across projects. The file ending may be ommited in the \cmd{\includegraphics} command, if it is one of .tikz, .TIKZ, .TikZ, .pgf or .PGF. At the moment, use only \emph{either} width \emph{or} height for normal (i.e.\ non-PGFPlots) tikzpicture environments and use width \emph{and} height or one of both optionally together with \emph{axisratio} for tikzpicture environments containing a PGFPlots' axis environment.
%
% \subsection{currfile}
% If the tikzpicture package is loaded together with the \href{http://www.ctan.org/pkg/currfile}{currfile} package, another feature is activated. Suppose you have your project organized in the following directory tree with \textcolor{blue}{directories} shown in blue color:
@@ -357,6 +361,8 @@ and the derived files tikzscale.ins,
% \section{Compatibility}
% Using both the externalization library and tikzscale seems to have a race condition when a makefile is used with multiple jobs (-j$X$ with $X > 1$). The probability of getting errors increases with the number of jobs. For $X = 1$, obviously, no race condition could be observed. You should either avoid using mode \emph{list and make} or have only one job if you want to be on the safe side.
%
+% Note, that there was a \href{http://tex.stackexchange.com/a/88158/7323}{bug} in the externalization library, which has been fixed on 25th of December in 2012, so you might want to use a more recent version of TikZ of PGFPlots.
+%
% \subsection{Load Order}
% There is no constraint regarding the load order known, yet. TikZ, PGFPlots and currfile might all be loaded or not in all possible combinations and orders before or after tikzscale.
%
@@ -365,11 +371,13 @@ and the derived files tikzscale.ins,
%
% \section{Further Ideas}
% \begin{itemize}
-% \item When the externalization library is used, the graphic files get regenerated more often than necessary. This is, because the axis ratio is not saved, thus assumed unknown and the graphic is thus regenerated. For performance reasons if a default axis ratio is used, the plot is not regenerated. If a non-default axis ratio has been used for generating the externalized graphic and the default axis ratio is used in the current run, this is not detected and the graphic has the wrong size at the moment. You can, of course, delete the externalized graphic to generate a new one with the correct size.
+% \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.
% \item the package can test if a pgfplot is used (needed if normal TikZ graphics should be stretchable) by changing \cmd{\tikzscale@width} and or \cmd{\tikzscale@height} and measuring. If nothing changes, it must be a normal tikzpicture (the argument does not hold the other way round).
% \item it may be better to use the \href{http://tex.stackexchange.com/a/22957}{depth as well}
-% \item The final sizing parameters should be saved per figure in the aux file. The first rendering each run should be performed with the aux file's parameters into an sbox. The scaling algorithms should only be called, if the sizing requirements are not met.
+% \item The final sizing parameters should be saved per figure in the aux file. The first rendering each run should be performed with the aux file's parameters into an sbox. The scaling algorithms should only be called, if the sizing requirements are not met. The purpose is similar to the externalization library.
+% \item Using something like [x=5pt] as an argument to the axis environment, e.g. to scale the units in bar plots, is problematic, as tikzscale changes the behaviour, i.e. stops the scaling.
% \end{itemize}
%
% \section{Contributions}
@@ -382,6 +390,7 @@ and the derived files tikzscale.ins,
% \begin{itemize}
% \item Encouraged the author to create this package and created PGFPlots.
% \item Answered many questions and had a lot of good ideas regarding the externalization and beyond.
+% \item Fixed problems in the externalization library when used with tikzscale.
% \end{itemize}
% \item David Carlisle
% \begin{itemize}
@@ -392,6 +401,10 @@ and the derived files tikzscale.ins,
% \item Reported a bug when not using TikZ without PGFPlots, which lead to a fix.
% \item Reported a bug that a non-existent macro is used, which lead to a fix.
% \end{itemize}
+% \item devendra
+% \begin{itemize}
+% \item Reported bugs when using the externalization library together with tikzscale, which lead to a fix.
+% \end{itemize}
% \end{itemize}
%
%
@@ -407,9 +420,9 @@ and the derived files tikzscale.ins,
% \begin{macrocode}
\AtEndPreamble{%
% \end{macrocode}
- % Activate the output of the graphics sizes into the dpth files (one file per graphic). This key is used if the externalization library is activated to check if the scaling is correct, otherwise the code is not needed
+ % Activate the output of the graphics sizes into the dpth files (one file per graphic). This key is used if the externalization library is activated to check if the scaling is correct, otherwise the code is not needed.
% \begin{macrocode}
- \ifdef{\tikzifexternalizing}{%
+ \ifExternalizationLoaded{%
\pgfkeys{/pgf/images/external info}%
}{}%
% \end{macrocode}
@@ -419,33 +432,38 @@ and the derived files tikzscale.ins,
\ProvideDocumentCommand{\tikzsetexternalprefix}{m}{}%
\ProvideDocumentCommand{\tikzexternaldisable}{}{}%
\ProvideDocumentCommand{\tikzexternalenable}{}{}%
- \ProvideDocumentCommand{\tikzexternalize@hasbeencalled}{}{0}%
-% \end{macrocode}
- % Define a test to check if the current graphic should be drawn and scaled.
-% \begin{macrocode}
- \ifboolexpr{test {\ifundef{\tikzexternalize}} or test {\ifdefstring{\tikzexternalize@hasbeencalled}{0}}}{%
% \end{macrocode}
- % Always draw and scale the graphic if externalization library has not been loaded or not been activated.
+ % The check \cmd{\tikzifexternalizehasbeencalled} from file tikzexternalshared.code.tex is not exactly what is needed in tikzscale, as it always stays true after it has been set by \cmd{\tikzexternalize}. Instead, add a check whether externalization is active and set it to false if externalization has not been loaded for simplification. Thus, whether externalization is active can be checked without checking if it has been loaded at all. The initial state of \cmd{\tikzscale@externalizationActive} is not trivially known, as an arbitrary combination and order of \cmd{\tikzexternaldisable} and \cmd{\tikzexternalenable} commands could have been used before the end of the preamble. In the long run, tikzexternalshared.code.tex should offer that check. Until then, we can check whether \cmd{\tikz}=\cmd{\tikzexternal@origtikz} (i.e. externalization disabled) or \cmd{\tikz}=\cmd{\tikzexternal@tikz@replacement} (i.e. externalization enabled) holds (if neither of both holds, this indicates a problem, e.g. another package redefining the command). This is, of course, only needed if the externalization library has been loaded at all. Please note, the implementation of this check as a macro is possible, because tikzscale redefines tikzpicture, whereas the externalization library redefines tikz, so there is no conflict.
% \begin{macrocode}
- \def\tikzscale@ifDrawAndScale#1#2{#1}%
- }{%
+ \def\tikzscale@ifExternalizationActive#1#2{%
+ \ifExternalizationLoaded{%
+ \ifdefequal{\tikz}{\tikzexternal@tikz@replacement}{%
+ #1%
+ }{%
+ \ifdefequal{\tikz}{\tikzexternal@origtikz}{%
+ }{%
+ \PackageWarning{tikzscale}{Status of externalization is unknown, thus I assume it is deactivated.}%
+ }%
% \end{macrocode}
- % If externalization library has been loaded and activated, draw and scale the graphic if it is to be externalized.
+ % It's important, that this code is below the above code, as the below code can change the meaning of \cmd{\tikz} through side effects.
% \begin{macrocode}
- \def\tikzscale@ifDrawAndScale#1#2{%
- \tikzifexternalizingnext{#1}{#2}%
+ #2%
+ }%
+ }{%
+ #2%
}%
}%
+% \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tikzscale@scale}
% \begin{macrocode}
\@ifpackageloaded{tikz}{%
% \end{macrocode}
- % Set a minimum accuracy tikzscale tries to achieve. TeX's accuracy is limited, thus 0.001 pt cannot always be achieved independent of the number of iterations. The current value is chosen arbitrarily, but it might have to be increased in case a plot is found where the given accuracy cannot be achieved.
+ % Set a minimum accuracy tikzscale tries to achieve. TeX's accuracy is limited, thus, e.g. 0.04 pt, cannot always be achieved independent of the number of iterations. Use the \href{http://en.wikibooks.org/wiki/TeX/hfuzz}{value} (0.1 pt in an experiment) which is used for overfull paragraph warnings, too.
% \begin{macrocode}
\newlength{\tikzscale@accuracy}%
- \setlength{\tikzscale@accuracy}{0.01pt}%
+ \setlength{\tikzscale@accuracy}{\hfuzz}%
% \end{macrocode}
% This is needed in normal TikZ pictures and in PGFPlots, but as the pgfplots package loads the tikz package, it is fine to define it here.
% \begin{macrocode}
@@ -471,6 +489,27 @@ and the derived files tikzscale.ins,
% \end{macrocode}
%\end{macro}
%
+%\begin{macro}{\ifTikzLibraryLoaded}
+% This is a general command, which might be useful for inclusion into the tikz package. This is taken from \href{http://tex.stackexchange.com/a/48472}{stackexchange} and simplified.
+% \begin{macrocode}
+\def\ifTikzLibraryLoaded#1#2#3{%
+ \ifcsdef{tikz@library@#1@loaded}{%
+ #2%
+ }{%
+ #3%
+ }%
+}
+% \end{macrocode}
+%\end{macro}
+%
+%\begin{macro}{\ifExternalizationLoaded}
+% \begin{macrocode}
+\def\ifExternalizationLoaded#1#2{%
+ \ifTikzLibraryLoaded{external}{#1}{#2}%
+}
+% \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}
@@ -566,8 +605,50 @@ and the derived files tikzscale.ins,
% \end{macrocode}
% Deactivate the new includegraphics command inside of tikzpictures, as a tikzpicture might load a PNG graphic or something and this should not be scaled by tikzscale but by TikZ or PGFPlots. Besides, the current implementation is not reentrant, so its not a good idea to call the macro recursively. The deactivation must be inside of tikzpicture, as a tikzpicture can be loaded without using includegraphics, thus it cannot be done there.
% \begin{macrocode}
- \pretocmd{\tikzpicture}{\LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}}{}{\PackageWarning{tikzscale}{Patching tikzpicture not successful}}%
- \apptocmd{\endtikzpicture}{\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}}{}{\PackageWarning{tikzscale}{Patching endtikzpicture not successful}}%
+ \NewDocumentCommand{\tikzscale@patchTikzpicture}{}{%
+ \pretocmd{\tikzpicture}{\LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}}{}{\PackageError{tikzscale}{Patching tikzpicture failed}}%
+ \apptocmd{\endtikzpicture}{\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}}{}{\PackageError{tikzscale}{Patching endtikzpicture failed}}%
+ }%
+% \end{macrocode}
+ % Do the patching here, too, as even if externalization library is used, there is no guarantee, that \cmd{\tikzexternaldisable} or \cmd{\tikzexternalenable} is called. There is no problem in patching twice, as we are in \cmd{\AtEndPreamble}, thus externalization has already been loaded (only most probably, as always with LaTeX-dependencies).
+% \begin{macrocode}
+ \tikzscale@patchTikzpicture
+% \end{macrocode}
+% If the externalization library has been loaded, prepare it for use together with tikzscale.
+% \begin{macrocode}
+ \ifExternalizationLoaded{%
+ %
+% \end{macrocode}
+% \cmd{\tikzexternaldisable} and \cmd{\tikzexternalenable} normally unintentionally deactivate the tikzscale commands (as they restore the original TikZ commands), so let them restore the tikzscale commands instead.
+% \begin{macrocode}
+ \apptocmd{\tikzexternaldisable}{%
+ \LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
+ \tikzscale@patchTikzpicture
+ }{}{\PackageError{tikzscale}{Patching tikzexternaldisable failed}}%
+ %
+ \apptocmd{\tikzexternalenable}{%
+ \LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
+ \tikzscale@patchTikzpicture
+ }{}{\PackageError{tikzscale}{Patching tikzexternalenable failed}}%
+% \end{macrocode}
+ % Patch the externalization command to also save the axis ratio if given. Unfortunately, \cmd{\apptocmd} cannot be used, as patching fails due to "nested patching command and parameters in patch", thus, manual patching is in order.
+% \begin{macrocode}
+ \LetLtxMacro{\tikzscale@externalend@storeshifts}{\pgf@externalend@storeshifts}%
+ \def\pgf@externalend@storeshifts#1{%
+ \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.
+% \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}}}%
+ }{}%
+ \fi
+ }%
+ }{}%
}
% \end{macrocode}
%\end{macro}
@@ -698,59 +779,22 @@ and the derived files tikzscale.ins,
% \begin{macrocode}
\pgfkeys{/tikzscale, #1}%
% \end{macrocode}
- % Draw and scale the graphic if it can or should not be loaded from the externalized file.
-% \begin{macrocode}
- \tikzscale@ifDrawAndScale{%
- \tikzscale@includetikzUnexternalized[#1]{#2}%
- }{%
-% \end{macrocode}
- % Try to load a dpth file to get the sizes pgfexternalwidth and pgfexternalheight of the externalized graphic
+ % Check if the current graphic should be either drawn and scaled or simply included. As externalization can get activated or deactivated at any time (if the library has been loaded in the preamble), check in every call what to do.
% \begin{macrocode}
- \ifboolexpr{test {\ifdef{\tikzexternalgetnextfilename}}}{%
- \tikzexternalgetnextfilename{\tikzscale@externalizationName}%
- \pgfexternalreaddpth{\tikzscale@externalizationName}%
+ \tikzscale@ifExternalizationActive{%
% \end{macrocode}
- % Check if the sizes are still correct, i.e. agree with the sizes of the externalized PDF graphic. The axis ratio does not have to be checked, as is is always correct. This is because if it gets changed, the width and the height get changed, too, and one of these changes gets detected.
+ % If externalization library has been loaded and is active, draw and scale the graphic if it is to be externalized.
% \begin{macrocode}
- \ifdef{\requestedWidth}{%
- \ifdef{\pgfexternalwidth}{%
- \tikzscale@ifSizeDifference{\requestedWidth - \pgfexternalwidth}{%
- \tikzset{external/remake next}%
-% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of width difference}%
- }{}%
- }{%
- \tikzset{external/remake next}%
-% \PackageWarning{tikzscale}{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}%
- }{}%
- }{%
- \tikzset{external/remake next}%
-% \PackageWarning{tikzscale}{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}%
- }{}%
- \global\undef{\tikzscale@oldAxisRatio}%
- }{%
- \tikzset{external/remake next}%
-% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of no external axis ratio}%
- }%
- }{}%
+ \tikzifexternalizingnext{%
+ \tikzscale@includetikzUnexternalized[#1]{#2}%
}{%
- \tikzset{external/remake next}%
- \PackageWarning{tikzscale}{Generate \tikzscale@externalizationName \MessageBreak because no file found}%
+ \tikzscale@includetikzWithExternalization{#2}%
}%
- \input{#2}%
+ }{%
+% \end{macrocode}
+ % Always draw and scale the graphic if externalization library has not been loaded or is deactivated.
+% \begin{macrocode}
+ \tikzscale@includetikzUnexternalized[#1]{#2}%
}%
}
% \end{macrocode}
@@ -794,6 +838,71 @@ and the derived files tikzscale.ins,
}
% \end{macrocode}
%\end{macro}
+
+% \begin{macro}{\tikzscale@includetikzWithExternalization}
+% This macro includes a tikzpicture file using the externalization library. As a precondition, the externalization must be loaded and active.
+% \begin{macrocode}
+\NewDocumentCommand{\tikzscale@includetikzWithExternalization}{m}{%
+% \end{macrocode}
+ % Try to load a dpth file to get the sizes pgfexternalwidth and pgfexternalheight as well as tikzscale@oldAxisRatio of the externalized graphic.
+% \begin{macrocode}
+ \tikzexternalgetnextfilename{\tikzscale@externalizationName}%
+ \pgfexternalreaddpth{\tikzscale@externalizationName}%
+% \end{macrocode}
+ % Check if the next figure has to be remade. If no dpth file exist, it need not and must not be remade, as otherwise no md5-file is generated and thus one extra compilation run is necessary.
+% \begin{macrocode}
+ \IfFileExists{\tikzscale@externalizationName.dpth}{%
+ \tikzscale@checkRequestedSizeChanges
+ }{}%
+ \input{#1}%
+}
+% \end{macrocode}
+%\end{macro}
+%
+%\begin{macro}{\tikzscale@checkRequestedSizeChanges}
+% \begin{macrocode}
+\NewDocumentCommand{\tikzscale@checkRequestedSizeChanges}{}{%
+% \end{macrocode}
+ % Check if the sizes are still correct, i.e. agree with the sizes of the externalized PDF graphic. The saved axis ratio from the last run is checked, too, as it might have been changed by the user between the last run and the current run.
+% \begin{macrocode}
+ \ifdef{\requestedWidth}{%
+ \ifdef{\pgfexternalwidth}{%
+ \tikzscale@ifSizeDifference{\requestedWidth - \pgfexternalwidth}{%
+ \tikzset{external/remake next}%
+% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of width difference}%
+% \tikzscale@warnIfSizeDifference{\requestedWidth}{\pgfexternalwidth}{#2}%
+ }{}%
+ }{%
+ \tikzset{external/remake next}%
+% \PackageWarning{tikzscale}{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}%
+ }{}%
+ }{%
+ \tikzset{external/remake next}%
+% \PackageWarning{tikzscale}{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}%
+ }{}%
+ \undef{\tikzscale@oldAxisRatio}%
+ }{%
+ \tikzset{external/remake next}%
+% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of no external axis ratio}%
+ }%
+ }{}%
+}
+% \end{macrocode}
+%\end{macro}
%
%\begin{macro}{\tikzscale@preparePlot}
% \begin{macrocode}
@@ -916,6 +1025,7 @@ and the derived files tikzscale.ins,
% First divide before multiply to avoid overflowing (at 16384).
% \begin{macrocode}
\pgfmathsetmacro{\errorRatio}{\measuredIntermediate/\requestedSize}%
+% \PackageWarning{tikzscale}{errorRatio \errorRatio\MessageBreak for #3}%
\pgfmathsetglobalmacro{\tikzscale@scale}{\tikzscale@scale/\errorRatio}%
}{%
\breakforeach%
diff --git a/Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty b/Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty
index 9213aff24eb..7937de6b1f5 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}[2012/11/03 v0.1.3 tikzscale LaTeX package]
+\ProvidesPackage{tikzscale}[2013/01/02 v0.2 tikzscale LaTeX package]
\RequirePackage{graphicx}
\RequirePackage{etoolbox}
\RequirePackage{pgfkeys}
@@ -22,24 +22,31 @@
\RequirePackage{xstring}
\AtEndPreamble{%
-\ifdef{\tikzifexternalizing}{%
+\ifExternalizationLoaded{%
\pgfkeys{/pgf/images/external info}%
}{}%
\ProvideDocumentCommand{\tikzsetnextfilename}{m}{}%
\ProvideDocumentCommand{\tikzsetexternalprefix}{m}{}%
\ProvideDocumentCommand{\tikzexternaldisable}{}{}%
\ProvideDocumentCommand{\tikzexternalenable}{}{}%
-\ProvideDocumentCommand{\tikzexternalize@hasbeencalled}{}{0}%
-\ifboolexpr{test {\ifundef{\tikzexternalize}} or test {\ifdefstring{\tikzexternalize@hasbeencalled}{0}}}{%
-\def\tikzscale@ifDrawAndScale#1#2{#1}%
+\def\tikzscale@ifExternalizationActive#1#2{%
+\ifExternalizationLoaded{%
+\ifdefequal{\tikz}{\tikzexternal@tikz@replacement}{%
+#1%
+}{%
+\ifdefequal{\tikz}{\tikzexternal@origtikz}{%
}{%
-\def\tikzscale@ifDrawAndScale#1#2{%
-\tikzifexternalizingnext{#1}{#2}%
+\PackageWarning{tikzscale}{Status of externalization is unknown, thus I assume it is deactivated.}%
+}%
+#2%
+}%
+}{%
+#2%
}%
}%
\@ifpackageloaded{tikz}{%
\newlength{\tikzscale@accuracy}%
-\setlength{\tikzscale@accuracy}{0.01pt}%
+\setlength{\tikzscale@accuracy}{\hfuzz}%
\def\maxTestIterations{10}%
}{}%
}
@@ -47,6 +54,16 @@
\pgfmathparse{#2}%
\global\let#1\pgfmathresult%
}
+\def\ifTikzLibraryLoaded#1#2#3{%
+\ifcsdef{tikz@library@#1@loaded}{%
+#2%
+}{%
+#3%
+}%
+}
+\def\ifExternalizationLoaded#1#2{%
+\ifTikzLibraryLoaded{external}{#1}{#2}%
+}
\def\edocsvlist#1{%
\edef\tikzscale@edocsvlist{#1}%
\expandafter\docsvlist\expandafter{\tikzscale@edocsvlist}%
@@ -102,8 +119,30 @@
}%
\LetLtxMacro{\tikzscale@oldincludegraphics}{\includegraphics}%
\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
-\pretocmd{\tikzpicture}{\LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}}{}{\PackageWarning{tikzscale}{Patching tikzpicture not successful}}%
-\apptocmd{\endtikzpicture}{\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}}{}{\PackageWarning{tikzscale}{Patching endtikzpicture not successful}}%
+\NewDocumentCommand{\tikzscale@patchTikzpicture}{}{%
+\pretocmd{\tikzpicture}{\LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}}{}{\PackageError{tikzscale}{Patching tikzpicture failed}}%
+\apptocmd{\endtikzpicture}{\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}}{}{\PackageError{tikzscale}{Patching endtikzpicture failed}}%
+}%
+\tikzscale@patchTikzpicture
+\ifExternalizationLoaded{%
+\apptocmd{\tikzexternaldisable}{%
+\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
+\tikzscale@patchTikzpicture
+}{}{\PackageError{tikzscale}{Patching tikzexternaldisable failed}}%
+\apptocmd{\tikzexternalenable}{%
+\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
+\tikzscale@patchTikzpicture
+}{}{\PackageError{tikzscale}{Patching tikzexternalenable failed}}%
+\LetLtxMacro{\tikzscale@externalend@storeshifts}{\pgf@externalend@storeshifts}%
+\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}}}%
+}{}%
+\fi
+}%
+}{}%
}
\NewDocumentCommand{\tikzscale@includegraphics}{O{}m}{%
\begingroup
@@ -157,12 +196,44 @@ axisratio/.value required
}
\NewDocumentCommand{\tikzscale@includetikz}{O{}m}{%
\pgfkeys{/tikzscale, #1}%
-\tikzscale@ifDrawAndScale{%
+\tikzscale@ifExternalizationActive{%
+\tikzifexternalizingnext{%
\tikzscale@includetikzUnexternalized[#1]{#2}%
}{%
-\ifboolexpr{test {\ifdef{\tikzexternalgetnextfilename}}}{%
+\tikzscale@includetikzWithExternalization{#2}%
+}%
+}{%
+\tikzscale@includetikzUnexternalized[#1]{#2}%
+}%
+}
+\NewDocumentCommand{\tikzscale@includetikzUnexternalized}{O{}m}{%
+\elseif{test {\ifundef{\requestedWidth}} and test {\ifundef{\requestedHeight}} and test {\ifundef{\requestedAxisRatio}}}{%
+\input{#2}%
+}{test {\ifdef{\requestedWidth}} and test {\ifdef{\requestedHeight}}}{%
+\tikzscale@resizePlotTo{#2}%
+}{test {\ifdef{\requestedAxisRatio}}}{%
+\tikzscale@includeAxisRatio{#2}%
+}{test {\ifundef{\requestedAxisRatio}}}{%
+\ifdef{\pgfplotsset}{%
+\def\requestedAxisRatio{1}%
+\tikzscale@includeAxisRatio{#2}%
+}{%
+\tikzscale@includeNormalTikzpicture{#2}%
+}%
+}{%
+\tikzscale@invalidKeyError{#2}%
+}%
+}
+
+\NewDocumentCommand{\tikzscale@includetikzWithExternalization}{m}{%
\tikzexternalgetnextfilename{\tikzscale@externalizationName}%
\pgfexternalreaddpth{\tikzscale@externalizationName}%
+\IfFileExists{\tikzscale@externalizationName.dpth}{%
+\tikzscale@checkRequestedSizeChanges
+}{}%
+\input{#1}%
+}
+\NewDocumentCommand{\tikzscale@checkRequestedSizeChanges}{}{%
\ifdef{\requestedWidth}{%
\ifdef{\pgfexternalwidth}{%
\tikzscale@ifSizeDifference{\requestedWidth - \pgfexternalwidth}{%
@@ -186,35 +257,11 @@ axisratio/.value required
\tikzscale@ifSizeDifference{\requestedAxisRatio - \tikzscale@oldAxisRatio}{%
\tikzset{external/remake next}%
}{}%
-\global\undef{\tikzscale@oldAxisRatio}%
+\undef{\tikzscale@oldAxisRatio}%
}{%
\tikzset{external/remake next}%
}%
}{}%
-}{%
-\tikzset{external/remake next}%
-\PackageWarning{tikzscale}{Generate \tikzscale@externalizationName \MessageBreak because no file found}%
-}%
-\input{#2}%
-}%
-}
-\NewDocumentCommand{\tikzscale@includetikzUnexternalized}{O{}m}{%
-\elseif{test {\ifundef{\requestedWidth}} and test {\ifundef{\requestedHeight}} and test {\ifundef{\requestedAxisRatio}}}{%
-\input{#2}%
-}{test {\ifdef{\requestedWidth}} and test {\ifdef{\requestedHeight}}}{%
-\tikzscale@resizePlotTo{#2}%
-}{test {\ifdef{\requestedAxisRatio}}}{%
-\tikzscale@includeAxisRatio{#2}%
-}{test {\ifundef{\requestedAxisRatio}}}{%
-\ifdef{\pgfplotsset}{%
-\def\requestedAxisRatio{1}%
-\tikzscale@includeAxisRatio{#2}%
-}{%
-\tikzscale@includeNormalTikzpicture{#2}%
-}%
-}{%
-\tikzscale@invalidKeyError{#2}%
-}%
}
\NewDocumentCommand{\tikzscale@preparePlot}{}{%
\pgfplotsset{every axis/.append style={width=\tikzscale@width,height=\tikzscale@height,every axis/.style={}}}%