summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/yquant/yquant-tools.tex')
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-tools.tex100
1 files changed, 100 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex b/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex
index 5f7efe5e037..4b31a4e35ed 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-tools.tex
@@ -30,6 +30,11 @@
\long\def\@thirdoffour#1#2#3#4{#3}%
\long\def\@fourthoffour#1#2#3#4{#4}%
\long\def\@thirdandfourthoffour#1#2#3#4{#3#4}%
+\long\def\@secondandthirdoffive#1#2#3#4#5{{#2}{#3}}
+\long\def\@firstoffive#1#2#3#4#5{#1} % unused
+\long\def\@secondoffive#1#2#3#4#5{#2}
+\long\def\@thirdoffive#1#2#3#4#5{#3}
+\long\def\@fourthoffive#1#2#3#4#5{#4} % unused
\long\def\@fifthoffive#1#2#3#4#5{#5}
% Loop #1 from min(#2, #3) to max(#2, #3), executing #4
@@ -184,6 +189,30 @@
\expandafter\yquant@sort@aux\expandafter0\expandafter{\the\numexpr\yquant@sort@count-1\relax}%
}
+% Returns the first item in the unordered sortlist when compared according to #1 and stores it in #2.
+\protected\def\yquant@sort@findfirst#1#2{%
+ \ifnum\yquant@sort@count<1 %
+ \let#2=\empty%
+ \else%
+ \letcs#2{yquant@sort@item0}%
+ \count0=1 %
+ \loop%
+ \ifnum\count0<\yquant@sort@count\relax%
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter#1%
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{%
+ \expandafter\expandafter\expandafter#2%
+ \expandafter\expandafter\expandafter}%
+ \expandafter\expandafter\expandafter{%
+ \csname yquant@sort@item\the\count0\endcsname%
+ }%
+ \relax{%
+ \letcs#2{yquant@sort@item\the\count0}%
+ }%
+ \advance\count0 by 1 %
+ \repeat%
+ \fi%
+}
+
\def\yquant@sort@ascending#1#2{%
\ifnum#2>#1 %
\expandafter\@firstoftwo%
@@ -316,6 +345,7 @@
\begingroup
\catcode`\|=3
+\catcode`\&=3
\gdef\yquant@list@delim{|}
\protected\gdef\yquant@list@dequeue#1#2{%
@@ -338,8 +368,78 @@
\expandafter\yquant@list@dequeue@i#1\etb@lst@q@end{#1}{#2}\gdef%
}%
}
+
+\protected\gdef\yquant@list@eupdateorinsert#1#2#3{%
+ % the list items are of the form <number>:<value>. If an item is present where <number> = #2, then set its <value> to #3, if #3 is greater. If no item is present, add it.
+ \begingroup%
+ \def\etb@tempa##1|#2:##2|##3&{%
+ \endgroup%
+ \ifstrempty{##3}{%
+ \eappto#1{#2:#3|}%
+ }{%
+ \ifdim##2<#3 %
+ \yquant@list@ereplace#1{#2:##2}{#2:#3}%
+ \fi%
+ }%
+ }%
+ \expandafter\etb@tempa\expandafter|#1|#2:#3|&%
+}
+
+\protected\gdef\yquant@list@ereplace#1#2#3{%
+ \begingroup%
+ \def\etb@tempa##1|#2|##2&{%
+ \endgroup%
+ \ifstrempty{##1}{%
+ \edef#1{%
+ \unexpanded{##1}|#3|\unexpanded{##2}%
+ }%
+ }{%
+ \edef#1{%
+ \unexpanded\expandafter{\@gobble##1}|#3|\unexpanded{##2}%
+ }%
+ }%
+ }%
+ \expandafter\etb@tempa\expandafter|#1&
+}
+
+% expands to the contents of a list ranging from #1 to #2 (ascending)
+\gdef\yquant@list@range#1#2{%
+ \ifnum#1>#2 %
+ \expandafter\@firstoftwo%
+ \else%
+ \expandafter\@secondoftwo%
+ \fi{}{%
+ #1|%
+ \expandafter\yquant@list@range\expandafter{\the\numexpr#1+1\relax}{#2}%
+ }%
+}
\endgroup
+% performs #3 if #1 is a subset of #2; else, performs #4
+\protected\def\ifyquant@registersubset#1#2{%
+ \begingroup%
+ \let\yquant@register@multi=\@fourthoffour
+ \def\yquant@register@multi@contiguous##1##2##3{\yquant@list@range{##1}{##2}}%
+ \edef\listA{#1}%
+ \edef\listB{#2}%
+ \let\ifsuccess=\iftrue%
+ \forlistloop\yquant@registersubset@loop\listA%
+ \expandafter%
+ \endgroup%
+ \ifsuccess%
+ \expandafter\@firstoftwo%
+ \else%
+ \expandafter\@secondoftwo%
+ \fi%
+}
+
+\protected\def\yquant@registersubset@loop#1{%
+ \ifinlist{#1}\listB\relax{%
+ \let\ifsuccess=\iffalse%
+ \listbreak%
+ }%
+}
+
\def\ifyquant@OR#1#2{%
#1%
\expandafter\@firstoftwo%