summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/syst-ext.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/syst-ext.tex')
-rw-r--r--Master/texmf-dist/tex/context/base/syst-ext.tex183
1 files changed, 111 insertions, 72 deletions
diff --git a/Master/texmf-dist/tex/context/base/syst-ext.tex b/Master/texmf-dist/tex/context/base/syst-ext.tex
index bee6049bf24..7723d9deb6f 100644
--- a/Master/texmf-dist/tex/context/base/syst-ext.tex
+++ b/Master/texmf-dist/tex/context/base/syst-ext.tex
@@ -141,6 +141,35 @@
% \redefine\hans{hans}
% \define\hans#1[]#2#3{hans}
+%D The next variant fits nicely in the setups syntax:
+%D
+%D \starttyping
+%D \starttexdefinition bagger [#1] #2
+%D oeps
+%D #1
+%D oeps
+%D \stoptexdefinition
+%D
+%D \bagger [a] {b}
+%D \stoptyping
+
+\bgroup \obeylines
+
+\gdef\starttexdefinition%
+ {\bgroup%
+ \obeylines%
+ \dostarttexdefinition}
+
+\gdef\dostarttexdefinition #1 #2
+ {\catcode13=\@@ignore%
+ \dodostarttexdefinition{#1}{#2}}%
+
+\long\gdef\dodostarttexdefinition#1#2#3\stoptexdefinition%
+ {\egroup%
+ \long\setvalue{#1}#2{#3}}
+
+\egroup
+
%D \macros
%D {newcounter,
%D increment,decrement}
@@ -1205,10 +1234,6 @@
\def\convertedcommand
{\expandafter\doconvertargument\meaning}
-%\long\def\convertargument#1\to#2%
-% {\long\def\convertedargument{#1}%
-% \dodoglobal\edef#2{\convertedcommand\convertedargument}}
-
\long\def\convertargument#1\to#2%
{\long\def#2{#1}% saves a restore
\dodoglobal\edef#2{\convertedcommand#2}}
@@ -1216,20 +1241,29 @@
\long\def\convertcommand#1\to#2%
{\dodoglobal\edef#2{\convertedcommand#1}}
+% no dodoglobal !
+
\long\def\defconvertedargument#1#2% less sensitive for \to
{\long\def#1{#2}% saves a restore
- \dodoglobal\edef#1{\convertedcommand#1}}
+ \edef#1{\convertedcommand#1}}
\long\def\defconvertedcommand#1#2% less sensitive for \to
- {\dodoglobal\edef#1{\convertedcommand#2}}
+ {\edef#1{\convertedcommand#2}}
+
+\long\def\gdefconvertedargument#1#2% less sensitive for \to
+ {\long\gdef#1{#2}% saves a restore
+ \xdef#1{\convertedcommand#1}}
+
+\long\def\gdefconvertedcommand#1#2% less sensitive for \to
+ {\xdef#1{\convertedcommand#2}}
\endTEX
\def\convertvalue#1\to
{\expandafter\convertcommand\csname#1\endcsname\to}
-\def\defconvertvalue#1#2% less sensitive for \to
- {\@EA\defconvertcommand\@EA#1\csname#2\endcsname}
+\def\defconvertedvalue#1#2% less sensitive for \to
+ {\@EA\defconvertedcommand\@EA#1\csname#2\endcsname}
%D \macros
%D {doifassignmentelse}
@@ -1287,22 +1321,21 @@
%D something I found out when primitives like \type
%D {\jobname} were fed (or something undefined).
-\beginETEX \detokenize
+% command variant: one level expansion !
-\long\def\convertargument#1\to#2%
- {\dodoglobal\edef#2{\detokenize{#1}}}
-
-% \long\def\convertcommand#1\to#2%
-% {\@EA\dodoglobal\@EA\edef\@EA#2\@EA{\@EA\detokenize\@EA{#1}}}
-
-\long\def\convertcommand#1\to#2%
- {\dodoglobal\edef#2{\@EA\detokenize\@EA{#1}}} % hm, only second is also ok
+\beginETEX \detokenize
-\long\def\defconvertedargument#1#2% less sensitive for \to
- {\dodoglobal\edef#1{\detokenize{#2}}}
+\long\def\convertargument#1\to#2{\dodoglobal\edef#2{\detokenize{#1}}}
+\long\def\convertcommand #1\to#2{\dodoglobal\edef#2{\@EA\detokenize\@EA{#1}}} % hm, only second is also ok
-\long\def\defconvertedcommand#1#2% less sensitive for \to
- {\dodoglobal\edef#1{\detokenize\@EA{#2}}}
+\long\def\defconvertedargument #1#2{\edef#1{\detokenize {#2}}}
+\long\def\defconvertedcommand #1#2{\edef#1{\detokenize\@EA{#2}}}
+\long\def\edefconvertedargument#1#2{\edef#1{#2}%
+ \edef#1{\detokenize\@EA{#1}}}
+\long\def\gdefconvertedargument#1#2{\xdef#1{\detokenize {#2}}}
+\long\def\gdefconvertedcommand #1#2{\xdef#1{\detokenize\@EA{#2}}}
+\long\def\xdefconvertedargument#1#2{\xdef#1{#2}%
+ \xdef#1{\detokenize\@EA{#1}}}
\endETEX
@@ -1324,35 +1357,6 @@
%D The \type{-}, the delimiter \type{\\\\} and the the second
%D argument are completely redundant.
-% %D As said, the \TEX\ alternative fails on expanding primitives,
-% %D like in:
-% %D
-% %D \starttyping
-% %D \convertcommand\someprimitive\to\ascii
-% %D \stoptyping
-% %D
-% %D Because these primitives convert to themselves, we can use
-% %D the backslash as a signal to treat them different. At the
-% %D cost of slightly more overhead we can therefore define a
-% %D more robust alternative. The catcode trickery is needed to
-% %D get the backslash into the test as character (and not as
-% %D escape, letter or whatever code else).
-% %
-% % does not work:
-% %
-% % \beginTEX
-% %
-% % \let\dodoconvertargument\doconvertargument
-% %
-% % \bgroup
-% % \catcode`\*=\@@escape
-% % \catcode`\\=\@@other
-% % *gdef*doconvertargument#1%
-% % {*ifx#1\*else*expandafter*dodoconvertargument*fi#1}
-% % *egroup
-% %
-% % \endTEX
-
%D \macros
%D {showvalue,showargument}
%D
@@ -1373,7 +1377,7 @@
\endETEX
\long\def\showargument#1%
- {\convertargument#1\to\ascii\show\ascii}
+ {\defconvertedargument\ascii{#1}\ascii}
%D \macros
%D {doifmeaningelse}
@@ -1513,8 +1517,8 @@
\beginTEX
\def\ConvertToConstant#1#2#3%
- {\expandafter\convertargument\expandafter{#2}\to\!!stringa
- \expandafter\convertargument\expandafter{#3}\to\!!stringb
+ {\expandafter\defconvertedargument\expandafter\!!stringa\expandafter{#2}%
+ \expandafter\defconvertedargument\expandafter\!!stringb\expandafter{#3}%
#1{\!!stringa}{\!!stringb}}
\endTEX
@@ -3647,16 +3651,25 @@
\beginETEX
+% \def\executeifdefined#1% #2 / never change this one again
+% {\ifcsname#1\endcsname
+% \expandafter\firstoftwoarguments
+% \else
+% \expandafter\secondoftwoarguments
+% \fi
+% {\csname#1\endcsname}}
+
\def\executeifdefined#1% #2 / never change this one again
{\ifcsname#1\endcsname
- \expandafter\firstoftwoarguments
+ \csname#1\expandafter\expandafter\expandafter\endcsname\expandafter\gobbleoneargument
\else
- \expandafter\secondoftwoarguments
- \fi
- {\csname#1\endcsname}}
+ \expandafter\firstofoneargument
+ \fi}
\endETEX
+% \letvalue{f }\firstofoneargument \def\executeifdefined#1{\csname\ifcsname#1\endcsname#1\else f \fi\endcsname}
+
%D This one also has the advantage that it is fully
%D expandable and that it can be used after an assignment.
@@ -3842,19 +3855,45 @@
%D Therefore we smuggle a \type {\relax} in front of the
%D argument, which we remove afterwards.
+% \def\doprocessseparatedlist#1]#2[#3]#4%
+% {\def\dodoprocessseparatedlist##1##2#3%
+% {\if]##1%
+% \let\dodoprocessseparatedlist\relax
+% \else\if]##2%
+% \let\dodoprocessseparatedlist\relax
+% \else\ifx\blankspace##2%
+% #4{##1}%
+% \else
+% #4{##1##2}%
+% \fi\fi\fi
+% \dodoprocessseparatedlist}%
+% \@EA\dodoprocessseparatedlist\gobbleoneargument#1#3]#3}
+
+% testcase Vit Zyka:
+%
+% \def\Do#1{(#1)}
+% 1\processseparatedlist[{aap noot}] [ ]\Do \par
+% 2\processseparatedlist[{aap} {noot}][ ]\Do \par
+% 3\processseparatedlist[aap {noot}] [ ]\Do \par
+% 4\processseparatedlist[aap noot] [ ]\Do \par
+% 5\processseparatedlist[aap;noot;a noot;noot a; noot a noot][;]\Do \par
+% 6\processseparatedlist[][;]\Do \par
+% 7\processseparatedlist[;][;]\Do \par
+
\def\doprocessseparatedlist#1]#2[#3]#4%
- {\def\dodoprocessseparatedlist##1##2#3%
- {\if]##1%
- \let\dodoprocessseparatedlist\relax
- \else\if]##2%
- \let\dodoprocessseparatedlist\relax
- \else\ifx\blankspace##2%
- #4{##1}%
- \else
- #4{##1##2}%
- \fi\fi\fi
- \dodoprocessseparatedlist}%
- \@EA\dodoprocessseparatedlist\gobbleoneargument#1#3]#3}
+ {\def\dodoprocessseparatedlist##1##2#3%
+ {\def\!!stringa{##2}% suggested by VZ
+ \if]##1%
+ \let\dodoprocessseparatedlist\relax
+ \else\ifx\blankspace\!!stringa
+ #4{##1}%
+ \else\if]##2%
+ \let\dodoprocessseparatedlist\relax
+ \else
+ #4{##1##2}%
+ \fi\fi\fi
+ \dodoprocessseparatedlist}%
+ \@EA\dodoprocessseparatedlist\gobbleoneargument#1#3]#3}
\def\processseparatedlist[%
{\doprocessseparatedlist\relax}
@@ -4436,11 +4475,11 @@
\def\dotwodigitrounding#1.#2#3#4\relax{\ifx#2*#1\else#1.#2#3\fi}
\def\integerrounding#1%
- {\@EA\@EA\@EA\dointegerrounding \@EA\WITHOUTPT\the\dimexpr#1\points+32768sp\relax.\relax}
+ {\@EA\@EA\@EA\dointegerrounding \@EA\WITHOUTPT\the\dimexpr#1\points+.5\points\relax.\relax}
\def\onedigitrounding#1%
- {\@EA\@EA\@EA\doonedigitrounding\@EA\WITHOUTPT\the\dimexpr#1\points+32768sp\relax00.*0\relax}
+ {\@EA\@EA\@EA\doonedigitrounding\@EA\WITHOUTPT\the\dimexpr#1\points+.05\points\relax00.*0\relax}
\def\twodigitrounding#1%
- {\@EA\@EA\@EA\dotwodigitrounding\@EA\WITHOUTPT\the\dimexpr#1\points+32768sp\relax000.*00\relax}
+ {\@EA\@EA\@EA\dotwodigitrounding\@EA\WITHOUTPT\the\dimexpr#1\points+.005\points\relax000.*00\relax}
\endETEX