summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tikzscale
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-05-22 23:11:03 +0000
committerKarl Berry <karl@freefriends.org>2013-05-22 23:11:03 +0000
commite7d5962cb25a83a847dcd4cbb693779486262433 (patch)
treecd765fe37a14f610b635ed3f97b19ea1914beb4c /Master/texmf-dist/tex/latex/tikzscale
parent640e5c86ccf9706a7d564f0bf722bab07510a8af (diff)
tikzscale (22may13)
git-svn-id: svn://tug.org/texlive/trunk@30637 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/tikzscale')
-rw-r--r--Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty101
1 files changed, 79 insertions, 22 deletions
diff --git a/Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty b/Master/texmf-dist/tex/latex/tikzscale/tikzscale.sty
index 3359cd5db86..fac78df85a3 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/03/30 v0.2.5 tikzscale LaTeX package]
+\ProvidesPackage{tikzscale}[2013/05/22 v0.2.6 tikzscale LaTeX package]
\RequirePackage{graphicx}
\RequirePackage{etoolbox}
\RequirePackage{pgfkeys}
@@ -35,6 +35,11 @@
\def\ifExternalizationLoaded#1#2{%
\ifTikzLibraryLoaded{external}{#1}{#2}%
}
+\def\ifedefequal#1#2{%
+\edef\etoolbox@ifedefequal@first{#1}%
+\edef\etoolbox@ifedefequal@second{#2}%
+\ifdefequal{\etoolbox@ifedefequal@first}{\etoolbox@ifedefequal@second}%
+}
\def\edocsvlist#1{%
\edef\tikzscale@edocsvlist{#1}%
\expandafter\docsvlist\expandafter{\tikzscale@edocsvlist}%
@@ -124,6 +129,7 @@
#2%
}%
}%
+\def\tikzscale@debug#1{}%
\AtEndPreamble{%
\def\tikzscale@tikzFileExtensions{.tikz,.TIKZ,.TikZ,.pgf,.PGF}%
\DeclareGraphicsExtensions{\tikzscale@tikzFileExtensions,\Gin@extensions}%
@@ -154,13 +160,16 @@
\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}}}%
-}{}%
+\tikzscale@writeToDpth{#1}{\tikzscale@oldAxisRatio}{\requestedAxisRatio}%
\fi
}%
}{}%
}
+\def\tikzscale@writeToDpth#1#2#3{%
+\ifdef{#3}{%
+\immediate\write#1{\noexpand\pgfexternal@restore{\noexpand\def\noexpand#2{#3}}}%
+}{}%
+}
\NewDocumentCommand{\tikzscale@includegraphics}{O{}m}{%
\begingroup
\LetLtxMacro{\includegraphics}{\tikzscale@oldincludegraphics}%
@@ -262,30 +271,36 @@ axisratio/.value required
\pgfkeys{/tikzscale, #1}%
\tikzscale@ifExternalizationActive{%
\tikzifexternalizingnext{%
-\tikzscale@includetikzUnexternalized[#1]{#2}%
+\tikzscale@debug{Externalizing the file #2}%
+\tikzscale@includetikzUnexternalized{#2}%
}{%
\tikzscale@includetikzWithExternalization{#2}%
}%
}{%
-\tikzscale@includetikzUnexternalized[#1]{#2}%
+\tikzscale@includetikzUnexternalized{#2}%
}%
}
-\NewDocumentCommand{\tikzscale@includetikzUnexternalized}{O{}m}{%
+\def\tikzscale@includetikzUnexternalized#1{%
\elseif{test {\ifundef{\requestedWidth}} and test {\ifundef{\requestedHeight}} and test {\ifundef{\requestedAxisRatio}}}{%
-\tikzscale@trim{\input{#2}}%
+\tikzscale@debug{no option given}%
+\tikzscale@trim{\input{#1}}%
}{test {\ifdef{\requestedWidth}} and test {\ifdef{\requestedHeight}}}{%
-\tikzscale@resizePlotTo{#2}%
+\tikzscale@debug{width and height given}%
+\tikzscale@resizePlotTo{#1}%
}{test {\ifdef{\requestedAxisRatio}}}{%
-\tikzscale@includeAxisRatio{#2}%
+\tikzscale@debug{axis ratio given}%
+\tikzscale@includeAxisRatio{#1}%
}{test {\ifundef{\requestedAxisRatio}}}{%
+\tikzscale@debug{width or height given}%
\ifdef{\pgfplotsset}{%
\def\requestedAxisRatio{1}%
-\tikzscale@includeAxisRatio{#2}%
+\tikzscale@includeAxisRatio{#1}%
}{%
-\tikzscale@includeNormalTikzpicture{#2}%
+\tikzscale@debug{no pgfplots loaded}%
+\tikzscale@includeNormalTikzpicture{#1}%
}%
}{%
-\tikzscale@invalidKeyError{#2}%
+\tikzscale@invalidKeyError{#1}%
}%
}
@@ -302,29 +317,34 @@ axisratio/.value required
\ifdef{\pgfexternalwidth}{%
\tikzscale@ifSizeDifference{\requestedWidth - \pgfexternalwidth}{%
\tikzset{external/remake next}%
+\tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of width difference \MessageBreak (requestedWidth=\requestedWidth, pgfexternalwidth=\pgfexternalwidth)}%
}{}%
}{%
\tikzset{external/remake next}%
+\tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of no external width}%
}%
}{}%
\ifdef{\requestedHeight}{%
\ifdef{\pgfexternalheight}{%
\tikzscale@ifSizeDifference{\requestedHeight - \pgfexternalheight}{%
\tikzset{external/remake next}%
+\tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of height difference \MessageBreak (requestedHeight=\requestedHeight, pgfexternalheight=\pgfexternalheight)}%
}{}%
}{%
\tikzset{external/remake next}%
+\tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of no external height}%
}%
}{}%
\ifdef{\requestedAxisRatio}{%
\ifdef{\tikzscale@oldAxisRatio}{%
\tikzscale@ifSizeDifference{\requestedAxisRatio - \tikzscale@oldAxisRatio}{%
\tikzset{external/remake next}%
+\tikzscale@debug{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}%
+\tikzscale@debug{Regenerate \tikzscale@externalizationName \MessageBreak because of no external axis ratio}%
}%
}{}%
}
@@ -366,6 +386,7 @@ axisratio/.value required
}%
}
\NewDocumentCommand{\tikzscale@scaleTikzpictureTo}{mmm}{%
+\tikzscale@debug{At beginning scale, requestedWidth=\requestedWidth}%
\tikzscale@conditionalDisableExternalization
\def\tikzscale@scale{1}%
\tikzscale@measureSize{\measuredFirst}{#1}{#2}%
@@ -382,20 +403,52 @@ axisratio/.value required
\tikzscale@measureSize{\measuredIntermediate}{#1}{#2}%
\tikzscale@ifSizeDifference{\measuredIntermediate-\requestedSize}{%
\pgfmathsetmacro{\errorRatio}{\measuredIntermediate/\requestedSize}%
+\tikzscale@debug{errorRatio=\errorRatio\MessageBreak for #3}%
\pgfmathsetglobalmacro{\tikzscale@scale}{\tikzscale@scale/\errorRatio}%
}{%
\breakforeach%
}%
}%
-\tikzscale@conditionalEnableExternalization{#3}%
+ % Do a last measurement to be able to warn if the size does not fit good enough. This measurement has to be done before possibly reactivating the externalization, as measurements with activated externalization can lead to wrong measurement results (possibly due to calling \cmd{\shipout} inside of the measurement). The assumption is, that the real graphic size does not change if the externalization gets activated, which all tests seem to confirm.
\tikzscale@measureSize{\measuredFinal}{#1}{#2}%
-\usebox{\tikzscale@measuredSize}%
\tikzscale@warnIfSizeDifference{\measuredFinal}{\requestedSize}{#3}%
+\tikzscale@testGraphicFileForRetry{#1}{#2}{#3}{\measuredFinal}%
}{%
+\tikzscale@testGraphicFileForRetry{#1}{#2}{#3}{\measuredSecond}%
+}%
+}
+\def\tikzscale@testGraphicFileForRetry#1#2#3#4{%
\tikzscale@conditionalEnableExternalization{#3}%
+\tikzscale@ifExternalizationActive{%
+\tikzexternalgetnextfilename{\tikzscale@externalizationName}%
+}{}%
#2%
+\tikzscale@ifExternalizationActive{%
+\pgfexternalreaddpth{\tikzscale@externalizationName}%
+\tikzscale@ifIsWidth{#1}{%
+\edef\pgfexternalsize{\pgfexternalwidth}%
+}{%
+\edef\pgfexternalsize{\pgfexternalheight}%
}%
+\ifundef{\originalRequestedSize}{%
+\let\originalRequestedSize\requestedSize
+}{}%
+\tikzscale@debug{originalRequestedSize=\originalRequestedSize, requestedSize=\requestedSize, pgfexternalsize=\pgfexternalsize}%
+\tikzscale@ifSizeDifference{\originalRequestedSize-\pgfexternalsize}{%
+\pgfmathsetmacro{\requestedSize}{\requestedSize + #4 - \pgfexternalsize}%
+\tikzscale@decreaseFigureCounter
+\tikzscale@scaleTikzpictureTo{#1}{#2}{#3}%
+}{}%
+}{}%
}
+\def\tikzscale@decreaseFigureCounter{%
+\begingroup
+\edef\macroName{c@tikzext@no@\pgfkeysvalueof{/tikz/external/figure name}}%
+\c@pgf@counta=\csuse{\macroName}\relax
+\advance\c@pgf@counta -1\relax
+\expandafter\xdef\csname\macroName\endcsname{\the\c@pgf@counta}%
+\endgroup
+}%
\NewDocumentCommand{\tikzscale@resizePlotTo}{m}{%
\def\fileName{#1}%
\def\content{\tikzscale@trim{\input{#1}}}%
@@ -414,11 +467,11 @@ axisratio/.value required
\breakforeach
}%
}%
-\tikzscale@conditionalEnableExternalization{\fileName}%
\sbox{\tikzscale@measuredSize}{\content}%
-\usebox{\tikzscale@measuredSize}%
\tikzscale@warnIfSizeDifference{\requestedWidth}{\wd\tikzscale@measuredSize}{\fileName's width}%
\tikzscale@warnIfSizeDifference{\requestedHeight}{\ht\tikzscale@measuredSize}{\fileName's height}%
+\tikzscale@conditionalEnableExternalization{\fileName}%
+\content%
}
\NewDocumentCommand{\tikzscale@resizePlotWithAxesRatioTo}{mmmm}{%
@@ -433,7 +486,7 @@ axisratio/.value required
\tikzscale@measureSize{\measuredSize}{\dimension}{\content}%
\pgfmathsetmacro{\sizeDifference}{\measuredSize - \requestedSize}%
\tikzscale@ifSizeDifference{\sizeDifference}{%
-\ifdefstring{\dimension}{\wd}{%
+\tikzscale@ifIsWidth{\dimension}{%
\pgfmathsetglobalmacro{\tikzscale@width}{\tikzscale@width - \sizeDifference}%
\pgfmathsetglobalmacro{\tikzscale@height}{\tikzscale@width / \requestedAxisRatio}%
}{%
@@ -455,12 +508,16 @@ axisratio/.value required
\ifdef{\tikzscale@alreadyIncluded}{%
\global\undef\tikzscale@alreadyIncluded%
}{%
-\tikzscale@conditionalEnableExternalization{\fileName}%
+ % Do a last measurement to be able to warn if the size does not fit good enough. This measurement has to be done before possibly reactivating the externalization, as measurements with activated externalization can lead to wrong measurement results (possibly due to calling \cmd{\shipout} inside of the measurement). The assumption is, that the real graphic size does not change if the externalization gets activated, which all tests seem to confirm.
\tikzscale@measureSize{\measuredFinal}{\dimension}{\content}%
-\usebox{\tikzscale@measuredSize}%
\tikzscale@warnIfSizeDifference{\measuredFinal}{\requestedSize}{\fileName}%
+\tikzscale@conditionalEnableExternalization{\fileName}%
+\content%
}%
}
+\def\tikzscale@ifIsWidth#1{%
+\ifedefequal{#1}{\wd}%
+}
\newsavebox{\tikzscale@measuredSize}
\def\tikzscale@measureSize#1#2#3{%
\sbox{\tikzscale@measuredSize}{#3}%
@@ -484,7 +541,7 @@ axisratio/.value required
\tikzscale@ifExternalizationActive{%
\tikzexternaldisable
\def\tikzscale@externalizationWasDisabled{}%
-}{}
+}{}%
\ifExternalizationLoaded{%
\tikzscale@addRestoreEndLineCharToTikzpicture
}{}%