diff options
Diffstat (limited to 'Master/texmf-dist/source')
-rw-r--r-- | Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx | 106 |
1 files changed, 70 insertions, 36 deletions
diff --git a/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx b/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx index adea32dc79e..59b0b4f2596 100644 --- a/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx +++ b/Master/texmf-dist/source/latex/tikzscale/tikzscale.dtx @@ -16,7 +16,6 @@ tikzpictures. It allows scaling of TikZ images and PGFPlots to a provided width or height without changing the text size. Usage: \usepackage{tikzscale} - or \usepackage[loadFromCurrentDirectory]{tikzscale} As an example write \includegraphics{myTikZFile.tikz} @@ -95,7 +94,7 @@ and the derived files tikzscale.ins, %</internal> %<*package> \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{tikzscale}[2013/01/02 v0.2 tikzscale LaTeX package] +\ProvidesPackage{tikzscale}[2013/01/09 v0.2.1 tikzscale LaTeX package] \RequirePackage{graphicx} \RequirePackage{etoolbox} \RequirePackage{pgfkeys} @@ -188,6 +187,7 @@ and the derived files tikzscale.ins, %\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} +%\changes{v0.2.1}{2013/01/09}{Fix graphics with data from text file due to wrong line breaks; fix plain old \LaTeX support} % \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} @@ -361,7 +361,7 @@ 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. +% 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 or 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. @@ -371,6 +371,7 @@ and the derived files tikzscale.ins, % % \section{Further Ideas} % \begin{itemize} +% \item The \cmd{\tikzscale@trim} commands generates a warning in the figure log files that "Scaling of linewidth.tikz was only (tikzscale) accurate to 202.83331pt on input line 30." and other warnings, but they do not seem to have any influence. % \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. @@ -404,6 +405,11 @@ and the derived files tikzscale.ins, % \item devendra % \begin{itemize} % \item Reported bugs when using the externalization library together with tikzscale, which lead to a fix. +% \item Reported a problem when using data files, which lead to a fix regarding \cmd{\endlinechar}. +% \end{itemize} +% \item Mohammad Reza Keshtkaran +% \begin{itemize} +% \item Reported a bug when using plain old \LaTeX with an eps file, which lead to a fix. % \end{itemize} % \end{itemize} % @@ -530,6 +536,15 @@ and the derived files tikzscale.ins, % \end{macrocode} %\end{macro} % +%\begin{macro}{\tikzscale@trim} +% These is a general command to trim leading and trailing spaces, which might be useful for inclusion into another package taken from the following \href{http://www.matijs.net/blog/2006/07/20/how-to-trim-spaces-in-tex}{homepage}. +% \begin{macrocode} +\def\tikzscale@trim#1{% + \ignorespaces#1\unskip +}% +% \end{macrocode} +%\end{macro} +% % \begin{macro}{\elseif} % This macro provides a conditional which supports an if with an arbitrary amount of elseif (none is also ok) and an optional else. With a simplified syntax (remove the tests and the grouping) this would be worth a separate package. % \begin{macrocode} @@ -602,12 +617,28 @@ and the derived files tikzscale.ins, % \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. + % 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. % \begin{macrocode} - \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}}% + \pretocmd{\tikzpicture}{% + \LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}% + }{}{\PackageError{tikzscale}{Patching tikzpicture failed}}% + % + \apptocmd{\endtikzpicture}{% + \LetLtxMacro{\includegraphics}{\tikzscale@includegraphics}% + }{}{\PackageError{tikzscale}{Patching endtikzpicture failed}}% +% \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} + \apptocmd{\tikzpicture}{% +% \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. +% \begin{macrocode} + \ifdef{\tikzscale@restoreEndLineChar}{% + \tikzscale@restoreEndLineChar + }{}% + }{}{\PackageError{tikzscale}{Patching tikzpicture 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). @@ -661,29 +692,32 @@ 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?). +% \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}% + \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. + % 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. % \begin{macrocode} - \edef\tikzscale@restoreEndLineChar{\endlinechar=\the\endlinechar\relax}% - \endlinechar=-1% + \edef\tikzscale@restoreEndLineChar{\endlinechar=\the\endlinechar\relax}% + \endlinechar=-1% % \end{macrocode} - % Find the exact file name, as the ending and the path could be omitted. + % Find the exact file name, as the ending and the path could be omitted. % \begin{macrocode} - \tikzscale@findExactFileName{tikzscale@fileName}{#2}% + \tikzscale@findExactFileName{tikzscale@fileName}{#2}% % \end{macrocode} - % Check if the found file is a TikZ file. - % \begin{macrocode} - \tikzscale@isTikzFile{tikzscale@testTikzFile}{\tikzscale@fileName}% - \ifcsdef{tikzscale@testTikzFile}{% - \tikzscale@includetikz[#1]{\tikzscale@fileName}% - }{% - \tikzscale@oldincludegraphics[#1]{\tikzscale@fileName}% - }% - \tikzscale@restoreEndLineChar + % Check if the found file is a TikZ file. +% \begin{macrocode} + \tikzscale@isTikzFile{tikzscale@testTikzFile}{\tikzscale@fileName}% + \ifcsdef{tikzscale@testTikzFile}{% + \tikzscale@includetikz[#1]{\tikzscale@fileName}% + }{% +% \end{macrocode} + % Restore \cmd{\endlinechar} before calling code from other packages. This is not only cleaner, but really avoids an error when using the plain old latex (with dvi output) with an eps graphic. +% \begin{macrocode} + \tikzscale@restoreEndLineChar + \tikzscale@oldincludegraphics[#1]{\tikzscale@fileName}% + }% \endgroup }% % \end{macrocode} @@ -807,7 +841,7 @@ and the derived files tikzscale.ins, % \end{macrocode} % If no option is given, directly load the content, as nothing should get scaled. % \begin{macrocode} - \input{#2}% + \tikzscale@trim{\input{#2}}% }{test {\ifdef{\requestedWidth}} and test {\ifdef{\requestedHeight}}}{% % \end{macrocode} % If width and height are given, the content must be a pgfplot, so scale it. The plot currently only had approximately the given size without calling the resizeTo macro, due to a (known) bug in PGFPlots. @@ -854,7 +888,7 @@ and the derived files tikzscale.ins, \IfFileExists{\tikzscale@externalizationName.dpth}{% \tikzscale@checkRequestedSizeChanges }{}% - \input{#1}% + \tikzscale@trim{\input{#1}}% } % \end{macrocode} %\end{macro} @@ -869,8 +903,8 @@ and the derived files tikzscale.ins, \ifdef{\pgfexternalwidth}{% \tikzscale@ifSizeDifference{\requestedWidth - \pgfexternalwidth}{% \tikzset{external/remake next}% -% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of width difference}% -% \tikzscale@warnIfSizeDifference{\requestedWidth}{\pgfexternalwidth}{#2}% +% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of width difference \MessageBreak (requestedWidth: \requestedWidth, pgfexternalwidth: \pgfexternalwidth)}% +% \tikzscale@warnIfSizeDifference{\requestedWidth}{\pgfexternalwidth}{current file}% }{}% }{% \tikzset{external/remake next}% @@ -881,7 +915,7 @@ and the derived files tikzscale.ins, \ifdef{\pgfexternalheight}{% \tikzscale@ifSizeDifference{\requestedHeight - \pgfexternalheight}{% \tikzset{external/remake next}% -% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of height difference}% +% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of height difference \MessageBreak (requestedHeight: \requestedHeight, pgfexternalheight: \pgfexternalheight)}% }{}% }{% \tikzset{external/remake next}% @@ -892,12 +926,12 @@ and the derived files tikzscale.ins, \ifdef{\tikzscale@oldAxisRatio}{% \tikzscale@ifSizeDifference{\requestedAxisRatio - \tikzscale@oldAxisRatio}{% \tikzset{external/remake next}% -% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of axis ratio difference}% +% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of axis ratio difference \MessageBreak (requestedAxisRatio: \requestedAxisRatio, oldAxisRatio: \tikzscale@oldAxisRatio)}% }{}% \undef{\tikzscale@oldAxisRatio}% }{% \tikzset{external/remake next}% -% \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of no external axis ratio}% + \PackageWarning{tikzscale}{Regenerate \tikzscale@externalizationName \MessageBreak because of no external axis ratio}% }% }{}% } @@ -925,10 +959,10 @@ and the derived files tikzscale.ins, \tikzscale@prepareTikzpicture \elseif{test {\ifdef{\requestedWidth}} and test {\ifundef{\requestedHeight}}}{% \def\requestedSize{\requestedWidth}% - \tikzscale@scaleTikzpictureTo{\wd}{\input{#1}}{#1}% + \tikzscale@scaleTikzpictureTo{\wd}{\tikzscale@trim{\input{#1}}}{#1}% }{test {\ifundef{\requestedWidth}} and test {\ifdef{\requestedHeight}}}{% \def\requestedSize{\requestedHeight}% - \tikzscale@scaleTikzpictureTo{\ht}{\input{#1}}{#1}% + \tikzscale@scaleTikzpictureTo{\ht}{\tikzscale@trim{\input{#1}}}{#1}% }{% \tikzscale@invalidKeyError{#1}% }% @@ -956,12 +990,12 @@ and the derived files tikzscale.ins, \let\requestedSize\requestedWidth \def\tikzscale@width{\requestedWidth}% \pgfmathsetmacro{\tikzscale@height}{\requestedWidth / \requestedAxisRatio}% - \tikzscale@resizePlotWithAxesRatioTo{\wd}{\tikzscale@width}{\input{#1}}{#1}% + \tikzscale@resizePlotWithAxesRatioTo{\wd}{\tikzscale@width}{\tikzscale@trim{\input{#1}}}{#1}% }{test {\ifundef{\requestedWidth}} and test {\ifdef{\requestedHeight}}}{% \let\requestedSize\requestedHeight \def\tikzscale@height{\requestedHeight}% \pgfmathsetmacro{\tikzscale@width}{\requestedHeight * \requestedAxisRatio}% - \tikzscale@resizePlotWithAxesRatioTo{\ht}{\tikzscale@height}{\input{#1}}{#1}% + \tikzscale@resizePlotWithAxesRatioTo{\ht}{\tikzscale@height}{\tikzscale@trim{\input{#1}}}{#1}% }{% \tikzscale@invalidKeyError{#1}% }% @@ -1057,7 +1091,7 @@ and the derived files tikzscale.ins, % \begin{macrocode} \NewDocumentCommand{\tikzscale@resizePlotTo}{m}{% \def\fileName{#1}% - \def\content{\input{#1}}% + \def\content{\tikzscale@trim{\input{#1}}}% \tikzscale@preparePlot \def\tikzscale@width{\requestedWidth}% \def\tikzscale@height{\requestedHeight}% |