summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/tikzscale
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/tikzscale')
-rw-r--r--Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx136
1 files changed, 79 insertions, 57 deletions
diff --git a/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx b/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx
index 2c148abcce6..d5f7a29bb9e 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/10/31 v0.1 tikzscale LaTeX package]
+\ProvidesPackage{tikzscale}[2012/11/02 v0.1.2 tikzscale LaTeX package]
\RequirePackage{graphicx}
\RequirePackage{etoolbox}
\RequirePackage{pgfkeys}
@@ -114,6 +114,8 @@ and the derived files tikzscale.ins,
\usepackage{tikzscale}
\usepackage{tikz}
\usepackage{pgfplots}
+% 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}
\usepackage{xcolor}
\usepackage{lmodern}
\usepackage{amsmath}
@@ -182,6 +184,8 @@ and the derived files tikzscale.ins,
%\maketitle
%
%\changes{v0.1}{2012/10/31}{First public release}
+%\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}
% \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}
@@ -306,16 +310,14 @@ and the derived files tikzscale.ins,
% 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
-% \frame{\includegraphics[width=0.4\linewidth,height=0.4\linewidth]{testgraphic2D.tikz}}\\
-%^^A \includegraphics[width=0.4\linewidth,height=0.4\linewidth]{testgraphic2D.tikz}
+% \frame{\includegraphics[width=0.4\linewidth,height=0.4\linewidth]{testgraphic2D.tikz}}
% \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.
% \begin{figure}
% \centering
-% \frame{\includegraphics[width=0.4\linewidth,axisratio=1]{testgraphic2D.tikz}}\\
-%^^A \includegraphics[width=0.4\linewidth,axisratio=1]{testgraphic2D.tikz}\\
+% \frame{\includegraphics[width=0.4\linewidth,axisratio=1]{testgraphic2D.tikz}}
% \caption{Using options \texttt{width=0.4\cmd{\linewidth}} and \texttt{axisratio=1} results in an quadratic graphic area with overall width set to 40\% of the linewidth. The height follows from these constraints, so that the overall plot is not quadratic in general.}
% \label{axisratio}
% \end{figure}
@@ -352,7 +354,7 @@ and the derived files tikzscale.ins,
% If both tikzscale and currfile are loaded, the limitation is fixed, so that both \cmd{\includegraphics} commands succeed. Note, that this functionality supports the traditional graphic formats, too, and is also available without loading the TikZ or PGFPlots packages, although the package's name might imply otherwise.
%
% \section{Compatibility}
-% Using both the externalization library and tikzscale seems to have a race condition when a make file is used with multiple jobs (-j$X$ with $X > 1$). The probability of getting errors increases with the number of jobs and for $X = 1$ and $X = 2$ no race condition could be observed, yet. You should either avoid using mode \emph{list and make} or have only one job if you want to be on the safe side.
+% 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.
%
% \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.
@@ -362,7 +364,7 @@ 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, for example, because the axis ratio is not saved, thus assumed unknown and the graphic is thus regenerated.
+% \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 if graphic files are located in a subdirectory, the externalized files should also be in that subdirectory.
% \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}
@@ -378,7 +380,7 @@ and the derived files tikzscale.ins,
% \item Dr.\ Christian Feuersänger
% \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.
+% \item Answered many questions and had a lot of good ideas regarding the externalization and beyond.
% \end{itemize}
% \item David Carlisle
% \begin{itemize}
@@ -411,8 +413,23 @@ and the derived files tikzscale.ins,
\ProvideDocumentCommand{\tikzsetexternalprefix}{m}{}%
\ProvideDocumentCommand{\tikzexternaldisable}{}{}%
\ProvideDocumentCommand{\tikzexternalenable}{}{}%
- \ProvideDocumentCommand{\tikzifexternalizingnext}{mm}{#1}%
+ \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.
+% \begin{macrocode}
+ \def\tikzscale@ifDrawAndScale#1#2{#1}%
+ }{%
+% \end{macrocode}
+ % If externalization library has been loaded and activated, draw and scale the graphic if it is to be externalized.
+% \begin{macrocode}
+ \def\tikzscale@ifDrawAndScale#1#2{%
+ \tikzifexternalizingnext{#1}{#2}%
+ }%
+ }%
%\end{macro}
%
%\begin{macro}{\tikzscale@scale}
@@ -540,6 +557,11 @@ and the derived files tikzscale.ins,
% \begin{macrocode}
\LetLtxMacro{\tikzscale@oldincludegraphics}{\includegraphics}%
\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
+% \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}}%
}
% \end{macrocode}
%\end{macro}
@@ -552,6 +574,10 @@ and the derived files tikzscale.ins,
% Start a group, so that changed variables during processing the current tikzpicture due not influence other tikzpictures. This is much more convienient, than resetting every single variable. Use \cmd{\begingroup} instead of \cmd{\bgroup} to simplify finding unmatched braces.
% \begin{macrocode}
\begingroup
+ % \end{macrocode}
+ % It happened at least once together with externalization, that the deactivation of the new includegraphics command did not work, so do it again to be safe (maybe reentrance problem with multiple tikzpicture calls?).
+% \begin{macrocode}
+ \LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}%
% \end{macrocode}
% There is a leading space character introduced by the externalization library, if the file is input directly. Thus use a trick to avoid that space. Furthermore, TikZ introduces with a specific version an trailing space character. To get rid of all space character issues, just solve the problem here once an for all.
% \begin{macrocode}
@@ -566,10 +592,6 @@ and the derived files tikzscale.ins,
% \begin{macrocode}
\tikzscale@isTikzFile{tikzscale@testTikzFile}{\tikzscale@fileName}%
\ifcsdef{tikzscale@testTikzFile}{%
-% \end{macrocode}
- % Deactivate the new includegraphics command, as a tikzpicture might load a PNG graphic or something and this should not be scaled by tikzscale but by TikZ or PGFPlots.
-% \begin{macrocode}
- \LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}%
\tikzscale@includetikz[#1]{\tikzscale@fileName}%
}{%
\tikzscale@oldincludegraphics[#1]{\tikzscale@fileName}%
@@ -666,61 +688,62 @@ and the derived files tikzscale.ins,
% \begin{macrocode}
\NewDocumentCommand{\tikzscale@includetikz}{O{}m}{%
% \end{macrocode}
- % TODO: Is it really necessary to execute this command here or can it be moved to a more specialized code path?
-% \begin{macrocode}
- \ifdef{\tikzexternalgetnextfilename}{%
- \tikzexternalgetnextfilename{\tikzscale@externalizationName}%
- }{}%
-% \end{macrocode}
% Check the keys here already, as they are needed both to see if already externalized files fulfill their requirements and to handle unexternalized files.
% \begin{macrocode}
\pgfkeys{/tikzscale, #1}%
- \tikzifexternalizingnext{%
+% \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}
- % Load this thing in an environment, where it does not get printed, as there is some garbage in the file, too. As the sbox creates a new group, use a global variable to get the content out of the group.
+ % Try to load a dpth file to get the sizes pgfexternalwidth and pgfexternalheight of the externalized graphic
% \begin{macrocode}
- \sbox{\tikzscale@measuredSize}{%
- \IfFileExists{\tikzscale@externalizationName.dpth}{%
- \input{\tikzscale@externalizationName.dpth}%
- \xdef\tikzscale@measuredWidth{\pgfexternalwidth}%
- \xdef\tikzscale@measuredHeight{\pgfexternalheight}%
- }{}%
- }%
+ \ifboolexpr{test {\ifdef{\tikzexternalgetnextfilename}}}{%
+ \tikzexternalgetnextfilename{\tikzscale@externalizationName}%
+ \pgfexternalreaddpth{\tikzscale@externalizationName}%
% \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.
+ % 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.
% \begin{macrocode}
- \ifdef{\requestedWidth}{%
- \ifdef{\tikzscale@measuredWidth}{%
- \tikzscale@ifSizeDifference{\requestedWidth - \tikzscale@measuredWidth}{%
+ \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}%
- }{}%
- \global\undef{\tikzscale@measuredWidth}%
- }{%
- \tikzset{external/remake next}%
- }%
- }{}%
- \ifdef{\requestedHeight}{%
- \ifdef{\tikzscale@measuredHeight}{%
- \tikzscale@ifSizeDifference{\requestedHeight - \tikzscale@measuredHeight}{%
+% \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}%
- }{}%
- \global\undef{\tikzscale@measuredHeight}%
- }{%
- \tikzset{external/remake next}%
- }%
- }{}%
- \ifdef{\requestedAxisRatio}{%
- \ifdef{\tikzscale@oldAxisRatio}{%
- \tikzscale@ifSizeDifference{\requestedAxisRatio - \tikzscale@oldAxisRatio}{%
+% \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}%
- }{}%
- \global\undef{\tikzscale@oldAxisRatio}%
- }{%
- \tikzset{external/remake next}%
- }%
- }{}%
+% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of no external axis ratio}%
+ }%
+ }{}%
+ }{%
+ \tikzset{external/remake next}%
+ \PackageWarning{tikzscale}{Generate \tikzscale@externalizationName \MessageBreak because no file found}%
+ }%
\input{#2}%
}%
}
@@ -1085,7 +1108,6 @@ and the derived files tikzscale.ins,
% For the externalization, set correct file name and only externalize the graphic with the final size. This produces a \href{http://old.nabble.com/minor-comment-about-TikZ-external-library-usage-tt31042245.html#a31042245}{known bug}
% \begin{macrocode}
% \tikzsetnextfilename{#1}%
-% \edef\myprefix{\pwd}
% \end{macrocode}
% Get the current directory as a string and use it as an prefix, so that the graphic's PDF is generated in a subdirectory if the tikz file is located in a subdirectory, too. This is necessary, as the PDF file is searched for in the subdirectory in this case. This might be unnecessary due to the newly created path lookup logic.
% \begin{macrocode}