summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/pgfplots/liststructure.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/pgfplots/liststructure.sty')
-rw-r--r--Master/texmf-dist/tex/latex/pgfplots/liststructure.sty196
1 files changed, 196 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/pgfplots/liststructure.sty b/Master/texmf-dist/tex/latex/pgfplots/liststructure.sty
new file mode 100644
index 00000000000..8a0a9568449
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/pgfplots/liststructure.sty
@@ -0,0 +1,196 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% This is a helper package with an elementary list datastructure.
+%
+% Its implementation is based on Knuth's list macros in "The TeXbook".
+%
+% The following macros are supplied:
+%
+% \listnewempty
+% \listnew
+% \listcopy
+% \listpopfront
+% \listpushback
+% \listpushfront
+% \listsize
+% \listselect
+% \listcheckempty
+% \listforeach
+%
+% Copyright 2007/2008 by Christian Feuersänger.
+%
+% This program is free software: you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation, either version 3 of the License, or
+% (at your option) any later version.
+%
+% This program is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with this program. If not, see <http://www.gnu.org/licenses/>.
+%
+%
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\ProvidesPackage{liststructure}[2008/26/01 Version 0.9]
+
+\newtoks\TOKL@ta
+\newtoks\TOKL@tb
+\newif\iflistempty
+
+% Creates a new, empty list.
+\long\def\listnewempty#1{\let#1=\empty}
+
+% Creates a new list with an abirtrary number of elements.
+% Arguments:
+% #1: the list's name (a macro name)
+% #2: the elements in the form
+% first\\second\\third\\ ...\\
+% like in tabular with one column.
+%
+% Example:
+% \listnew\foolist{First Element\\Second Element\\Third Element\\}
+%
+% WARNING: do NOT forget the final '\\'!
+\long\def\listnew#1#2{%
+ \listnewempty{#1}%
+ \long\def\listnew@impl@rest{#2}%
+ \loop
+ \ifx\listnew@impl@rest\empty
+ \else
+ \expandafter\listnew@impl\listnew@impl@rest\tolist#1\relax
+ \repeat
+}
+
+% Copies list #1 to list #2.
+\def\listcopy#1\to#2{\let#2=#1}
+
+
+% helper macro for \listnew
+\long\def\listnew@impl#1\\#2\tolist#3{%
+ \listpushback#1\to#3\relax%
+ \def\listnew@impl@rest{#2}%
+}
+
+
+% #1: the item to prepend
+% #2: the list as macro name
+% Example:
+% \listpushfront Next first Element\to\foolist
+\long\def\listpushfront#1\to#2{%
+ \TOKL@ta={\list@sep{#1}}%
+ \TOKL@tb=\expandafter{#2}%
+ \edef#2{\the\TOKL@ta\the\TOKL@tb}%
+}
+
+% #1: the item to append
+% #2: the list as macro name
+% Example:
+% \listpushback Next last element\to\foolist
+\long\def\listpushback#1\to#2{%
+ \TOKL@ta={\list@sep{#1}}%
+ \TOKL@tb=\expandafter{#2}%
+ \edef#2{\the\TOKL@tb\the\TOKL@ta}%
+}
+
+% Concatenates two lists #2 and #3 into #1
+% Example:
+% \listconcat\result=\foolist&\bar
+\long\def\listconcat#1=#2&#3{%
+ \TOKL@ta=\expandafter{#2}%
+ \TOKL@tb=\expandafter{#3}%
+ \edef#1{\the\TOKL@ta\the\TOKL@tb}%
+}
+
+% implements #2 := pop_front(#1)
+% Example:
+% \listpopfront\foolist\to\poppedfirstelem
+\long\def\listpopfront#1\to#2{%
+ \listcheckempty#1\relax
+ \iflistempty
+ \errmessage{ERROR: \string\listpopfront\ from \string#1\ although list is EMPTY}%
+ \else
+ \expandafter\listpopfront@impl#1\listpopfront@macronames#1#2%
+ \fi
+}
+
+% implementation helper for listpopfront
+\long\def\listpopfront@impl\list@sep#1#2\listpopfront@macronames#3#4{%
+ \def#4{#1}%
+ \def#3{#2}%
+}
+
+% Counts the number of elements in list #1, storing it into the count
+% register #2.
+% Example:
+% \listsize\foo\to{\count0}%
+% \the\count0
+\long\def\listsize#1\to#2{%
+ #2=0%
+ \long\def\list@sep##1{\advance#2 by 1 }%
+ #1%
+}
+
+% Returns the #1th element of list #2 into macro #3
+% Arguments:
+% #1: a count 0,...,N-1 where N is the list size.
+% You may specify a number of a count.
+% #2: a list
+% #3: a macro name
+% Example:
+% Element 0:
+% \listselect0\of\foo\to\elem
+% \elem
+% Element \count1:
+% \listselect\count1\of\foo\to\elem
+\long\def\listselect#1\of#2\to#3{%
+ \def#3{\errmessage{The requested item #1 of \string#2 is OUT OF RANGE.}}%
+ \begingroup
+ \count0=#1\relax
+ \long\def\list@sep##1{%
+ \advance\count0-1
+ \ifnum\count0=-1
+ \global\def\listselect@tmp{\def#3{##1}}%
+ % the command \listselect@tmp will be expander AFTER
+ % '\endgroup'
+ \aftergroup\listselect@tmp%
+ \fi%
+ }%
+ #2%
+ \endgroup
+}
+
+% Sets the boolean \iflistempty depending on whether list #1 is empty
+% or not.
+% Example:
+%
+% \listcheckempty\foolist
+% \iflistempty
+% List foolist is empty!
+% \else
+% List is not empty.
+% \fi
+\def\listcheckempty#1{%
+ \ifx#1\empty
+ \listemptytrue
+ \else
+ \listemptyfalse
+ \fi
+}
+
+
+% Iterates through each list element, names it #2 and calls code #3.
+% Example:
+% \listnew\foolist{Eins\\Zwei\\Drei\\}%
+% \listforeach\foolist\as\foo{Element \foo\par}%
+% results in
+% Element Eins
+% Element Zwei
+% Element Drei
+\long\def\listforeach#1\as#2#3{{%
+ \long\def\list@sep##1{\def#2{##1}#3}%
+ #1\relax
+}}