summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-01-14 23:33:07 +0000
committerKarl Berry <karl@freefriends.org>2013-01-14 23:33:07 +0000
commit3e6b25207e86f8109b30b08f8b7498e932832ca7 (patch)
treee777bf88550a23af871e815c675d198c6dd886db /Master
parentfef4ece1788f2100ac3474d71832fa39da34a6ce (diff)
tikzscale (14jan13)
git-svn-id: svn://tug.org/texlive/trunk@28834 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.pdfbin147196 -> 149001 bytes
-rw-r--r--Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.tex78
-rw-r--r--Master/texmf-dist/doc/latex/tikzscale/tikzscale.pdfbin358999 -> 359330 bytes
-rw-r--r--Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx239
-rw-r--r--Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty115
5 files changed, 256 insertions, 176 deletions
diff --git a/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.pdf b/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.pdf
index 00b3ea4853e..b6e760fcfcb 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 91c3f4518ad..df683a957f8 100644
--- a/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.tex
+++ b/Master/texmf-dist/doc/latex/tikzscale/test-tikzscale.tex
@@ -6,18 +6,25 @@
\usepackage{pgfplots}
\usepackage{currfile}
\usepackage{lmodern}
+% Use the package ifpdf to share one test document between pdflatex and latex
+\usepackage{ifpdf}
% 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}
\usetikzlibrary{external}
\tikzexternalize
% \tikzexternalize[mode=list and make]
+\ifpdf
+\else
+ \tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"; dvips -o "\image".ps "\image".dvi}}
+\fi
\begin{document}
\section*{Tests}
\begin{itemize}
\item Test that with externalization, no picture is generated multiple times.
- \item Test that there are no warnings without using externalization.
+ \item Test that there are no warnings with and without using externalization.
+ \item Test with \texttt{pdflatex} and \texttt{latex} and do not forget to use \texttt{dvips}.
\item Normal input command\\%
\input{testRectangle.tikz}%
\item Use includegraphics with file ending\\%
@@ -30,22 +37,8 @@
\includegraphics[width=5cm]{testRectangle}%
\item Use includegraphics with scaling while having column width already\\%
\includegraphics[width=\linewidth]{linewidth}%
- \item Use includegraphics with jpg\\%
- \includegraphics{example-grid-100x100bp.jpg}%
- \item Use includegraphics with pdf\\%
- \includegraphics{example-grid-100x100bp.pdf}%
- \item Use includegraphics with png\\%
- \includegraphics{example-grid-100x100bp.png}%
-% \item Use includegraphics with eps%
-% \includegraphics{example-grid-100x100bp.eps}%
- \item Use includegraphics with pdf and scaling\\%
- \includegraphics[width=0.3\linewidth]{example-grid-100x100bp.pdf}%
- \item Use includegraphics with column width\\%
- \includegraphics[width=\linewidth]{example-grid-100x100bp.jpg}%
\item Use \texttt{input} with pgfplots\\%
\input{pgfplots-test.tikz}%
- \item Input a 2D pgfplots\\
- \input{testgraphic2D.tikz}%
\item Use pgfplots without optional parameter\\%
\includegraphics{pgfplots-test}%
\item Use pgfplots with given width and height\\%
@@ -54,24 +47,43 @@
\includegraphics{testNode.tikz}%
% \item Use includegraphics with scaling only a node results in an error\\%
% \includegraphics[width=\linewidth]{testNode.tikz}%
- \item Use includegraphics with a two dimensional plot\\%
- \includegraphics{testgraphic2D.tikz}%
- \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=\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\\%
- \frame{\input{testgraphic2D.tikz}}
- \item Use a two dimensional plot with a tight frame with width \settowidth{\mylen}{\frame{\includegraphics{testgraphic2D.tikz}}}\the\mylen\\%
- \frame{\includegraphics{testgraphic2D.tikz}}
+ \ifpdf
+ \item Use includegraphics with jpg\\%
+ \includegraphics{example-grid-100x100bp.jpg}%
+ \item Use includegraphics with pdf\\%
+ \includegraphics{example-grid-100x100bp.pdf}%
+ \item Use includegraphics with png\\%
+ \includegraphics{example-grid-100x100bp.png}%
+ \item Use includegraphics with pdf and scaling\\%
+ \includegraphics[width=0.3\linewidth]{example-grid-100x100bp.pdf}%
+ \item Use includegraphics with column width\\%
+ \includegraphics[width=\linewidth]{example-grid-100x100bp.jpg}%
+ \item Input a 2D pgfplots\\
+ \input{testgraphic2D.tikz}%
+ \item Use includegraphics with a two dimensional plot\\%
+ \includegraphics{testgraphic2D.tikz}%
+ \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=\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\\%
+ \frame{\input{testgraphic2D.tikz}}
+ \item Use a two dimensional plot with a tight frame with width \settowidth{\mylen}{\frame{\includegraphics{testgraphic2D.tikz}}}\the\mylen\\%
+ \frame{\includegraphics{testgraphic2D.tikz}}
+ \else
+ \item Use includegraphics with eps (this is not found within dvi, even without tikzscale)\\%
+ \includegraphics{example-grid-100x100bp.eps}%
+ \item Use includegraphics with eps and full path (this is not shown, even without tikzscale)\\%
+ \includegraphics{/usr/share/texlive/texmf-dist/tex/latex/mwe/example-grid-100x100bp.eps}%
+ \fi
\item Use includegraphics with a histogram of a normal distribution\\%
\includegraphics[width=\linewidth,height=0.5\linewidth]{histogramNormal}%
\end{itemize}
diff --git a/Master/texmf-dist/doc/latex/tikzscale/tikzscale.pdf b/Master/texmf-dist/doc/latex/tikzscale/tikzscale.pdf
index 816f99c8608..a66ac1cde97 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 59b0b4f2596..49c6f7a0174 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/01/09 v0.2.1 tikzscale LaTeX package]
+\ProvidesPackage{tikzscale}[2013/01/13 v0.2.2 tikzscale LaTeX package]
\RequirePackage{graphicx}
\RequirePackage{etoolbox}
\RequirePackage{pgfkeys}
@@ -188,6 +188,7 @@ and the derived files tikzscale.ins,
%\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}
%\changes{v0.2.1}{2013/01/09}{Fix graphics with data from text file due to wrong line breaks; fix plain old \LaTeX support}
+%\changes{v0.2.2}{2013/01/13}{Fully support plain (dvi) \LaTeX; mind graphicspath}
% \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}
@@ -410,6 +411,8 @@ and the derived files tikzscale.ins,
% \item Mohammad Reza Keshtkaran
% \begin{itemize}
% \item Reported a bug when using plain old \LaTeX with an eps file, which lead to a fix.
+% \item Reported another bug when using plain old \LaTeX, which lead to some rework to fully support \LaTeX without additional code.
+% \item Reported a bug when using \cmd{\graphicspath}, which lead to a fix.
% \end{itemize}
% \end{itemize}
%
@@ -422,63 +425,6 @@ and the derived files tikzscale.ins,
% \fi
% \makeatletter
%
-%\begin{macro}{\tikzexternal}
-% \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.
-% \begin{macrocode}
- \ifExternalizationLoaded{%
- \pgfkeys{/pgf/images/external info}%
- }{}%
-% \end{macrocode}
- % Provide dummy commands, if the externalization library has not been loaded during the preamble.
-% \begin{macrocode}
- \ProvideDocumentCommand{\tikzsetnextfilename}{m}{}%
- \ProvideDocumentCommand{\tikzsetexternalprefix}{m}{}%
- \ProvideDocumentCommand{\tikzexternaldisable}{}{}%
- \ProvideDocumentCommand{\tikzexternalenable}{}{}%
-% \end{macrocode}
- % 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@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}
- % 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}
- #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, 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}{\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}
- \def\maxTestIterations{10}%
- }{}%
-}
-% \end{macrocode}
-%\end{macro}
-%
% This command draws the plot's border at the right text border, so that thick points or label descriptions can reach into the margin. This should be limited to PGFPlots only if activated.
%^^A \tikzset{every picture/.style={trim axis right}}
%
@@ -590,9 +536,31 @@ and the derived files tikzscale.ins,
}
}
\ExplSyntaxOff
+%\end{macro}
+%
+%\begin{macro}
+ % 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@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}
+ % 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}
+ #2%
+ }%
+ }{%
+ #2%
+ }%
+ }%
% \end{macrocode}
%\end{macro}
-
%
%\begin{macro}{\activatetikzscale}
% \begin{macrocode}
@@ -607,61 +575,83 @@ and the derived files tikzscale.ins,
% The \cmd{graphicspath} command is used to set additional directories, which are searched for graphics. \cmd{\Ginput@path} is used to get the \href{http://tex.stackexchange.com/a/58404}{current content}.
% \begin{macrocode}
\ifdef{\currfiledir}{%
-% \graphicspath{{\currfiledir}{}\Ginput@path}%
- \def\tikzscale@graphicspath{\currfiledir,{}}%
+ \ifdef{\Ginput@path}{%
+ \def\tikzscale@graphicspath{\Ginput@path,\currfiledir,{}}%
+ }{%
+ \def\tikzscale@graphicspath{\currfiledir,{}}%
+ }%
}{%
\def\tikzscale@graphicspath{{}}%
}%
% \end{macrocode}
-% Save the \cmd{\includegraphics} \href{ftp://ftp.tu-chemnitz.de/pub/tex/macros/latex/required/graphics/grfguide.pdf}{command} and replace it by a new more generic command, to have a consistent user interface.
+% Save the \cmd{\includegraphics} \href{ftp://ftp.tu-chemnitz.de/pub/tex/macros/latex/required/graphics/grfguide.pdf}{command}.
% \begin{macrocode}
\LetLtxMacro{\tikzscale@oldincludegraphics}{\includegraphics}%
- \LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
- \NewDocumentCommand{\tikzscale@patchTikzpicture}{}{%
% \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. Using \cmd{\apptocmd} to do a local definition inside of the group started by \cmd{\tikzpicture} does not work.
+ % Activate the enhanced includegraphics command at end of preamble, so that no other package is interfering (besides on purpose).
% \begin{macrocode}
- \pretocmd{\tikzpicture}{%
- \LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}%
- }{}{\PackageError{tikzscale}{Patching tikzpicture failed}}%
- %
- \apptocmd{\endtikzpicture}{%
- \LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
- }{}{\PackageError{tikzscale}{Patching endtikzpicture failed}}%
+ \tikzscale@useEnhancedIncludegraphics
% \end{macrocode}
- % Restore the \cmd{\endlinechar} during the execution of the tikzpicture environment. This is necessary, for example, if data is read from a table and the data entries are separated by newline characters. Not restoring the \cmd{\endlinechar} would \href{http://tex.stackexchange.com/q/89053/7323}{distort the data}. Use \cmd{\apptocmd} to call the command inside the group opened by tikzpicture. Thus, nothing has to be done in \cmd{\endtikzpicture} regarding \cmd{\endlinechar}.
+ % Also patch tikzpicture environment to temporarily deactivate the enhanced includegraphics command inside the tikzpicture environment in case the tikzpicture environment is called directly (without includegraphics being called) and loading another graphic (like a PNG file inside of a pgfplot).
% \begin{macrocode}
- \apptocmd{\tikzpicture}{%
+ \tikzscale@patchTikzpictureIncludegraphics
% \end{macrocode}
- % \cmd{\tikzscale@restoreEndLineChar} is only defined if \cmd{\includegraphics} has been called. If, instead, \cmd{tikzpicture} has been called directly, it is not defined, so do a check first.
+ % As \cmd{\endtikzpicture} does not seem to be redefined, patch it here (once) to activate tikzscale's \cmd{\includegraphics} again. This is probably not necessary, but might be handy if there are two tikzpicture environments in one includegraphics environment.
% \begin{macrocode}
- \ifdef{\tikzscale@restoreEndLineChar}{%
- \tikzscale@restoreEndLineChar
- }{}%
- }{}{\PackageError{tikzscale}{Patching tikzpicture failed}}%
- }%
+ \tikzscale@patchEndtikzpictureIncludegraphics
+% \end{macrocode}
+% \begin{macrocode}
+}
+% \end{macrocode}
+%\end{macro}
+%
+%\begin{macro}{\tikzexternal}
+% \begin{macrocode}
+\AtEndPreamble{%
% \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).
+ % Activate the output of the graphics sizes into the dpth files (one file per graphic) if externalization might be used (known at the end of preamble). 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}
+ \ifExternalizationLoaded{%
+ \pgfkeys{/pgf/images/external info}%
+ }{}%
+% \end{macrocode}
+ % Provide dummy commands, if the externalization library has not been loaded during the preamble.
+% \begin{macrocode}
+ \ProvideDocumentCommand{\tikzsetnextfilename}{m}{}%
+ \ProvideDocumentCommand{\tikzsetexternalprefix}{m}{}%
+ \ProvideDocumentCommand{\tikzexternaldisable}{}{}%
+ \ProvideDocumentCommand{\tikzexternalenable}{}{}%
+% \end{macrocode}
+%
+% \begin{macrocode}
+ \@ifpackageloaded{tikz}{%
+% \end{macrocode}
+ % 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}{\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}
- \tikzscale@patchTikzpicture
+ \def\maxTestIterations{10}%
+ }{}%
% \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.
+% \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. The idea is to get the tikzscale's includegraphics command being called and then redefine tikzpicture and do the rest of the work there.
% \begin{macrocode}
\apptocmd{\tikzexternaldisable}{%
- \LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
- \tikzscale@patchTikzpicture
+ \tikzscale@useEnhancedIncludegraphics
+ \tikzscale@patchTikzpictureIncludegraphics
}{}{\PackageError{tikzscale}{Patching tikzexternaldisable failed}}%
%
\apptocmd{\tikzexternalenable}{%
- \LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
- \tikzscale@patchTikzpicture
+ \tikzscale@useEnhancedIncludegraphics
+ \tikzscale@patchTikzpictureIncludegraphics
}{}{\PackageError{tikzscale}{Patching tikzexternalenable failed}}%
-% \end{macrocode}
+% \end{macrodode}
% 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}%
@@ -680,6 +670,8 @@ and the derived files tikzscale.ins,
\fi
}%
}{}%
+% \end{macrocode}
+% \begin{macrocode}
}
% \end{macrocode}
%\end{macro}
@@ -697,10 +689,9 @@ and the derived files tikzscale.ins,
% \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. Note, that the redefinition of \cmd{\endlinechar} is local to the current group, so it does not have to be restored at the end of the group.
+ % Do the patching of endlinechar and tikzpicture here, as tikzpicture should not be changed if not called via the new \cmd{\includegraphics} command.
% \begin{macrocode}
- \edef\tikzscale@restoreEndLineChar{\endlinechar=\the\endlinechar\relax}%
- \endlinechar=-1%
+ \tikzscale@FixEndLine
% \end{macrocode}
% Find the exact file name, as the ending and the path could be omitted.
% \begin{macrocode}
@@ -723,6 +714,70 @@ and the derived files tikzscale.ins,
% \end{macrocode}
%\end{macro}
%
+%\begin{macro}{\tikzscale@useEnhancedIncludegraphics}
+ % Replace the \cmd{\includegraphics} command by tikzscale's more generic command, to provide a consistent user interface.
+% \begin{macrocode}
+\def\tikzscale@useEnhancedIncludegraphics{%
+ \LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
+}
+% \end{macrocode}
+%\end{macro}
+%
+%\begin{macro}{\tikzscale@FixEndLine}
+% tikzpicture environment gets redefined:
+% - without external library: only inside tikzscale (once)
+% - with external library: additionally, whenever \cmd{\externalenable} or \cmd{\externaldisable} is called (\cmd{\tikzpiture} and \cmd{\endtikzpicture})
+% Use cases to patch tikzpicture:
+% - to use tikzscale's includegraphics
+% - to restore end of line character
+% Constraints:
+% - The patches have to be applied at the beginning of \cmd{\tikzpicture} and the end of \cmd{\endtikzpicture}, as \cmd{\tikzpicture} might not be executed completely when using external, as then the content of the tizkpicture environment is not executed at all.
+% - The patches should not accumulate
+% - A group might make sense to have a local scope
+% \begin{macrocode}
+\def\tikzscale@FixEndLine{%
+% \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 a trailing space character. To get rid of all space character issues, just solve the problem here once an for all. Note, that the redefinition of \cmd{\endlinechar} is local to the current group, so it does not have to be restored at the end of the group.
+% \begin{macrocode}
+ \edef\tikzscale@restoreEndLineChar{\endlinechar=\the\endlinechar\relax}%
+ \endlinechar=-1%
+% \end{macrocode}
+ % Restore the \cmd{\endlinechar} during the execution of the tikzpicture environment. This is necessary, for example, if data is read from a table and the data entries are separated by newline characters. Not restoring the \cmd{\endlinechar} would \href{http://tex.stackexchange.com/q/89053/7323}{distort the data}. Use \cmd{\apptocmd} to call the command inside the group opened by tikzpicture. Thus, nothing has to be done in \cmd{\endtikzpicture} regarding \cmd{\endlinechar}.
+% \begin{macrocode}
+ \pretocmd{\tikzpicture}{%
+ \tikzscale@restoreEndLineChar
+ }{}{\PackageError{tikzscale}{Patching tikzpicture failed}}%
+ %
+ \apptocmd{\endtikzpicture}{%
+ \endlinechar=-1%
+ }{}{\PackageError{tikzscale}{Patching endtikzpicture failed}}%
+}%
+% \end{macrocode}
+%\end{macro}
+%
+%\begin{macro}{\tikzscale@patchTikzpictureIncludegraphics}
+% \begin{macrocode}
+\def\tikzscale@patchTikzpictureIncludegraphics{%
+ % 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. Using \cmd{\apptocmd} to do a local definition inside of the group started by \cmd{\tikzpicture} does not work. The includegraphics commands really has to be deactivated here, as a tikzpicture including a PNG file might be called directly without calling includegraphics
+% \begin{macrocode}
+ \pretocmd{\tikzpicture}{%
+ \LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}%
+ }{}{\PackageError{tikzscale}{Patching tikzpicture failed}}%
+ %
+}
+% \end{macrocode}
+%\end{macro}
+%
+%\begin{macro}{\tikzscale@patchEndtikzpictureIncludegraphics}
+% \begin{macrocode}
+\def\tikzscale@patchEndtikzpictureIncludegraphics{%
+ \apptocmd{\endtikzpicture}{%
+ \LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
+ }{}{\PackageError{tikzscale}{Patching endtikzpicture failed}}%
+}
+% \end{macrocode}
+%\end{macro}
+%
% \begin{macro}{\tikzscale@findExactFileName}
% Find the exact file name of a graphic file by testing several paths and file endings if there are degrees of freedom. The file name is saved in the command sequence name given by the first argument.
% \begin{macrocode}
diff --git a/Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty b/Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty
index 517f35a8634..38b78365249 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/01/09 v0.2.1 tikzscale LaTeX package]
+\ProvidesPackage{tikzscale}[2013/01/13 v0.2.2 tikzscale LaTeX package]
\RequirePackage{graphicx}
\RequirePackage{etoolbox}
\RequirePackage{pgfkeys}
@@ -21,35 +21,6 @@
\RequirePackage{letltxmacro}
\RequirePackage{xstring}
-\AtEndPreamble{%
-\ifExternalizationLoaded{%
-\pgfkeys{/pgf/images/external info}%
-}{}%
-\ProvideDocumentCommand{\tikzsetnextfilename}{m}{}%
-\ProvideDocumentCommand{\tikzsetexternalprefix}{m}{}%
-\ProvideDocumentCommand{\tikzexternaldisable}{}{}%
-\ProvideDocumentCommand{\tikzexternalenable}{}{}%
-\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.}%
-}%
-#2%
-}%
-}{%
-#2%
-}%
-}%
-\@ifpackageloaded{tikz}{%
-\newlength{\tikzscale@accuracy}%
-\setlength{\tikzscale@accuracy}{\hfuzz}%
-\def\maxTestIterations{10}%
-}{}%
-}
\def\pgfmathsetglobalmacro#1#2{%
\pgfmathparse{#2}%
\global\let#1\pgfmathresult%
@@ -111,39 +82,59 @@
}
}
\ExplSyntaxOff
-
+\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.}%
+}%
+#2%
+}%
+}{%
+#2%
+}%
+}%
\AtEndPreamble{%
\def\tikzscale@tikzFileExtensions{.tikz,.TIKZ,.TikZ,.pgf,.PGF}%
\DeclareGraphicsExtensions{\tikzscale@tikzFileExtensions,\Gin@extensions}%
\ifdef{\currfiledir}{%
+\ifdef{\Ginput@path}{%
+\def\tikzscale@graphicspath{\Ginput@path,\currfiledir,{}}%
+}{%
\def\tikzscale@graphicspath{\currfiledir,{}}%
+}%
}{%
\def\tikzscale@graphicspath{{}}%
}%
\LetLtxMacro{\tikzscale@oldincludegraphics}{\includegraphics}%
-\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
-\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}}%
-\apptocmd{\tikzpicture}{%
-\ifdef{\tikzscale@restoreEndLineChar}{%
-\tikzscale@restoreEndLineChar
+\tikzscale@useEnhancedIncludegraphics
+\tikzscale@patchTikzpictureIncludegraphics
+\tikzscale@patchEndtikzpictureIncludegraphics
+}
+\AtEndPreamble{%
+\ifExternalizationLoaded{%
+\pgfkeys{/pgf/images/external info}%
+}{}%
+\ProvideDocumentCommand{\tikzsetnextfilename}{m}{}%
+\ProvideDocumentCommand{\tikzsetexternalprefix}{m}{}%
+\ProvideDocumentCommand{\tikzexternaldisable}{}{}%
+\ProvideDocumentCommand{\tikzexternalenable}{}{}%
+\@ifpackageloaded{tikz}{%
+\newlength{\tikzscale@accuracy}%
+\setlength{\tikzscale@accuracy}{\hfuzz}%
+\def\maxTestIterations{10}%
}{}%
-}{}{\PackageError{tikzscale}{Patching tikzpicture failed}}%
-}%
-\tikzscale@patchTikzpicture
\ifExternalizationLoaded{%
\apptocmd{\tikzexternaldisable}{%
-\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
-\tikzscale@patchTikzpicture
+\tikzscale@useEnhancedIncludegraphics
+\tikzscale@patchTikzpictureIncludegraphics
}{}{\PackageError{tikzscale}{Patching tikzexternaldisable failed}}%
\apptocmd{\tikzexternalenable}{%
-\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
-\tikzscale@patchTikzpicture
+\tikzscale@useEnhancedIncludegraphics
+\tikzscale@patchTikzpictureIncludegraphics
}{}{\PackageError{tikzscale}{Patching tikzexternalenable failed}}%
\LetLtxMacro{\tikzscale@externalend@storeshifts}{\pgf@externalend@storeshifts}%
\def\pgf@externalend@storeshifts#1{%
@@ -159,8 +150,7 @@
\NewDocumentCommand{\tikzscale@includegraphics}{O{}m}{%
\begingroup
\LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}%
-\edef\tikzscale@restoreEndLineChar{\endlinechar=\the\endlinechar\relax}%
-\endlinechar=-1%
+\tikzscale@FixEndLine
\tikzscale@findExactFileName{tikzscale@fileName}{#2}%
\tikzscale@isTikzFile{tikzscale@testTikzFile}{\tikzscale@fileName}%
\ifcsdef{tikzscale@testTikzFile}{%
@@ -171,6 +161,29 @@
}%
\endgroup
}%
+\def\tikzscale@useEnhancedIncludegraphics{%
+\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
+}
+\def\tikzscale@FixEndLine{%
+\edef\tikzscale@restoreEndLineChar{\endlinechar=\the\endlinechar\relax}%
+\endlinechar=-1%
+\pretocmd{\tikzpicture}{%
+\tikzscale@restoreEndLineChar
+}{}{\PackageError{tikzscale}{Patching tikzpicture failed}}%
+\apptocmd{\endtikzpicture}{%
+\endlinechar=-1%
+}{}{\PackageError{tikzscale}{Patching endtikzpicture failed}}%
+}%
+\def\tikzscale@patchTikzpictureIncludegraphics{%
+\pretocmd{\tikzpicture}{%
+\LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}%
+}{}{\PackageError{tikzscale}{Patching tikzpicture failed}}%
+}
+\def\tikzscale@patchEndtikzpictureIncludegraphics{%
+\apptocmd{\endtikzpicture}{%
+\LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}%
+}{}{\PackageError{tikzscale}{Patching endtikzpicture failed}}%
+}
\NewDocumentCommand{\tikzscale@findExactFileName}{mm}{%
\csundef{#1}%
\def\tikzscale@checkDirectory##1{%