diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex')
-rw-r--r-- | Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex | 492 |
1 files changed, 465 insertions, 27 deletions
diff --git a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex index e3094554af6..781f5e4937d 100644 --- a/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex +++ b/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotsutil.code.tex @@ -24,29 +24,11 @@ % %-------------------------------------------- -\def\pgfplots@EOI{\pgfplots@EOI}% - -\newtoks\t@pgfplots@toka -\newtoks\t@pgfplots@tokb -\newtoks\t@pgfplots@tokc -\newdimen\pgfplots@tmpa - -% use these macros for GLOBAL temporary assignments. -% you can NEVER rely on their values unless you know exactly what you are doing. -\gdef\pgfplots@glob@TMPa{}% -\gdef\pgfplots@glob@TMPb{}% -\gdef\pgfplots@glob@TMPc{}% - -% use these macros for LOCAL temporary assigments. -% you can NEVER rely on their values unless you know exactly what you are doing. -\def\pgfplots@loc@TMPa{}% -\def\pgfplots@loc@TMPb{}% -\def\pgfplots@loc@TMPc{}% - -\input pgfplotsliststructure.code.tex -\input pgfplotsliststructureext.code.tex -\input pgfplotsarray.code.tex -\input pgfplotstable.code.tex +\newif\ifpgfplots@usefpu +\pgfkeys{% + /pgfplots/use fpu/.is if=pgfplots@usefpu, + /pgfplots/use fpu=true, +} % Produces an \aftergroup statement for each single token in #1. % @@ -105,10 +87,18 @@ \fi }% -\def\pgfplots@error#1{\PackageError{pgfplots}{#1}{}}% -\def\pgfplots@warning#1{\pgfplots@message{! Package pgfplots Warning: #1}}% -\def\pgfplots@message#1{% - \immediate\write16{#1}% +% Issues an error message if the **LaTeX** package '#1' is not loaded +% (An error is also raised if the document is not a LaTeX document). +% #1: the required LaTeX package +% #2: the feature which requires this package +\def\pgfplots@assert@LaTeX@package@loaded#1#2{% + \pgfutil@ifundefined{@ifpackageloaded}{% + \pgfplots@error{Sorry, #2 only works with LaTeX (it relies on the LaTeX package #1)}% + }{% + \pgfutil@ifundefined{ver@#1.sty}% this here has been extracted from ltclass.dtx. \@ifpackageloaded is only usable in preamble. + {\pgfplots@error{Sorry, use need \string\usepackage{#1} in your preamble for '#2'}}% + {\relax}% + }% }% \def\pgfplots@assert@tikzinternal@exists#1{% \pgfutil@ifundefined{#1}{% @@ -192,6 +182,11 @@ \def#2{#1}% }% +{ +\catcode`\%=12 +\gdef\pgfplots@PERCENT@TEXT{%} +} + % Usage: % \pgfplots@if{pgfplots@scaled@ticks}{true-code}{false-code} % @@ -204,3 +199,446 @@ #3% \fi }% + +\def\pgfplotsmathmin#1#2{% + \ifdim#1 pt<#2 pt + \edef\pgfmathresult{#1}% + \else + \edef\pgfmathresult{#2}% + \fi +}% +\def\pgfplotsmathmax#1#2{% + \ifdim#1 pt>#2 pt + \edef\pgfmathresult{#1}% + \else + \edef\pgfmathresult{#2}% + \fi +}% +\def\pgfplotsmathlessthan#1#2{\ifdim#1 pt<#2 pt \pgfmathfloatcomparisontrue\else\pgfmathfloatcomparisonfalse\fi} + +% Re-define two-argument function for min and max. +% The pgfmath engine now uses a variable number of arguments. +\def\pgfplotsmathfloatmax#1#2{% + \pgfmathfloatlessthan{#1}{#2}% + \ifpgfmathfloatcomparison + \edef\pgfmathresult{#2}% + \else + \edef\pgfmathresult{#1}% + \fi +} +\def\pgfplotsmathfloatmin#1#2{% + \pgfmathfloatlessthan{#1}{#2}% + \ifpgfmathfloatcomparison + \edef\pgfmathresult{#1}% + \else + \edef\pgfmathresult{#2}% + \fi +} + +% Defines \pgfmathresult to be #1 * 10^{#2}. +% +% #1 a macro without unit suffix. +% #2 an integer number (may be a register) +\def\pgfplotsmathmultiplypowten@#1#2{% + \begingroup + \pgf@xa=#1pt + \ifnum#2<0 + \ifcase-#2 + \or\divide\pgf@xa by10 + \or\divide\pgf@xa by100 + \or\divide\pgf@xa by1000 + \or\divide\pgf@xa by10000 + \or\divide\pgf@xa by100000 + \fi + \else + \ifcase#2 + \or\multiply\pgf@xa by10 + \or\multiply\pgf@xa by100 + \or\multiply\pgf@xa by1000 + \or\multiply\pgf@xa by10000 + \or\multiply\pgf@xa by100000 + \fi + \fi + \edef\pgfmathresult{\pgf@sys@tonumber{\pgf@xa}}% + \pgfmath@smuggleone\pgfmathresult + \endgroup +}% + + +% converts a comma-separated list (PGF foreach) to my internal list +% structure. +\long\def\pgfplots@foreach@to@list#1\to#2{% + \global\pgfplotslistnewempty\pgfplots@glob@TMPa + \begingroup + \foreach \pgfplots@i in {#1} {% + \expandafter\pgfplotslistpushbackglobal\pgfplots@i\to\pgfplots@glob@TMPa + }% + \endgroup + \pgfplotslistcopy\pgfplots@glob@TMPa\to#2\relax +} + +% Simply invokes the code of PGF key #1 with value #2, that means +% #1#2\pgfeov +\def\pgfplots@invoke@pgfkeyscode#1#2{% + \pgfkeysgetvalue{#1}\pgfplots@invoke@pgfkeyscode@CODE + \pgfplots@invoke@pgfkeyscode@CODE#2\pgfeov +} + + +% Usage: +% \pgfplots@letcsname pgfplots@xtick={pgfplots@kram@x} +% -> invokes \csname ... \endcsname for both args. +\def\pgfplots@letcsname#1=#2{% + \expandafter\let\expandafter\pgfplots@loc@TMPc\csname #2\endcsname + \expandafter\let\csname #1\endcsname=\pgfplots@loc@TMPc +}% + +% I have introduced this macro to allow optimizations of (x,y) +% coordinate processing. Use it for everything which is directly plot +% related. +% +% @see \pgfplotsqpointxy@orthogonal +\let\pgfplotsqpointxy=\pgfqpointxy +\let\pgfplotsqpointxyz=\pgfqpointxyz + +% A "quick" quick variant of \pgfqpointxy which assumes that +% the X unit vector is ( e_xx,0 )^T and the Y unit vector is ( 0, +% e_yy)^T. +% +% In words, the unit vectors are orthogonal. This is the usual case +% for two-dimensional plots and shall be optimized. +\def\pgfplotsqpointxy@orthogonal#1#2{% + \pgf@x=#1\pgf@xx% + \pgf@y=#2\pgf@yy} + + +% Takes a domain as input and generates a foreach argument which +% samples from the domain. +% Writes the result to \pgfplotslocretval +% INPUT: +% #1:#2 the domain +% /pgfplots/samples the number of samples +% OUTPUT: +% \pgfplotslocretval a foreach specification. +\def\pgfplots@domain@to@foreach#1:#2\relax{% + \pgfmathparse{#1}% + \let\pgfplots@loc@TMPa=\pgfmathresult% + \pgfmathparse{#2}% + \let\pgfplots@loc@TMPb=\pgfmathresult% + \pgfmathparse{\pgfplots@loc@TMPa+(\pgfplots@loc@TMPb-\pgfplots@loc@TMPa)/(\pgfkeysvalueof{/pgfplots/samples}-1)}% + \edef\pgfplotslocretval{\pgfplots@loc@TMPa,\pgfmathresult,...,\pgfplots@loc@TMPb}% +} + +{ + \catcode`\;=\active + \catcode`\:=\active + \gdef\pgfplots@activesemicolon{;}% + \gdef\pgfplots@activecolon{:}% +} + +% checks whether ';' is active and replaces a sequence of commands +% accordingly. +% +% @see \pgfplots@appendto@activesemicolon@switcher +\def\pgfplots@checkandpreparefor@active@semicolon{% + \ifnum\the\catcode`\;=\active\relax + \pgfplots@checkandpreparefor@active@semicolon@ + \fi +}% +\def\pgfplots@checkandpreparefor@active@semicolon@{}% + +% Adds all commands '#1' to the sequence of commands which will be +% issued in case ';' is active. +\def\pgfplots@appendto@activesemicolon@switcher#1{% + \expandafter\def\expandafter\pgfplots@checkandpreparefor@active@semicolon@\expandafter{% + \pgfplots@checkandpreparefor@active@semicolon@ + #1% + }% +}% + + +% Usage: +% \pgfplotsforeachentryinCSV{\value}{1,2,3,4.5,6.7,10}{The value is \value\par} +% +% The loop is ungrouped. +\long\def\pgfplotsforeachentryinCSV#1#2#3{% + \def\pgfplotsforeachentryinCSV@{#1}% + \long\def\pgfplotsforeachentryinCSV@@{#3}% + \pgfplotsforeachentryinCSV@loop#2,\pgfplots@EOI +}% +% A variant of \pgfplotsforeachentryinCSV where a trailing comma +% indicates the end of input. +% Example: +% +% \pgfplotsforeachentryinCSV{\value}{1,2,3,4.5,6.7,10,}{The value is \value\par} +% ^ +% +% It is permissable to provide an empty list (without trailing comma) +\long\def\pgfplotsforeachentryinCSVisterminated#1#2#3{% + \def\pgfplotsforeachentryinCSV@{#1}% + \long\def\pgfplotsforeachentryinCSV@@{#3}% + \pgfplotsforeachentryinCSV@loop#2\pgfplots@EOI +}% +\def\pgfplotsforeachentryinCSV@loop{% + \pgfutil@ifnextchar\pgfplots@EOI{% + \pgfutil@gobble + }{% + \pgfplotsforeachentryinCSV@next + }% +}% +\def\pgfplotsforeachentryinCSV@next#1,{% + \expandafter\def\pgfplotsforeachentryinCSV@{#1}% + \pgfplotsforeachentryinCSV@@ + \pgfplotsforeachentryinCSV@loop +}% + + +% A (simple) replacement for \foreach which +% 1. does NOT scope the argument +% 2. allows to use PGF Math routines for loops ( '...' notation) +% instead of TeX registers. +% +% Usage: +% \pgfplotsforeachungrouped \x in {1,2,3,4,5} {<code>} +% +% Some details: +% - If #2 is a UNIFORM SAMPLING RANGE, the algorithm is supposed to be +% most effective. +% - If \pgfmathadd@ is the standard PGF math version of \pgfmathadd@, +% we use fast TeX dimensions for any loops. Otherwise, \pgfmathadd@ +% is used (assuming it has been replaced and should be used. +% +\def\pgfplotsforeachungrouped#1{\pgfplotsforeachungrouped@{#1}}% +\long\def\pgfplotsforeachungrouped@#1in #2#3{% + \pgfplotsforeachungrouped@isuniform{#2}% + \ifpgfplots@loc@tmp + \pgfplotsforeachungroupeduniform@#1{#2}{#3}% + \else + \pgfplotsforeachungroupednonuniform@#1{#2}{#3}% + \fi +} +\let\pgfplots@original@pgfmathadd@=\pgfmathadd@ + +\long\def\pgfplotsforeachungroupeduniform@#1#2#3{% + \pgfplotsforeachungroupeduniform@@{#1}#2\relax{#3}% +} +\long\def\pgfplotsforeachungroupeduniform@@#1#2,#3,...,#4\relax#5{% + % Compute mesh width! + \pgfmathparse{#2}% + \let\pgfplots@foreach@loc@TMPa=\pgfmathresult + \pgfmathparse{#3}% + \let\pgfplots@foreach@loc@TMPb=\pgfmathresult + \pgfmathsubtract@{\pgfplots@foreach@loc@TMPb}{\pgfplots@foreach@loc@TMPa}% + \ifx\pgfmathadd@\pgfplots@original@pgfmathadd@ + % perform manual restoration of local variables: + \edef\pgfplots@foreach@loc@TMPd{% + \noexpand\pgf@xa=\the\pgf@xa\noexpand\relax + \noexpand\pgf@xb=\the\pgf@xb\noexpand\relax + \noexpand\pgf@ya=\the\pgf@ya\noexpand\relax + }% + % mesh width: + \pgf@ya=\pgfmathresult pt + % the loop will run while ( NOT <cur> \pgfplots@foreach@loc@cmp <last> ) + \ifdim\pgf@ya<0pt + \def\pgfplots@foreach@loc@cmp{<}% + \else + \def\pgfplots@foreach@loc@cmp{>}% + \fi + % + \pgfmathparse{#4}% + \let\pgfplots@foreach@loc@TMPb=\pgfmathresult + \pgf@xa=\pgfplots@foreach@loc@TMPa pt + \pgf@xb=\pgfplots@foreach@loc@TMPb pt + \long\def\pgfplots@foreach@loc@TMPc{#5}% + % + \pgfutil@loop + \ifdim\pgf@xa \pgfplots@foreach@loc@cmp \pgf@xb\relax + \pgfplots@loc@tmpfalse + \else + \pgfplots@loc@tmptrue + \fi + \ifpgfplots@loc@tmp + \edef#1{\pgf@sys@tonumber{\pgf@xa}}% + \pgfplots@foreach@loc@TMPc\relax + \advance\pgf@xa by\pgf@ya\relax + \pgfutil@repeat + % ok, restore them: + \pgfplots@foreach@loc@TMPd + \else + % Use \pgfmath engine for the loop: + \edef\pgfplots@foreach@loc@TMPd{% + \noexpand\pgf@xa=\the\pgf@xa\noexpand\relax + }% + % mesh width: + \let\pgfplots@foreach@loc@meshwidth=\pgfmathresult + \pgfmathparse{0}% invoke the parser - in case the fpu is active. + \pgfmathlessthan@{\pgfplots@foreach@loc@meshwidth}{\pgfmathresult}% + \pgf@xa=\pgfmathresult pt + % the loop will run while ( NOT \pgfplots@foreach@loc@cmp{<cur>}{<last>} ) + \ifdim\pgf@xa=1pt + \let\pgfplots@foreach@loc@cmp=\pgfmathlessthan@ + \else + \let\pgfplots@foreach@loc@cmp=\pgfmathgreaterthan@ + \fi + % + \pgfmathparse{#4}% + \let\pgfplots@foreach@loc@TMPb=\pgfmathresult + \long\def\pgfplots@foreach@loc@TMPc{#5}% + % + \pgfutil@loop + \pgfplots@foreach@loc@cmp{\pgfplots@foreach@loc@TMPa}{\pgfplots@foreach@loc@TMPb}% + \pgf@xa=\pgfmathresult pt + \ifdim\pgf@xa=0pt + \let#1=\pgfplots@foreach@loc@TMPa% + \pgfplots@foreach@loc@TMPc\relax + \pgfmathadd@{\pgfplots@foreach@loc@TMPa}{\pgfplots@foreach@loc@meshwidth}% + \let\pgfplots@foreach@loc@TMPa=\pgfmathresult + \pgfutil@repeat + % ok, restore them: + \pgfplots@foreach@loc@TMPd + \fi +}% +\long\def\pgfplotsforeachungroupednonuniform@#1#2#3{% + \pgfplotsapplistXXglobalnewempty + \foreach\pgfplots@foreach@loc@TMPa in {#2} {% + \expandafter\pgfplotsapplistXXglobalpushback\expandafter{\pgfplots@foreach@loc@TMPa,}% + }% + \pgfplotsapplistXXgloballet\pgfplots@foreach@loc@TMPa + \pgfplotsapplistXXglobalclear + \expandafter\pgfplotsforeachentryinCSVisterminated\expandafter\pgfplots@foreach@loc@TMPa\expandafter{\pgfplots@foreach@loc@TMPa}{% + \let#1=\pgfplots@foreach@loc@TMPa + #3% + }% +} + +% Sets \ifpgfplots@loc@tmp to something true if and only if '#1' is of the form +% #1 = <number1>,<number2>,...,<number3>. +\def\pgfplotsforeachungrouped@isuniform#1{% + \edef\pgfplots@foreach@loc@TMPa{#1}% + \expandafter\pgfplotsforeachungrouped@isuniform@\pgfplots@foreach@loc@TMPa,,,,\relax +}% +\def\pgfplotsforeachungrouped@isuniform@#1,#2,#3,#4,#5\relax{% + \def\pgfplots@foreach@loc@TMPa{#5}% + \def\pgfplots@foreach@loc@TMPb{,,,}% + \pgfplots@loc@tmpfalse + \ifx\pgfplots@foreach@loc@TMPa\pgfplots@foreach@loc@TMPb + \def\pgfplots@foreach@loc@TMPa{#3}% + \def\pgfplots@foreach@loc@TMPb{...}% + \ifx\pgfplots@foreach@loc@TMPa\pgfplots@foreach@loc@TMPb + \pgfutil@in@,{#4}% + \ifpgfutil@in@ + \else + % ok, we REALLY have a uniform range! + \pgfplots@loc@tmptrue + \fi + \fi + \fi +}% + +% Allows to provide an output routine for +% \pgfplotsforeachlogarithmicungrouped which changes the number format +% of \pgfmathresult. +% +% Example: +% \pgfplotsforeachlogarithmicformatresultwith{\pgfmathfloattofixed{\pgfmathresult}} +% +% #1: is code which modifies \pgfmathresult. +\def\pgfplotsforeachlogarithmicformatresultwith#1{% + \def\pgfplotsforeachlogarithmicungrouped@finalizeresult{#1}% +} + +% \pgfplotsforeachlogarithmicungrouped \x/\logx in {a:b} {#3} +% +% samples \x between a and b using a logarithmic scale. +% +% During '#3', \x will contain the sample and \logx the logarithm of +% \x. +% +% Both, #1 and #2 will be provided as floating point numbers unless +% configured otherwise with \pgfplotsforeachlogarithmicsetoutput, +% see above. +% +\def\pgfplotsforeachlogarithmicungrouped#1/#2{\pgfplotsforeachlogarithmicungrouped@{#1}{#2}}% +\long\def\pgfplotsforeachlogarithmicungrouped@#1#2in #3#4{% + % define + % \pgfplots@foreach@loc@TMPd = N in fixed point + % \pgfplots@foreach@loc@TMPc = N-1 in float : + \pgfkeysgetvalue{/pgfplots/samples}{\pgfplots@plot@samples} + \pgfmathfloatcreate{1}{1.0}{0}% + \let\pgfplots@foreach@loc@TMPa=\pgfmathresult + \pgfmathfloatparsenumber{\pgfplots@plot@samples}% + \expandafter\pgfmathfloatsubtract@\expandafter{\pgfmathresult}{\pgfplots@foreach@loc@TMPa}% + \let\pgfplots@foreach@loc@TMPc=\pgfmathresult + % + \edef\pgfplots@loc@TMPb{#3}% + \expandafter\pgfplotsforeachlogarithmicungrouped@readdomain\pgfplots@loc@TMPb\relax + % compute mesh width into \pgfplots@foreach@loc@TMPc: + % \pgfplots@foreach@loc@TMPc := h := ( log(xmax) - log(xmin) ) / (N-1) + \pgfmathfloatsubtract@{\pgfplots@foreach@loc@TMPb}{\pgfplots@foreach@loc@TMPa}% + \pgfmathfloatdivide@{\pgfmathresult}{\pgfplots@foreach@loc@TMPc}% + \let\pgfplots@foreach@loc@TMPc=\pgfmathresult + % + % apply local scoping here: + \edef\pgfplots@foreach@loc@TMPd{% + \noexpand\c@pgf@counta=\the\c@pgf@counta\noexpand\relax + }% + \long\def\pgfplots@foreach@loc@TMPf{#4}% + \c@pgf@counta=0 + \pgfutil@loop + \ifnum\c@pgf@counta<\pgfplots@plot@samples + % compute exp(log(min) + i * h) + \expandafter\pgfmathfloatparsenumber\expandafter{\the\c@pgf@counta}% + \expandafter\pgfmathfloatmultiply@\expandafter{\pgfmathresult}{\pgfplots@foreach@loc@TMPc}% + \expandafter\pgfmathfloatadd@\expandafter{\pgfmathresult}{\pgfplots@foreach@loc@TMPa}% + \let\pgfplots@loc@TMPa=\pgfmathresult + \pgfplotsforeachlogarithmicungrouped@finalizeresult% + \let#2=\pgfmathresult + \pgfmathfloatexp@{\pgfplots@loc@TMPa}% + \pgfplotsforeachlogarithmicungrouped@finalizeresult% + \let#1=\pgfmathresult + % + % ok, invoke it! + % -> store \c@pgf@counta before doing so. We need to scope + % manually here. + \edef\pgfplots@foreach@loc@TMPe{\the\c@pgf@counta}% + \pgfplots@foreach@loc@TMPf\relax + \c@pgf@counta=\pgfplots@foreach@loc@TMPe\relax + \advance\c@pgf@counta by 1 + \pgfutil@repeat + % restore scoped variables: + \pgfplots@foreach@loc@TMPd +} +% can be used to convert the number format from float to something +% else. +\def\pgfplotsforeachlogarithmicungrouped@finalizeresult{}% + + +% defines +% \pgfplots@foreach@loc@TMPa := log(firstintervalpt) +% and +% \pgfplots@foreach@loc@TMPb := log(secondintervalpt) +\def\pgfplotsforeachlogarithmicungrouped@readdomain#1:#2\relax{% + \pgfmathfloatparsenumber{#1}% + \pgfmathfloatln@{\pgfmathresult}% + \let\pgfplots@foreach@loc@TMPa=\pgfmathresult + \pgfmathfloatparsenumber{#2}% + \pgfmathfloatln@{\pgfmathresult}% + \let\pgfplots@foreach@loc@TMPb=\pgfmathresult +} + +% invokes '#2' if #1 expands (\edef) to the empty string or '#3' if not. +\def\pgfplots@ifempty#1#2#3{% + \edef\pgfplots@loc@TMPa{#1}% + \ifx\pgfplots@loc@TMPa\pgfutil@empty #2\else #3\fi +}% + +\def\pgfplots@logfileopen#1{% + \immediate\write-1{PGFPlots: reading {#1}}% +}% + +\input pgfplotsliststructure.code.tex +\input pgfplotsliststructureext.code.tex +\input pgfplotsarray.code.tex +\input pgfplotstable.code.tex + +\endinput |