You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: tikzscale.dtx
+71-50
Original file line number
Diff line number
Diff line change
@@ -303,12 +303,12 @@ and the derived files tikzscale.ins,
303
303
% 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.
304
304
%
305
305
% \subsection{Externalization library}
306
-
% TikZ externalization library is supported.
306
+
% TikZ' externalization library is supported. Its use is highly recommended, as tikzscale renders some graphics multiple times to get the correct size. The savings by using the externalization library can thus be huge.
307
307
%
308
308
% \section{Further Ideas}
309
309
% \begin{itemize}
310
-
% \item At least give a clear error message for unscalable plots.
311
-
% \item the package can test if a pgfplot is used (needed due to keepAspectRatio in pgfplots) by changing the width and or height and measuring. If nothing changes, it must be a normal tikzpicture (the argument does not hold the other way round).
310
+
% \item How to support for imagesc plots something like "scale only axis, width=\cmd{\linewidth}, height=\cmd{\linewidth}" without writing into the margin?
311
+
% \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).
312
312
% \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.
313
313
% \end{itemize}
314
314
%
@@ -346,27 +346,17 @@ and the derived files tikzscale.ins,
346
346
%\end{macro}
347
347
%
348
348
%\begin{macro}{\tikzscale@scale}
349
-
% Set these as default values to allow a preview of tikzpicture environments in ktikz or the like. Global definitions are necessary, as local definitions result in errors in some situations.
350
-
%
351
-
% Use a scale factor for all tikzpicture environments. Set the factor to 1 as default, so if there are no additional scaling demands, just keep the tikzpicture unscaled. The internal redefinition of the style is correct, because if one tikzpicture includes another one, the scaling factor is reset so that it does not get squared in the inner one: http://tex.stackexchange.com/questions/38605/scaling-a-tikz-figure-from-an-external-file
% 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.
358
353
% \begin{macrocode}
359
354
\newlength{\tikzscale@accuracy}%
360
355
\setlength{\tikzscale@accuracy}{0.01pt}%
361
356
%
357
+
% 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.
@@ -408,7 +398,7 @@ and the derived files tikzscale.ins,
408
398
%\end{macro}
409
399
410
400
%
411
-
%\begin{macro}{\includegraphics}
401
+
%\begin{macro}{\activatetikzscale}
412
402
% \begin{macrocode}
413
403
\AtEndPreamble{%
414
404
% \end{macrocode}
@@ -427,30 +417,45 @@ and the derived files tikzscale.ins,
427
417
\def\tikzscale@graphicspath{{}}%
428
418
}%
429
419
% \end{macrocode}
430
-
% \item Save the \cmd{\includegraphics} \href{ftp://ftp.tu-chemnitz.de/pub/tex/macros/latex/required/graphics/grfguide.pdf}{command}, to have a consistent user interface.
420
+
% \item 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.
% Find the exact file name, as the ending and the path could be omitted.
432
+
% 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.
% 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.
@@ -518,15 +523,10 @@ and the derived files tikzscale.ins,
518
523
% If only one of width or height are given, scale proportionally to fullfil the requirement. If both are given, scale non-proportionally to required width and height. Therefore, for normal tikzpictures only give either width or height, as the aspect ratio is already determined by the coordinate limits in the tikzpicture, but give width and height for PGFPlots, as the aspect ratio is unknown for these plots. \cmd{\NewEnviron} could be used to handle something like verbose in a tikzpicture, but at the moment, this is unsupported.
% 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.
523
-
% \begin{macrocode}
524
526
\IfNoValueTF{#1}{%
525
527
\input{#2}%
526
528
}{%
527
-
\begingroup
528
529
\tikzscale@includeTikzSplitArguments{#2}#1%
529
-
\endgroup
530
530
}
531
531
}
532
532
% \end{macrocode}
@@ -542,9 +542,14 @@ and the derived files tikzscale.ins,
% Set a scaling factor or a width and height for the plot, which will be loaded. The \cmd{\tikzset} and \cmd{\pgfplotsset} commands have local scope. The internal redefinition of the style is correct, because if one tikzpicture includes another one, the scaling factor is reset so that it does not get \href{http://tex.stackexchange.com/questions/38605/scaling-a-tikz-figure-from-an-external-file}{squared} in the inner one. Note that if a user-defined style thus is ignored in this special case. The styles are defined here, so that files which are inputted without the \cmd{includegraphics} command are not affected.
% Use \cmd{\pgfmathsetmacro}, to allow calculations in the given argument.
564
+
% Use \cmd{\pgfmathsetmacro}, to allow calculations in the given argument. Do the calculation after checking the argument to output a useful error message in case the key is wrong.
560
565
% \begin{macrocode}
561
-
\pgfmathsetmacro{\tikzsize}{#2}%
562
566
\ifstrequal{#1}{width}{%
567
+
\pgfmathsetmacro{\tikzsize}{#2}%
563
568
\tikzscale@scaleTo{\wd}{\input{#3}}{#3}%
564
569
}{%
565
570
\ifstrequal{#1}{height}{%
571
+
\pgfmathsetmacro{\tikzsize}{#2}%
566
572
\tikzscale@scaleTo{\ht}{\input{#3}}{#3}%
567
573
}{%
568
574
\tikzscale@invalidKeyError{#1}%
@@ -595,6 +601,9 @@ and the derived files tikzscale.ins,
595
601
\tikzscale@invalidKeyError{#1 or #3}%
596
602
}%
597
603
}%
604
+
% \end{macrocode}
605
+
% Try to set initial sizes close to the requested sizes, to improve the optimization's speed.
606
+
% \begin{macrocode}
598
607
\def\tikzscale@width{\requestedWidth}%
599
608
\def\tikzscale@height{\requestedHeight}%
600
609
% \end{macrocode}
@@ -624,18 +633,14 @@ and the derived files tikzscale.ins,
624
633
% \end{macrocode}
625
634
% It can happen, that there are no variable areas. Furthermore, the original size could already fit. Avoid numerical problems in both cases by directly drawing the picture. Do not compare the float values directly, as TeX's precision is quite limited.
0 commit comments