diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex')
-rw-r--r-- | Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex | 114 |
1 files changed, 88 insertions, 26 deletions
diff --git a/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex b/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex index aa21ad13dc4..87ce40e586b 100644 --- a/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex +++ b/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex @@ -19,6 +19,7 @@ % \pgfplotslistpushfront % \pgfplotslistsize % \pgfplotslistselect +% \pgfplotslistset % \pgfplotslistcheckempty % \pgfplotslistforeach % @@ -47,6 +48,9 @@ \newif\ifpgfplotslistempty +% Low-level IMPLEMENTATION NOTE +% the list is stored in the form +% '\pgfpl@@{<first>}\pgfpl@@{<second>}\pgfpl@@{<third>}....\pgfpl@@{<last>}' \newif\ifpgfplots@loop@CONTINUE \newif\ifpgfplotslist@is@backslash@terminated @@ -74,6 +78,14 @@ % Use braces '{}' to use '\\' or ',' as arguments. % \long\def\pgfplotslistnew#1#2{% + \pgfplots@check@backwards@compatible@list@format #2\\\pgfplots@EOI + \ifpgfplots@is@old@list@format + \pgfplotslistnew@backslash{#1}{#2}% + \else + \pgfplots@foreach@to@list{#2}\to#1% + \fi +} +\long\def\pgfplotslistnew@backslash#1#2{% \pgfplotslistnewempty{#1}% \long\def\pgfplotslistnew@impl@rest{#2}% \pgfplotslist@check@backslash@list #2\\\pgfplotslist@EOI @@ -94,10 +106,10 @@ \expandafter\pgfplotslistnew@impl@comma\pgfplotslistnew@impl@rest\tolist#1\relax \fi \pgfutil@repeat -} +}% \def\pgfplotslist@EOI{\pgfplotslist@EOI} -\def\pgfplotslist@check@backslash@list#1\\#2\pgfplotslist@EOI{% +\long\def\pgfplotslist@check@backslash@list#1\\#2\pgfplotslist@EOI{% \def\pgfplotslist@loc@TMPa{#2}% \ifx\pgfplotslist@loc@TMPa\pgfutil@empty \pgfplotslist@is@backslash@terminatedfalse @@ -130,10 +142,15 @@ \t@pgfplots@tokb=\expandafter{#2}% \edef#2{\the\t@pgfplots@toka\the\t@pgfplots@tokb}% } +\long\def\pgfplotslistpushfrontglobal#1\to#2{% + \t@pgfplots@toka={\pgfpl@@{#1}}% + \t@pgfplots@tokb=\expandafter{#2}% + \xdef#2{\the\t@pgfplots@toka\the\t@pgfplots@tokb}% +} % Assembles a low-level list item representation into the token % register #2. -\def\pgfplotslist@assembleentry#1\into#2{% +\long\def\pgfplotslist@assembleentry#1\into#2{% #2={\pgfpl@@{#1}}% } @@ -176,8 +193,7 @@ \long\def\pgfplotslistpopfront#1\to#2{% \pgfplotslistcheckempty#1\relax \ifpgfplotslistempty - \pgfplots@error{ERROR: \string\pgfplotslistpopfront\ from \string#1\ although list is EMPTY}% - \let#2=\pgfutil@empty + \pgfplotsthrow{no such element}{#1}{\string\pgfplotslistpopfront\ from \string#1\ although list is EMPTY}\pgfeov% \else \expandafter\pgfplotslistpopfront@impl#1\pgfplotslistpopfront@macronames#1#2% \fi @@ -185,8 +201,7 @@ \long\def\pgfplotslistfront#1\to#2{% \pgfplotslistcheckempty#1\relax \ifpgfplotslistempty - \pgfplots@error{ERROR: \string\pgfplotslistfront\ from \string#1\ although list is EMPTY}% - \let#2=\pgfutil@empty + \pgfplotsthrow{no such element}{#2}{\string\pgfplotslistfront\ from \string#1\ although list is EMPTY}\pgfeov% \else \expandafter\pgfplotslistfront@impl#1\pgfplotslistpopfront@macronames#2% \fi @@ -224,11 +239,11 @@ % \elem % Element \count1: % \pgfplotslistselect\count1\of\foo\to\elem -\def\pgfplotslistselect#1\of#2\to#3{% - \global\def\pgfplotslistselect@tmp{\def#3{}\pgfplots@error{The requested list entry with index #1 of \string#2 is too large; this list has not enough elements.}}% +\long\def\pgfplotslistselect#1\of#2\to#3{% + \global\def\pgfplotslistselect@tmp{\pgfplotsthrow{no such element}{#3}{The requested list entry with index #1 of \string#2 is too large; this list has not enough elements.}\pgfeov}% \pgfplotslistselect@{#1}\of{#2}\to{#3}% } -\def\pgfplotslistselect@#1\of#2\to#3{% +\long\def\pgfplotslistselect@#1\of#2\to#3{% \begingroup \count0=#1\relax \long\def\pgfpl@@##1{% @@ -241,11 +256,73 @@ \endgroup \pgfplotslistselect@tmp } -\def\pgfplotslistselectorempty#1\of#2\to#3{% + +% Selects a list entry. If it does not exist, '#' will be empty. +\long\def\pgfplotslistselectorempty#1\of#2\to#3{% \global\def\pgfplotslistselect@tmp{\def#3{}}% \pgfplotslistselect@{#1}\of{#2}\to{#3}% } +% Changes the element at index '#1' of list '#2' to the content '#3'. +% +% This operation has quadratic (!) time in the worst case. +\long\def\pgfplotslistset#1\of#2\to#3{% + \ifcase#1\relax + % change first: + \def\pgfplotslistset@\pgfpl@@##1##2\relax{\def#2{\pgfpl@@{#3}##2}}% + \expandafter\pgfplotslistset@#2\relax + \or + % change second: + \def\pgfplotslistset@\pgfpl@@##1\pgfpl@@##2##3\relax{\def#2{\pgfpl@@{##1}\pgfpl@@{#3}##2}}% + \expandafter\pgfplotslistset@#2\relax + \or + \def\pgfplotslistset@\pgfpl@@##1\pgfpl@@##2\pgfpl@@##3##4\relax{\def#2{\pgfpl@@{##1}\pgfpl@@{##2}\pgfpl@@{#3}##3}}% + \expandafter\pgfplotslistset@#2\relax + \or + \def\pgfplotslistset@\pgfpl@@##1\pgfpl@@##2\pgfpl@@##3\pgfpl@@##4##5\relax{\def#2{\pgfpl@@{##1}\pgfpl@@{##2}\pgfpl@@{##3}\pgfpl@@{#3}##4}}% + \expandafter\pgfplotslistset@#2\relax + \else + \begingroup + \global\pgfplotslistnewempty\pgfplotslistnewempty\pgfplotslist@glob@TMPa + \let\pgfpl@@=\pgfutil@empty % make sure it is not \relax. + \count0=#1\relax + \count1=0 + \def\pgfplotslistset@newelem{#3}% + \expandafter\pgfplotslistset@loop#2\relax + \ifnum\count1 =\count0 + \else + \pgfplotsthrow{no such element}{\pgfplots@loc@TMPa}{\string\pgfplotslistset{\the\count0} failed because there are only \the\count1\space elements in the list. Use pushback to resize it.}\pgfeov% + \global\let\pgfplotslist@glob@TMPa=\pgfplots@loc@TMPa + \fi + \endgroup + \let#3=\pgfplotslist@glob@TMPa + \global\let\pgfplotslist@glob@TMPa=\relax + \fi +}% + +\def\pgfplotslistset@loop{% + \pgfutil@ifnextchar\relax{% + \pgfplotslistset@loop@break + }{% + \pgfplotslistset@loop@next + }% +} +\def\pgfplotslistset@loop@break#1\relax{% + % re-append remaining elements: + \expandafter\gdef\expandafter\pgfplotslist@glob@TMPa\expandafter{\pgfplotslist@glob@TMPa#1} +}% +\def\pgfplotslistset@loop@next\pgfpl@@#1{% + \ifnum\count1 =\count0 + % Ah - we found the element to replace! + \expandafter\pgfplotslistpushbackglobal\expandafter{\pgfplotslistset@newelem}\to\pgfplotslist@glob@TMPa + \expandafter\pgfplotslistset@loop@break + \else + \pgfplotslistpushbackglobal{#1}\to\pgfplotslist@glob@TMPa + \advance\count1 by1 + \expandafter\pgfplotslistset@loop + \fi +}% + % Sets the boolean \ifpgfplotslistempty depending on whether list #1 is empty % or not. % Example: @@ -287,8 +364,6 @@ \endgroup } -\newif\ifpgfplotslistforeachungroupedrunning - % The same but without groups around #3. % % The list can be nested. @@ -329,16 +404,3 @@ }% \def\pgfplotslistforeachungrouped@EOI{\pgfplotslistforeachungrouped@EOI}% equals only itself in \ifx -%-------------------------------------------------- -% \long\def\pgfplotslistforeachungrouped#1\as#2#3{% -% \ifpgfplotslistforeachungroupedrunning -% \pgfplots@error{Sorry, you can't nest pgfplotslistforeachungrouped.}% -% \else -% \pgfplotslistforeachungroupedrunningtrue -% \long\def\pgfpl@@##1{\def#2{##1}#3}% -% #1\relax -% \pgfplotslistforeachungroupedrunningfalse -% \fi -% } -%-------------------------------------------------- - |