summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/syst-gen.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/syst-gen.tex')
-rw-r--r--Master/texmf-dist/tex/context/base/syst-gen.tex306
1 files changed, 205 insertions, 101 deletions
diff --git a/Master/texmf-dist/tex/context/base/syst-gen.tex b/Master/texmf-dist/tex/context/base/syst-gen.tex
index 25e5390afd1..71e156b629b 100644
--- a/Master/texmf-dist/tex/context/base/syst-gen.tex
+++ b/Master/texmf-dist/tex/context/base/syst-gen.tex
@@ -13,6 +13,7 @@
% nagaan : \ifinstringelse in syst-ext.tex
% do => p! dodo pp! dododo ppp!
+% todo: \donetrue etc local maken
%D The following macros are responsible for the interaction
%D with \CONTEXT. These macros have proven their use. These
@@ -345,6 +346,7 @@
\dimendef\!!dimenh=14 %skipdef\!!skipc=4
\dimendef\!!dimeni=16 %skipdef\!!skipd=6
\dimendef\!!dimenj=18 %skipdef\!!skipe=8
+ \dimendef\!!dimenk=20 %skipdef\!!skipf=10
\let\!!stringa=\empty \let\!!stringb=\empty \let\!!stringc=\empty
\let\!!stringd=\empty \let\!!stringe=\empty \let\!!stringf=\empty
@@ -403,7 +405,9 @@
%D \type{\unprotect}, one can use \type{\@EA} as equivalent
%D of \type{\expandafter}.
-\let\@EA =\expandafter
+\let\@NX\noexpand
+\let\@EA\expandafter
+
\def\@EAEA {\expandafter\expandafter}
\def\@EAEAEA{\expandafter\expandafter\expandafter}
@@ -441,7 +445,7 @@
\newtoks\everysafeexpanded
-\long\def\safeexpanded#1%
+\long\def\safeexpanded#1% why the \noexpand
{\begingroup
\the\everysafeexpanded\long\xdef\@@expanded{\noexpand#1}%
\endgroup
@@ -2243,7 +2247,7 @@
{\let\expandedaction\noexpandedaction}
%D \macros
-%D {getfirstcharacter,firstcharacter, doiffirstcharacter}
+%D {getfirstcharacter, firstcharacter, remainingcharacters, doiffirstcharacter}
%D
%D Sometimes the action to be undertaken depends on the
%D next character. This macro get this character and puts it in
@@ -2257,12 +2261,13 @@
%D complicated arguments, for instance arguments that
%D consist of two or more expandable tokens.
-\def\dogetfirstcharacter#1#2\\%
- {\def\firstcharacter{#1}}
+\def\dogetfirstcharacter#1#2\relax
+ {\def\firstcharacter{#1}%
+ \def\remainingcharacters{#2}}
\def\getfirstcharacter#1%
{\edef\!!stringa{#1}%
- \expandafter\dogetfirstcharacter\!!stringa\\}
+ \expandafter\dogetfirstcharacter\!!stringa\relax}
\def\doiffirstcharelse#1#2% char string
% kort (maar onleesbaar)
@@ -2537,7 +2542,7 @@
%D Even more important is that this alternative is fully
%D expandable!
-\long\def\doifnumberelse#1%
+\long\def\doifnumberelse#1% does not accept counters
{\ifcase0\ifcase1#1\or\or\or\or\or\or\or\or\or\else1\fi\space
\expandafter\secondoftwoarguments
\else
@@ -3001,6 +3006,112 @@
\def\doeassign [#1][#2]{\p!doassign\dosetevalue #1\@relax@#2==\empty\@relax@}
\def\undoassign[#1][#2]{\p!doassign\doresetvalue#1\@relax@#2==\empty\@relax@}
+%D When someone asked on the mailing list if it's possible to
+%D use the current value of a parameter, Taco posted a small module. His
+%D method had the disadvantage of making all assignments expanded and thereby
+%D fragile. The following alternative uses a prefix.
+
+%D \macros{currentvalue}
+%D
+%D Just in case a \type{\getparameter} argument itself ends up
+%D inside a \type{\write} or other expandable location, our
+%D new macro needs a default value.
+
+\let\currentvalue\empty
+
+\def\p!n!doassign#1#2\@relax@#3=#4=#5#6\@relax@% normal
+ {\ifx#5\empty
+ \@EA\xshowassignerror
+ \else\ifx#5=%
+ \@EAEAEA#1%
+ \else
+ \@EAEAEA\xshowassignerror
+ \fi\fi
+ {#2}{#3}{#4}}
+
+\beginTEX
+
+\def\p!e!doassign#1#2\@relax@#3=#4=#5#6\@relax@
+ {\ifx#5\empty
+ \@EA\xshowassignerror
+ \else\ifx#5=%
+ \@EA\ifx\csname#2#3\endcsname\relax
+ \let\currentvalue\empty
+ \else
+ \@EA\let\@EA\currentvalue\csname#2#3\endcsname
+ \fi
+ \@EAEAEA#1%
+ \else
+ \@EAEAEA\xshowassignerror
+ \fi\fi
+ {#2}{#3}{#4}}
+
+\endTEX
+
+\beginETEX
+
+\def\p!e!doassign#1#2\@relax@#3=#4=#5#6\@relax@
+ {\ifx#5\empty
+ \@EA\xshowassignerror
+ \else\ifx#5=%
+ \ifcsname#2#3\endcsname
+ \@EA\let\@EA\currentvalue\csname#2#3\endcsname
+ \else
+ \let\currentvalue\empty
+ \fi
+ \@EAEAEA#1%
+ \else
+ \@EAEAEA\xshowassignerror
+ \fi\fi
+ {#2}{#3}{#4}}
+
+\endETEX
+
+%D We default to:
+
+\let\p!doassign\p!n!doassign
+
+%D And set:
+
+\let\currentvalue\empty
+
+%D \macros {expandparameters}
+%D
+%D Example usage:
+%D
+%D \startbuffer
+%D \getparameters[taco][name=taco]
+%D \convertcommand\taconame\to\ascii \ascii
+%D \expandparameters \getparameters[taco][name=\currentvalue\space hoekwater]
+%D \convertcommand\taconame\to\ascii \ascii
+%D \getparameters[taco][name=\currentvalue\space hoekwater]
+%D \convertcommand\taconame\to\ascii \ascii
+%D \stopbuffer
+%D
+%D \typebuffer
+%D \startlines
+%D \getbuffer
+%D \stoplines
+
+%D Here we hook in the code (beware, this is the optimized get **):
+
+\def\xdoget@n@parameters#1]%
+ {\xprocesscommaitem#1,],\@relax@}
+
+\def\xdoget@e@parameters#1]%
+ {\let\dosetnvalue\dosetvalue
+ \let\dosetvalue\dosetevalue
+ \let\p!doassign\p!e!doassign
+ \xprocesscommaitem#1,],\@relax@
+ \let\p!doassign\p!n!doassign
+ \let\dosetvalue\dosetnvalue
+ \let\xdogetparameters\xdoget@n@parameters
+ \let\currentvalue\empty}
+
+\let\xdogetparameters\xdoget@n@parameters % **
+
+\def\expandparameters{\let\xdogetparameters\xdoget@e@parameters}
+
%D \macros
%D {getemptyparameters}
%D
@@ -3145,9 +3256,9 @@
\def\p!dogetcommalistsize#1%
{\advance\commalistcounter\plusone}
-\def\getcommalistsize[#1]%
+\def\getcommalistsize#1]% don't loose [{#1}]
{\commalistcounter\zerocount
- \processcommalist[#1]\p!dogetcommalistsize % was [{#1}]
+ \processcommalist#1]\p!dogetcommalistsize % was [{#1}]
\edef\commalistsize{\the\commalistcounter}}
\def\getcommacommandsize[#1]%
@@ -3694,40 +3805,31 @@
%D Now a whole bunch of variables like \type{\@@xxalfavariable}
%D and \type{\@@xxbetavariable} is defined.
-\def\dosingleargumentwithset#1%
- {\def\dodosinglewithset[##1]%
- {\def\dododosinglewithset####1%
- {#1[####1]}%
- \processcommalist[##1]\dododosinglewithset}%
- \dosingleargument\dodosinglewithset}%
+% \def\dosingleargumentwithset#1%
+% {\def\dodosinglewithset[##1]%
+% {\def\dododosinglewithset####1{#1[####1]}%
+% \processcommalist[##1]\dododosinglewithset}%
+% \dosingleargument\dodosinglewithset}%
\def\dodoublewithset#1#2%
{\def\dododoublewithset[##1][##2]%
- {\doifnot{##1}{}
- {\def\dodododoublewithset####1%
- {#2[####1][##2]}%
+ {\doifsomething{##1}
+ {\def\dodododoublewithset####1{#2[####1][##2]}%
\processcommalist[##1]\dodododoublewithset}}%
- #1\dododoublewithset}%
-
-\def\dodoubleemptywithset%
- {\dodoublewithset\dodoubleempty}
+ #1\dododoublewithset}
-\def\dodoubleargumentwithset%
- {\dodoublewithset\dodoubleargument}
+\def\dodoubleemptywithset {\dodoublewithset\dodoubleempty}
+\def\dodoubleargumentwithset{\dodoublewithset\dodoubleargument}
\def\dotriplewithset#1#2%
{\def\dodotriplewithset[##1][##2][##3]%
- {\doifnot{##1}{}
- {\def\dododotriplewithset####1%
- {#2[####1][##2][##3]}%
+ {\doifsomething{##1}
+ {\def\dododotriplewithset####1{#2[####1][##2][##3]}%
\processcommalist[##1]\dododotriplewithset}}%
- #1\dodotriplewithset}%
+ #1\dodotriplewithset}
-\def\dotripleemptywithset%
- {\dotriplewithset\dotripleempty}
-
-\def\dotripleargumentwithset%
- {\dotriplewithset\dotripleargument}
+\def\dotripleemptywithset {\dotriplewithset\dotripleempty}
+\def\dotripleargumentwithset{\dotriplewithset\dotripleargument}
%D \macros
%D {strippedcsname}
@@ -4003,76 +4105,74 @@
%D \type {\if} and friends, in practice we will use a
%D slightly more complicated macro.
-\let\normalif \if
-\let\normalifx \ifx
-\let\normalifnum \ifnum
-\let\normalifdim \ifdim
-\let\normalifcat \ifcat
-\let\normalifcase \ifcase
-\let\normalifcsname \ifcsname
-\let\normalifhmode \ifhmode
-\let\normalifvmode \ifvmode
-\let\normalor \or
-\let\normalelse \else
-\let\normalfi \fi
+\let\normalif \if
+\let\normalifcat \ifcat
+\let\normalifnum \ifnum
+\let\normalifdim \ifdim
+\let\normalifodd \ifodd
+\let\normalifvmode \ifvmode
+\let\normalifhmode \ifhmode
+\let\normalifmmode \ifmmode
+\let\normalifinner \ifinner
+\let\normalifvoid \ifvoid
+\let\normalifhbox \ifhbox
+\let\normalifvbox \ifvbox
+\let\normalifx \ifx
+\let\normalifeof \ifeof
+\let\normaliftrue \iftrue
+\let\normaliffalse \iffalse
+\let\normalifcase \ifcase
+\let\normalifdefined \ifdefined
+\let\normalifcsname \ifcsname
+\let\normaliffontchar \iffontchar
+\let\normalifincsname \ifincsname
+\let\normalifprimitive\ifprimitive
+\let\normalifabsnum \ifabsnum
+\let\normalifabsdim \ifabsdim
+
+\let\normalelse \else
+\let\normalor \or
+\let\normalfi \fi
+
+\newtoks \everyrobusttest
+
+\everyrobusttest
+ {\let\if \relax
+ \let\ifcat \relax
+ \let\ifnum \relax
+ \let\ifdim \relax
+ \let\ifodd \relax
+ \let\ifvmode \relax
+ \let\ifhmode \relax
+ \let\ifmmode \relax
+ \let\ifinner \relax
+ \let\ifvoid \relax
+ \let\ifhbox \relax
+ \let\ifvbox \relax
+ \let\ifx \relax
+ \let\ifeof \relax
+ \let\iftrue \relax
+ \let\iffalse \relax
+ \let\ifcase \relax
+ \let\ifdefined \relax
+ \let\ifcsname \relax
+ \let\iffontchar \relax
+ \let\ifincsname \relax
+ \let\ifprimitive\relax
+ \let\ifabsnum \relax
+ \let\ifabsdim \relax
+ \let\else \relax
+ \let\or \relax
+ \let\fi \relax}
\def\beginrobusttest
{\begingroup
- \let\if \relax
- \let\ifx \relax
- \let\ifnum \relax
- \let\ifdim \relax
- \let\ifcat \relax
- \let\ifcase \relax
- \let\ifcsname\relax
- \let\or \relax
- \let\else \relax
- \let\fi \relax}
+ \the\everyrobusttest}
\let\endrobusttest\endgroup
-% \def\dogetgroupargument#1#2%
-% {\def\nextnextargument%
-% {\normalifx\nextargument\bgroup
-% \endrobusttest
-% \let\expectedarguments\noexpectedarguments
-% \def\nextargument{#1\dodogetargument}%
-% %\normalelse\normalifx\nextargument\lineending % this can be an option
-% % \def\nextargument{\begingroup\def\\ {\endgroup\dogetgroupargument#1#2}\\}%
-% %\normalelse\normalifx\nextargument\blankspace % but may never be default
-% % \def\nextargument{\begingroup\def\\ {\endgroup\dogetgroupargument#1#2}\\}%
-% \normalelse
-% \endrobusttest
-% \ifnum\expectedarguments>\noexpectedarguments
-% \showargumenterror{\number\expectedarguments}{\number\inputlineno}%
-% \fi
-% \let\expectedarguments\noexpectedarguments
-% \def\nextargument{#2\dodogetargument{}}%
-% \normalfi%\normalfi\normalfi % so let's get rid of it
-% \nextargument}%
-% \beginrobusttest
-% \futurelet\nextargument\nextnextargument}
-
-% \def\dogetgroupargument#1#2%
-% {\def\nextnextargument%
-% {\normalifx\nextargument\bgroup
-% \endrobusttest
-% \noshowargumenterror
-% \def\nextargument{#1\dodogetargument}%
-% %\normalelse\normalifx\nextargument\lineending % this can be an option
-% % \def\nextargument{\begingroup\def\\ {\endgroup\dogetgroupargument#1#2}\\}%
-% %\normalelse\normalifx\nextargument\blankspace % but may never be default
-% % \def\nextargument{\begingroup\def\\ {\endgroup\dogetgroupargument#1#2}\\}%
-% \normalelse
-% \endrobusttest
-% \doshowargumenterror
-% \def\nextargument{#2\dodogetargument{}}%
-% \normalfi%\normalfi\normalfi % so let's get rid of it
-% \nextargument}%
-% \beginrobusttest
-% \futurelet\nextargument\nextnextargument}
-
-% we need to use an \ifcase in order to honor the \normal...
+%D We can add additional definitions later when we have defined
+%D \type {\appendtoks}.
\def \permitspacesbetweengroups{\chardef\@@permitspacesbetweengroups=0 }
\def\dontpermitspacesbetweengroups{\chardef\@@permitspacesbetweengroups=1 }
@@ -4279,11 +4379,16 @@
\chardef\statuswidth=15
\chardef\statuswrite=16
-\def\writestring
- {\immediate\write\statuswrite}
+\newtoks\everywritestring
+
+\def\writestring#1%
+ {\begingroup
+ \the\everywritestring
+ \immediate\write\statuswrite{#1}%
+ \endgroup}
\def\writeline
- {\writestring{}}
+ {\immediate\write\statuswrite{}}
%D First we present the normal \TEX\ variant, later we will
%D show the \ETEX-way.
@@ -4312,7 +4417,6 @@
\space\space\space\space\space\space\space
\space\space\space\space\space\space\space
\space\space\space\space\space\space\end
- %\expanded{\writestring{\the\scratchtoks\space:\space#2}}%
\@EA\writestring\@EA{\the\scratchtoks\space:\space#2}%
\endgroup}