summaryrefslogtreecommitdiff
path: root/tex/context/base/syst-aux.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/syst-aux.mkiv')
-rw-r--r--tex/context/base/syst-aux.mkiv510
1 files changed, 359 insertions, 151 deletions
diff --git a/tex/context/base/syst-aux.mkiv b/tex/context/base/syst-aux.mkiv
index c7be461a3..bd9b1630e 100644
--- a/tex/context/base/syst-aux.mkiv
+++ b/tex/context/base/syst-aux.mkiv
@@ -11,13 +11,17 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-%D There are some references to \LUA\ variants here but these concern
-%D (often old) experiments, moved from local test modules to here,
-%D cleaned up, but not really used. After all it's not that urgent
-%D and replacing helpers is a delicate process. Don't depend on it.
+%D There are some references to \LUA\ variants here but these concern (often old)
+%D experiments, moved from local test modules to here, cleaned up, but not really
+%D used. After all it's not that urgent and replacing helpers is a delicate process.
+%D Don't depend on it.
\registerctxluafile{syst-aux}{1.001}
+% A dedicated primitive \ifvoidmacro\cs == \ifx\cs\empty is some 10% faster but
+% probably not that noticeable in practice. An \ifvoidtoks might make sense but we
+% don't test that often for it (and it's more work to implement in the engine).
+
%D This is a stripped down combination of:
%D
%D \startitemize
@@ -26,20 +30,18 @@
%D \item \type {syst-new.tex}
%D \stopitemize
%D
-%D We keep them around (for \MKII) so you can find comments,
-%D experiences, intermediate versions and cleaner variants
-%D there (and also non-\ETEX\ variants).
+%D We keep them around (for \MKII) so you can find comments, experiences,
+%D intermediate versions and cleaner variants there (and also non-\ETEX\ variants).
%D
-%D Contrary to the older files, we now assume that this one
-%D is used in \CONTEXT\ and therefore we might also assume that
-%D some basic functionality is available.
+%D Contrary to the older files, we now assume that this one is used in \CONTEXT\ and
+%D therefore we might also assume that some basic functionality is available.
%D
-%D The original files contain previous implementations and notes about
-%D performance. This file will be stripped down in due time.
-
-%D Some of the macros here were only used in the bibliography module. They
-%D have been be moved to a separate syst module since the bib module is no
-%D longer using them. Some more will go away.
+%D The original files contain previous implementations and notes about performance.
+%D This file will be stripped down in due time.
+%D
+%D Some of the macros here were only used in the bibliography module. They have been
+%D be moved to a separate syst module since the bib module is no longer using them.
+%D Some more will go away.
\unprotect
@@ -72,13 +74,20 @@
% %def\expunded#1{\normalexpanded\expandafter{#1}}
% \def\expunded#1{\expandafter\empty#1} % used within an edef anyway
-
%D As we don't have namespace definers yet, we use a special one:
-\newcount\c_syst_helpers_n_of_namespaces \c_syst_helpers_n_of_namespaces\pluseight % 1-8 reserved for catcodes
+\ifdefined\c_syst_helpers_n_of_namespaces
+
+ % lets plug in a better error message
+
+\else
+
+ \newcount\c_syst_helpers_n_of_namespaces \c_syst_helpers_n_of_namespaces\pluseight % 1-8 reserved for catcodes
-\def\v_interfaces_prefix_template_system{\number \c_syst_helpers_n_of_namespaces>>}
-%def\v_interfaces_prefix_template_system{\characters\c_syst_helpers_n_of_namespaces>>} % no \characters yet
+ \def\v_interfaces_prefix_template_system{\number \c_syst_helpers_n_of_namespaces>>}
+ %def\v_interfaces_prefix_template_system{\characters\c_syst_helpers_n_of_namespaces>>} % no \characters yet
+
+\fi
\unexpanded\def\installsystemnamespace#1% maybe move this to syst-ini
{\ifcsname ??#1\endcsname
@@ -128,10 +137,16 @@
\newif\if!!doned \newif\if!!donee \newif\if!!donef
\def\!!zerocount {0} % alongside \zerocount
-\def\!!minusone {-1} % alongside \minusone
-\def\!!plusone {1} % alongside \plusone
-\def\!!plustwo {2} % alongside \plustwo
-\def\!!plusthree {3} % alongside \plusthree
+\def\!!minusone {-1} % ...
+\def\!!plusone {1} % ...
+\def\!!plustwo {2} % ...
+\def\!!plusthree {3} % ...
+\def\!!plusfour {4} % ...
+\def\!!plusfive {5} % ...
+\def\!!plussix {6} % ...
+\def\!!plusseven {7} % ...
+\def\!!pluseight {8} % ...
+\def\!!plusnine {9} % alongside \plusnine
\setnewconstant \uprotationangle 0
\setnewconstant\rightrotationangle 90
@@ -272,12 +287,14 @@
%D {\localnext} because we don't want clashes with \type
%D {\next}.
-\unexpanded\def\doifnextcharelse#1#2#3% #1 should not be {} !
+\unexpanded\def\doifelsenextchar#1#2#3% #1 should not be {} !
{\let\charactertoken=#1% = needed here
\def\m_syst_action_yes{#2}%
\def\m_syst_action_nop{#3}%
\futurelet\nexttoken\syst_helpers_inspect_next_character}
+\let\doifnextcharelse\doifelsenextchar
+
\def\syst_helpers_inspect_next_character
{\ifx\nexttoken\blankspace
\expandafter\syst_helpers_reinspect_next_character
@@ -312,18 +329,21 @@
\let\syst_helpers_next_optional_character_token=[
-\unexpanded\def\doifnextoptionalelse#1#2%
+\unexpanded\def\doifelsenextoptional#1#2%
{\def\m_syst_action_yes{#1}%
\def\m_syst_action_nop{#2}%
\let\if_next_blank_space_token\iffalse
\futurelet\nexttoken\syst_helpers_inspect_next_optional_character}
-\unexpanded\def\doifnextoptionalcselse#1#2% \cs \cs (upto 10% faster)
+\unexpanded\def\doifelsenextoptionalcs#1#2% \cs \cs (upto 10% faster)
{\let\m_syst_action_yes#1%
\let\m_syst_action_nop#2%
\let\if_next_blank_space_token\iffalse
\futurelet\nexttoken\syst_helpers_inspect_next_optional_character}
+\let\doifnextoptionalelse \doifelsenextoptional
+\let\doifnextoptionalcselse\doifelsenextoptionalcs
+
\def\syst_helpers_inspect_next_optional_character
{\ifx\nexttoken\blankspace
\expandafter\syst_helpers_reinspect_next_optional_character
@@ -340,12 +360,21 @@
\let\syst_helpers_next_bgroup_character_token\bgroup
-\unexpanded\def\doifnextbgroupelse#1#2%
+\unexpanded\def\doifelsenextbgroup#1#2%
{\def\m_syst_action_yes{#1}%
\def\m_syst_action_nop{#2}%
\let\if_next_blank_space_token\iffalse
\futurelet\nexttoken\syst_helpers_inspect_next_bgroup_character}
+\unexpanded\def\doifelsenextbgroupcs#1#2%
+ {\let\m_syst_action_yes#1%
+ \let\m_syst_action_nop#2%
+ \let\if_next_blank_space_token\iffalse
+ \futurelet\nexttoken\syst_helpers_inspect_next_bgroup_character}
+
+\let\doifnextbgroupelse \doifelsenextbgroup
+\let\doifnextbgroupcselse\doifelsenextbgroupcs
+
\def\syst_helpers_inspect_next_bgroup_character
{\ifx\nexttoken\blankspace
\expandafter\syst_helpers_reinspect_next_bgroup_character
@@ -362,12 +391,14 @@
\let\syst_helpers_next_parenthesis_character_token(
-\unexpanded\def\doifnextparenthesiselse#1#2%
+\unexpanded\def\doifelsenextparenthesis#1#2%
{\def\m_syst_action_yes{#1}%
\def\m_syst_action_nop{#2}%
\let\if_next_blank_space_token\iffalse
\futurelet\nexttoken\syst_helpers_inspect_next_parenthesis_character}
+\let\doifnextparenthesiselse\doifelsenextparenthesis
+
\def\syst_helpers_inspect_next_parenthesis_character
{\ifx\nexttoken\blankspace
\expandafter\syst_helpers_reinspect_next_parenthesis_character
@@ -384,16 +415,19 @@
%D The next one is handy in predictable situations:
-\unexpanded\def\doiffastoptionalcheckelse#1#2%
+\unexpanded\def\doifelsefastoptionalcheck#1#2%
{\def\m_syst_action_yes{#1}%
\def\m_syst_action_nop{#2}%
\futurelet\nexttoken\syst_helpers_do_if_fast_optional_check_else}
-\unexpanded\def\doiffastoptionalcheckcselse#1#2% \cs \cs
+\unexpanded\def\doifelsefastoptionalcheckcs#1#2% \cs \cs
{\let\m_syst_action_yes#1%
\let\m_syst_action_nop#2%
\futurelet\nexttoken\syst_helpers_do_if_fast_optional_check_else}
+\let\doiffastoptionalcheckelse \doifelsefastoptionalcheck
+\let\doiffastoptionalcheckcselse\doifelsefastoptionalcheckcs
+
\def\syst_helpers_do_if_fast_optional_check_else
{\ifx\nexttoken\syst_helpers_next_optional_character_token
\expandafter\m_syst_action_yes
@@ -562,12 +596,12 @@
\suppressifcsnameerror\plusone
-\def\doifundefinedelse#1%
+\def\doifelseundefined#1%
{\ifcsname#1\endcsname
\expandafter\secondoftwoarguments\else\expandafter\firstoftwoarguments
\fi}
-\def\doifdefinedelse#1%
+\def\doifelsedefined#1%
{\ifcsname#1\endcsname
\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments
\fi}
@@ -582,6 +616,9 @@
\expandafter\firstofoneargument\else\expandafter\gobbleoneargument
\fi}
+\let\doifundefinedelse\doifelseundefined
+\let\doifdefinedelse \doifelsedefined
+
%D \macros
%D {letbeundefined}
%D
@@ -605,7 +642,7 @@
%D behavior in text and math mode, which was due to this grouping subtilities. We
%D therefore decided to use \type{\begingroup} instead of \type{\bgroup}.
-\unexpanded\def\doifalldefinedelse#1%
+\unexpanded\def\doifelsealldefined#1%
{\begingroup
\donetrue % we could use a reserved one and avoid the group
\processcommalist[#1]\syst_helpers_do_if_all_defined_else
@@ -615,6 +652,8 @@
\endgroup\expandafter\secondoftwoarguments
\fi}
+\let\doifalldefinedelse\doifelsealldefined
+
\def\syst_helpers_do_if_all_defined_else#1%
{\ifcsname#1\endcsname\else
\donefalse
@@ -678,7 +717,7 @@
%D
%D This time, the string is not expanded.
-\unexpanded\def\doifemptyelse#1%
+\unexpanded\def\doifelseempty#1%
{\def\m_syst_string_one{#1}%
\ifx\m_syst_string_one\empty
\expandafter\firstoftwoarguments
@@ -686,6 +725,8 @@
\expandafter\secondoftwoarguments
\fi}
+\let\doifemptyelse\doifelseempty
+
\unexpanded\def\doifempty#1%
{\def\m_syst_string_one{#1}%
\ifx\m_syst_string_one\empty
@@ -751,7 +792,7 @@
\def\syst_helpers_re_do_if_in_set {\expandafter\syst_helpers_do_check_if_item_in_set \m_syst_string_two,],\relax}
\def\syst_helpers_re_do_if_not_in_set {\expandafter\syst_helpers_do_check_if_item_not_in_set \m_syst_string_two,],\relax}
-\unexpanded\def\doifinsetelse#1% make this two step too
+\unexpanded\def\doifelseinset#1% make this two step too
{\edef\m_syst_string_one{#1}%
\ifx\m_syst_string_one\empty
\expandafter\thirdofthreearguments
@@ -759,6 +800,8 @@
\expandafter\syst_helpers_do_if_in_set_else
\fi}
+\let\doifinsetelse\doifelseinset
+
\def\syst_helpers_do_if_in_set_else#1%
{\edef\m_syst_string_two{#1}%
\ifx\m_syst_string_two\empty
@@ -949,10 +992,12 @@
\fi\fi
#1#2}
-\unexpanded\def\doifcommonelse{\syst_helpers_do_do_if_common_else\firstoftwoarguments\secondoftwoarguments}
+\unexpanded\def\doifelsecommon{\syst_helpers_do_do_if_common_else\firstoftwoarguments\secondoftwoarguments}
\unexpanded\def\doifcommon {\syst_helpers_do_do_if_common_else\firstofoneargument \gobbleoneargument }
\unexpanded\def\doifnotcommon {\syst_helpers_do_do_if_common_else\gobbleoneargument \firstofoneargument }
+\let\doifcommonelse\doifelsecommon
+
%D \macros
%D {processcommalist,processcommacommand,quitcommalist,
%D processcommalistwithparameters}
@@ -1294,10 +1339,12 @@
\let\firstcharacter \empty
\let\remainingcharacters\empty
-\unexpanded\def\getfirstcharacter #1{\ctxcommand{getfirstcharacter(\!!bs#1\!!es)}}
-\unexpanded\def\doiffirstcharelse #1#2{\ctxcommand{doiffirstcharelse(\!!bs#1\!!es,\!!bs#2\!!es)}} % chr str
-\unexpanded\def\thefirstcharacter #1{\ctxcommand{thefirstcharacter(\!!bs#1\!!es)}}
-\unexpanded\def\theremainingcharacters#1{\ctxcommand{theremainingcharacters(\!!bs#1\!!es)}}
+\unexpanded\def\getfirstcharacter #1{\clf_getfirstcharacter{#1}}
+\unexpanded\def\doifelsefirstchar #1#2{\clf_doifelsefirstchar{#1}{#2}}
+\unexpanded\def\thefirstcharacter #1{\clf_thefirstcharacter{#1}}
+\unexpanded\def\theremainingcharacters#1{\clf_theremainingcharacters{#1}}
+
+\let\doiffirstcharelse\doifelsefirstchar
%D \macros
%D {doifinstringelse, doifincsnameelse}
@@ -1311,7 +1358,7 @@
\let\m_syst_sub_string\empty
-\unexpanded\def\doifinstringelse#1%
+\unexpanded\def\doifelseinstring#1%
{\edef\m_syst_sub_string{#1}% expand #1 here
\ifx\m_syst_sub_string\empty
\expandafter\thirdofthreearguments
@@ -1319,6 +1366,8 @@
\expandafter\syst_helpers_do_if_in_string_else_indeed
\fi}
+\let\doifinstringelse\doifelseinstring
+
\unexpanded\def\syst_helpers_do_if_in_string_else_indeed#1%
{\syst_helpers_do_if_in_string_else\m_syst_sub_string{#1}%
\expandafter\firstoftwoarguments
@@ -1381,13 +1430,15 @@
{\unless\if##2@}%
\expandafter\syst_helpers_do_do_if_in_csname_else#2#1@@\_e_o_s_}
-\unexpanded\def\doifincsnameelse#1#2%
+\unexpanded\def\doifelseincsname#1#2%
{\normalexpanded{\syst_helpers_do_if_in_csname_else{#1}}{#2}%
\expandafter\firstoftwoarguments
\else
\expandafter\secondoftwoarguments
\fi}
+\let\doifincsnameelse\doifelseincsname
+
%D \macros
%D {doifnumberelse,doifnumber,doifnotnumber}
%D
@@ -1403,13 +1454,15 @@
%D The macro accepts \type {123}, \type {abc}, \type {{}}, \type {\getal} and
%D \type {\the\count...}. This macro is a rather dirty one.
-\def\doifnumberelse#1% does not accept counters (fully expandable)
+\def\doifelsenumber#1% does not accept counters (fully expandable)
{\ifcase0\ifcase1#1\or\or\or\or\or\or\or\or\or\else1\fi\space
\expandafter\secondoftwoarguments
\else
\expandafter\firstoftwoarguments
\fi}
+\let\doifnumberelse\doifelsenumber
+
\def\doifnumber#1%
{\ifcase0\ifcase1#1\or\or\or\or\or\or\or\or\or\else1\fi\space
\expandafter\firstofoneargument
@@ -1434,10 +1487,10 @@
%D \stoptyping
\def\percentdimen#1#2% dimen percentage (with %)
- {\dimexpr\ctxcommand{percentageof("#2",\number#1)}\relax}
+ {\dimexpr\clf_percentageof{#2}\dimexpr#1\relax}
\unexpanded\def\setpercentdimen#1#2% dimen percentage (with %)
- {#1=\ctxcommand{percentageof("#2",\number#1)}\relax}
+ {#1=\clf_percentageof{#2}\dimexpr#1\relax}
%D \macros
%D {makerawcommalist,
@@ -1457,7 +1510,7 @@
%D
%D \starttyping
%D \makerawcommalist[string,string,...]\stringlist
-%D \rawdoifinsetelse{string}{string,...}{...}{...}
+%D \rawdoifelseinset{string}{string,...}{...}{...}
%D \rawprocesscommalist[string,string,...]\commando
%D \rawprocessaction[x][a=>\a,b=>\b,c=>\c]
%D \stoptyping
@@ -1492,12 +1545,12 @@
\unexpanded\def\rawprocesscommacommand[#1]% not really needed
{\normalexpanded{\rawprocesscommalist[#1]}}
-% \def\rawdoifinsetelse#1#2{\doifinstringelse{,#1,}{,#2,}}
+% \def\rawdoifelseinset#1#2{\doifinstringelse{,#1,}{,#2,}}
% \def\rawdoifinset #1#2{\doifinstring {,#1,}{,#2,}}
\def\m_syst_two_commas{,,}
-\unexpanded\def\rawdoifinsetelse#1%
+\unexpanded\def\rawdoifelseinset#1%
{\edef\m_syst_sub_string{,#1,}% expand #1 here
\ifx\m_syst_sub_string\m_syst_two_commas
\expandafter\thirdofthreearguments
@@ -1505,6 +1558,8 @@
\expandafter\syst_helpers_raw_do_if_in_set_else
\fi}
+\let\rawdoifinsetelse\rawdoifinsetelse
+
\unexpanded\def\syst_helpers_raw_do_if_in_set_else#1%
{\syst_helpers_do_if_in_string_else\m_syst_sub_string{,#1,}%
\expandafter\firstoftwoarguments
@@ -2170,7 +2225,7 @@
\unexpanded\def\dosingleempty#1%
{\syst_helpers_argument_reset
- \doifnextoptionalelse
+ \doifelsenextoptional
{\firstargumenttrue#1}%
{\syst_helpers_single_empty_one_nop#1}}
@@ -2182,13 +2237,13 @@
\unexpanded\def\dodoubleempty#1%
{\syst_helpers_argument_reset
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_double_empty_one_yes#1}%
{\syst_helpers_double_empty_one_nop#1}}
\def\syst_helpers_double_empty_one_yes#1[#2]%
{\firstargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\secondargumenttrue#1[{#2}]}%
{\syst_helpers_double_empty_two_nop#1{#2}}}
@@ -2212,19 +2267,19 @@
\unexpanded\def\dotripleempty#1%
{\syst_helpers_argument_reset
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_triple_empty_one_yes#1}%
{\syst_helpers_triple_empty_one_nop#1}}
\def\syst_helpers_triple_empty_one_yes#1[#2]%
{\firstargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_triple_empty_two_yes#1{#2}}%
{\syst_helpers_triple_empty_two_nop#1{#2}}}
\def\syst_helpers_triple_empty_two_yes#1#2[#3]%
{\secondargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\thirdargumenttrue#1[{#2}][{#3}]}%
{\syst_helpers_triple_empty_three_nop#1{#2}{#3}}}
@@ -2260,25 +2315,25 @@
\unexpanded\def\doquadrupleempty#1%
{\syst_helpers_argument_reset
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_quadruple_empty_one_yes#1}%
{\syst_helpers_quadruple_empty_one_nop#1}}
\def\syst_helpers_quadruple_empty_one_yes#1[#2]%
{\firstargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_quadruple_empty_two_yes#1{#2}}%
{\syst_helpers_quadruple_empty_two_nop#1{#2}}}
\def\syst_helpers_quadruple_empty_two_yes#1#2[#3]%
{\secondargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_quadruple_empty_three_yes#1{#2}{#3}}%
{\syst_helpers_quadruple_empty_three_nop#1{#2}{#3}}}
\def\syst_helpers_quadruple_empty_three_yes#1#2#3[#4]%
{\thirdargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\fourthargumenttrue#1[{#2}][{#3}][{#4}]}%
{\syst_helpers_quadruple_empty_four_nop#1{#2}{#3}{#4}}}
@@ -2327,31 +2382,31 @@
\unexpanded\def\doquintupleempty#1%
{\syst_helpers_argument_reset
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_quintuple_empty_one_yes#1}%
{\syst_helpers_quintuple_empty_one_nop#1}}
\def\syst_helpers_quintuple_empty_one_yes#1[#2]%
{\firstargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_quintuple_empty_two_yes#1{#2}}%
{\syst_helpers_quintuple_empty_two_nop#1{#2}}}
\def\syst_helpers_quintuple_empty_two_yes#1#2[#3]%
{\secondargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_quintuple_empty_three_yes#1{#2}{#3}}%
{\syst_helpers_quintuple_empty_three_nop#1{#2}{#3}}}
\def\syst_helpers_quintuple_empty_three_yes#1#2#3[#4]%
{\thirdargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_quintuple_empty_four_yes#1{#2}{#3}{#4}}%
{\syst_helpers_quintuple_empty_four_nop#1{#2}{#3}{#4}}}
\def\syst_helpers_quintuple_empty_four_yes#1#2#3#4[#5]%
{\fourthargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\fifthargumenttrue#1[{#2}][{#3}][{#4}][{#5}]}%
{\syst_helpers_quintuple_empty_five_nop#1{#2}{#3}{#4}{#5}}}
@@ -2414,37 +2469,37 @@
\unexpanded\def\dosixtupleempty#1%
{\syst_helpers_argument_reset
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_sixtuple_empty_one_yes#1}
{\syst_helpers_sixtuple_empty_one_nop#1}}
\def\syst_helpers_sixtuple_empty_one_yes#1[#2]%
{\firstargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_sixtuple_empty_two_yes#1{#2}}%
{\syst_helpers_sixtuple_empty_two_nop#1{#2}}}
\def\syst_helpers_sixtuple_empty_two_yes#1#2[#3]%
{\secondargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_sixtuple_empty_three_yes#1{#2}{#3}}%
{\syst_helpers_sixtuple_empty_three_nop#1{#2}{#3}}}
\def\syst_helpers_sixtuple_empty_three_yes#1#2#3[#4]%
{\thirdargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_sixtuple_empty_four_yes#1{#2}{#3}{#4}}%
{\syst_helpers_sixtuple_empty_four_nop#1{#2}{#3}{#4}}}
\def\syst_helpers_sixtuple_empty_four_yes#1#2#3#4[#5]%
{\fourthargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_sixtuple_empty_five_yes#1{#2}{#3}{#4}{#5}}%
{\syst_helpers_sixtuple_empty_five_nop#1{#2}{#3}{#4}{#5}}}
\def\syst_helpers_sixtuple_empty_five_yes#1#2#3#4#5[#6]%
{\fifthargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\sixthargumenttrue#1[{#2}][{#3}][{#4}][{#5}][{#6}]}%
{\syst_helpers_sixtuple_empty_six_nop#1{#2}{#3}{#4}{#5}{#6}}}
@@ -2522,43 +2577,43 @@
\unexpanded\def\doseventupleempty#1%
{\syst_helpers_argument_reset
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_seventuple_empty_one_yes#1}%
{\syst_helpers_seventuple_empty_one_nop#1}}
\def\syst_helpers_seventuple_empty_one_yes#1[#2]%
{\firstargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_seventuple_empty_two_yes#1{#2}}%
{\syst_helpers_seventuple_empty_two_nop#1{#2}}}
\def\syst_helpers_seventuple_empty_two_yes#1#2[#3]%
{\secondargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_seventuple_empty_three_yes#1{#2}{#3}}%
{\syst_helpers_seventuple_empty_three_nop#1{#2}{#3}}}
\def\syst_helpers_seventuple_empty_three_yes#1#2#3[#4]%
{\thirdargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_seventuple_empty_four_yes#1{#2}{#3}{#4}}%
{\syst_helpers_seventuple_empty_four_nop#1{#2}{#3}{#4}}}
\def\syst_helpers_seventuple_empty_four_yes#1#2#3#4[#5]%
{\fourthargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_seventuple_empty_five_yes#1{#2}{#3}{#4}{#5}}%
{\syst_helpers_seventuple_empty_five_nop#1{#2}{#3}{#4}{#5}}}
\def\syst_helpers_seventuple_empty_five_yes#1#2#3#4#5[#6]%
{\fifthargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\syst_helpers_seventuple_empty_six_yes#1{#2}{#3}{#4}{#5}{#6}}%
{\syst_helpers_seventuple_empty_six_nop#1{#2}{#3}{#4}{#5}{#6}}}
\def\syst_helpers_seventuple_empty_six_yes#1#2#3#4#5#6[#7]%
{\sixthargumenttrue
- \doifnextoptionalelse
+ \doifelsenextoptional
{\seventhargumenttrue#1[{#2}][{#3}][{#4}][{#5}][{#6}][{#7}]}%
{\syst_helpers_seventuple_empty_seven_nop#1{#2}{#3}{#4}{#5}{#6}{#7}}}
@@ -2714,13 +2769,13 @@
\unexpanded\def\complexorsimple#1%
{% \relax % prevents lookahead, brrr
- \doifnextoptionalelse
+ \doifelsenextoptional
{\firstargumenttrue \csname\s!complex\strippedcsname#1\endcsname}
{\firstargumentfalse\csname\s!simple \strippedcsname#1\endcsname}}
\unexpanded\def\complexorsimpleempty#1%
{% \relax % prevents lookahead, brrr
- \doifnextoptionalelse
+ \doifelsenextoptional
{\firstargumenttrue \csname\s!complex\strippedcsname#1\endcsname}
{\firstargumentfalse\csname\s!complex\strippedcsname#1\endcsname[]}}
@@ -2732,10 +2787,10 @@
%D in protection.
\unexpanded\def\syst_helpers_complex_or_simple#1#2%
- {\doifnextoptionalelse{\firstargumenttrue#1}{\firstargumentfalse#2}}
+ {\doifelsenextoptional{\firstargumenttrue#1}{\firstargumentfalse#2}}
\unexpanded\def\syst_helpers_complex_or_simple_empty#1%
- {\doifnextoptionalelse{\firstargumenttrue#1}{\firstargumentfalse#1[]}}
+ {\doifelsenextoptional{\firstargumenttrue#1}{\firstargumentfalse#1[]}}
\unexpanded\def\definecomplexorsimple#1%
{\unexpanded\edef#1{\syst_helpers_complex_or_simple
@@ -2936,7 +2991,14 @@
\def\fifthofsixarguments #1#2#3#4#5#6{#5}
\def\sixthofsixarguments #1#2#3#4#5#6{#6}
-\unexpanded\def\firstofoneunexpanded#1{#1}
+\unexpanded\def\firstofoneunexpanded #1{#1}
+
+\unexpanded\def\firstoftwounexpanded #1#2{#1}
+\unexpanded\def\secondoftwounexpanded #1#2{#2}
+
+\unexpanded\def\firstofthreeunexpanded #1#2#3{#1}
+\unexpanded\def\secondofthreeunexpanded#1#2#3{#2}
+\unexpanded\def\thirdofthreeunexpanded #1#2#3{#3}
%D \macros
%D {globalletempty,letempty,
@@ -3021,7 +3083,7 @@
%D
%D A fully expandable message:
-\def\immediatemessage#1{\ctxlua{logs.status("message","#1")}}
+\let\immediatemessage\clf_immediatemessage % {} mandate
%D \macros
%D {debuggerinfo}
@@ -3237,6 +3299,25 @@
% [here #oeps: \the\scratchcounter]
% \stoptexdefinition
+% \bgroup \obeylines
+%
+% \global\let\stoptexdefinition\relax
+%
+% \unexpanded\gdef\starttexdefinition%
+% {\bgroup%
+% \obeylines%
+% \syst_helpers_start_tex_definition_one}
+%
+% \gdef\syst_helpers_start_tex_definition_one#1
+% {\catcode\endoflineasciicode\ignorecatcode%
+% \syst_helpers_start_tex_definition_two{#1}}
+%
+% \gdef\syst_helpers_start_tex_definition_two#1#2\stoptexdefinition%
+% {\egroup%
+% \ctxcommand{thetexdefinition("#1")}{#2}}
+%
+% \egroup
+
\bgroup \obeylines
\global\let\stoptexdefinition\relax
@@ -3244,19 +3325,19 @@
\unexpanded\gdef\starttexdefinition%
{\bgroup%
\obeylines%
- \syst_helpers_start_tex_definition_one}
+ \syst_helpers_start_tex_definition}
-\gdef\syst_helpers_start_tex_definition_one#1
+\gdef\syst_helpers_start_tex_definition#1
{\catcode\endoflineasciicode\ignorecatcode%
- \syst_helpers_start_tex_definition_two{#1}}
+ \clf_texdefinition_one{#1}}
-\gdef\syst_helpers_start_tex_definition_two#1#2\stoptexdefinition%
+\gdef\dostarttexdefinition#1\stoptexdefinition%
{\egroup%
- \ctxcommand{thetexdefinition("#1")}{#2}}
+ \clf_texdefinition_two{#1}}
\egroup
-\unexpanded\def\texdefinition#1{\csname\ifcsname#1\endcsname#1\else donothing\fi\endcsname}
+\unexpanded\def\texdefinition#1{\csname\ifcsname#1\endcsname#1\else donothing\fi\endcsname} % todo: a nop cs: char 0 or some corenamespace
% This is a first variant, more might be added:
@@ -3333,14 +3414,14 @@
\def\syst_helpers_do_do_do_increment#1,#2){\dodoglobal\edef#1{\the\numexpr\ifdefined#1\ifx#1\relax\else#1\fi\fi+#2\relax}}
\def\syst_helpers_do_do_do_decrement#1,#2){\dodoglobal\edef#1{\the\numexpr\ifdefined#1\ifx#1\relax\else#1\fi\fi-#2\relax}}
-\def\syst_helpers_do_do_increment(#1{\doifnextcharelse,{\syst_helpers_do_do_do_increment#1}{\syst_helpers_do_do_do_increment#1,\plusone}}
-\def\syst_helpers_do_do_decrement(#1{\doifnextcharelse,{\syst_helpers_do_do_do_decrement#1}{\syst_helpers_do_do_do_decrement#1,\plusone}}
+\def\syst_helpers_do_do_increment(#1{\doifelsenextchar,{\syst_helpers_do_do_do_increment#1}{\syst_helpers_do_do_do_increment#1,\plusone}}
+\def\syst_helpers_do_do_decrement(#1{\doifelsenextchar,{\syst_helpers_do_do_do_decrement#1}{\syst_helpers_do_do_do_decrement#1,\plusone}}
\unexpanded\def\fastincrement#1{\dodoglobal\edef#1{\the\numexpr#1+\plusone \relax}}
\unexpanded\def\fastdecrement#1{\dodoglobal\edef#1{\the\numexpr#1+\minusone\relax}}
-\unexpanded\def\increment{\doifnextcharelse(\syst_helpers_do_do_increment\syst_helpers_do_increment}
-\unexpanded\def\decrement{\doifnextcharelse(\syst_helpers_do_do_decrement\syst_helpers_do_decrement}
+\unexpanded\def\increment{\doifelsenextchar(\syst_helpers_do_do_increment\syst_helpers_do_increment}
+\unexpanded\def\decrement{\doifelsenextchar(\syst_helpers_do_do_decrement\syst_helpers_do_decrement}
\unexpanded\def\incrementvalue#1{\expandafter\increment\csname#1\endcsname}
\unexpanded\def\decrementvalue#1{\expandafter\decrement\csname#1\endcsname}
@@ -3384,6 +3465,7 @@
{\expandafter\syst_helpers_checked_stripped_csname\string#1}
\def\syst_helpers_checked_stripped_csname#1%
+ %{\ifx#1\letterbackslash\else#1\fi}
{\if\noexpand#1\letterbackslash\else#1\fi}
%D \macros
@@ -4016,13 +4098,15 @@
\def\syst_helpers_check_if_assignment_else#1=#2#3\_e_o_p_{\if#2@}%
-\unexpanded\def\doifassignmentelse#1% expandable
+\unexpanded\def\doifelseassignment#1% expandable
{\expandafter\syst_helpers_check_if_assignment_else\detokenize{#1}=@@\_e_o_p_
\expandafter\secondoftwoarguments
\else
\expandafter\firstoftwoarguments
\fi}
+\let\doifassignmentelse\doifelseassignment
+
\newif\ifassignment
\unexpanded\def\docheckassignment#1%
@@ -4095,7 +4179,7 @@
%D
%D Watch the one level expansion of the second argument.
-\unexpanded\def\doifmeaningelse#1#2%
+\unexpanded\def\doifelsemeaning#1#2%
{\edef\m_syst_string_one{\meaning#1}%
\def \m_syst_string_two{#2}%
\edef\m_syst_string_two{\meaning\m_syst_string_two}%
@@ -4105,6 +4189,8 @@
\expandafter\secondoftwoarguments
\fi}
+\let\doifmeaningelse\doifelsemeaning
+
%D \macros
%D {doifsamestringselse,doifsamestring,doifnotsamestring}
%D
@@ -4122,10 +4208,12 @@
\edef\m_syst_string_two{\detokenize\expandafter{\normalexpanded{#4}}}%
\ifx\m_syst_string_one\m_syst_string_two\expandafter#1\else\expandafter#2\fi}
-\unexpanded\def\doifsamestringelse{\syst_helpers_if_samestring_else\firstoftwoarguments\secondoftwoarguments}
+\unexpanded\def\doifelsesamestring{\syst_helpers_if_samestring_else\firstoftwoarguments\secondoftwoarguments}
\unexpanded\def\doifsamestring {\syst_helpers_if_samestring_else\firstofoneargument \gobbleoneargument }
\unexpanded\def\doifnotsamestring {\syst_helpers_if_samestring_else\gobbleoneargument \firstofoneargument }
+\let\doifsamestringelse\doifelsesamestring
+
%D \macros
%D {ConvertToConstant,ConvertConstantAfter}
%D
@@ -4187,7 +4275,7 @@
\unexpanded\def\CheckConstantAfter#1#2%
{\expandafter\convertargument\v!prefix!\to\ascii
\convertargument#1\to#2\relax
- \doifinstringelse\ascii{#2}
+ \doifelseinstring\ascii{#2}
{\expandafter\convertargument#1\to#2}
{}}
@@ -4426,6 +4514,18 @@
{\m_syst_helpers_handle_group_after
\egroup}%
+\unexpanded\def\syst_helpers_handle_group_pickup#1#2#3% no inner group (so no kerning interference)
+ {\bgroup
+ \def\m_syst_helpers_handle_group_before{#1}%
+ \def\m_syst_helpers_handle_group_after {#2\egroup#3}%
+ \afterassignment\m_syst_helpers_handle_group_pickup_before
+ \let\next=}
+
+\def\m_syst_helpers_handle_group_pickup_before
+ {\bgroup
+ \aftergroup\m_syst_helpers_handle_group_after
+ \m_syst_helpers_handle_group_before}
+
\unexpanded\def\syst_helpers_handle_group_nop
{\ifnum\currentgrouptype=\semisimplegroupcode
\expandafter\syst_helpers_handle_group_nop_a
@@ -4458,10 +4558,13 @@
%D implementation became:
\unexpanded\def\groupedcommand#1#2%
- {\doifnextbgroupelse{\syst_helpers_handle_group_normal{#1}{#2}}{\syst_helpers_handle_group_nop{#1}{#2}}}
+ {\doifelsenextbgroup{\syst_helpers_handle_group_normal{#1}{#2}}{\syst_helpers_handle_group_nop{#1}{#2}}}
\unexpanded\def\simplegroupedcommand#1#2%
- {\doifnextbgroupelse{\syst_helpers_handle_group_simple{#1}{#2}}{\syst_helpers_handle_group_nop{#1}{#2}}}
+ {\doifelsenextbgroup{\syst_helpers_handle_group_simple{#1}{#2}}{\syst_helpers_handle_group_nop{#1}{#2}}}
+
+\unexpanded\def\pickupgroupedcommand#1#2#3%
+ {\doifelsenextbgroup{\syst_helpers_handle_group_pickup{#1}{#2}{#3}}{\syst_helpers_handle_group_nop{#1}{#2}}}
%D Users should be aware of the fact that grouping can
%D interfere with ones paragraph settings that are executed
@@ -4555,14 +4658,14 @@
\newtoks\AfterPar
\def\redowithpar\par
- {\doifnextcharelse\par\redowithpar\dodowithpar}%
+ {\doifelsenextchar\par\redowithpar\dodowithpar}%
\def\dowithpar#1#2%
{\def\dodowithpar##1\par{#1##1#2}%
\redowithpar\par}
\def\redogotopar\par
- {\doifnextcharelse\par\redogotopar\dodogotopar}%
+ {\doifelsenextchar\par\redogotopar\dodogotopar}%
\def\dogotopar#1%
{\def\dodogotopar{#1}%
@@ -4626,7 +4729,7 @@
\unexpanded\def\dowithpargument#1%
{\def\syst_helpers_next_par##1 \par{#1{##1}}%
\def\syst_helpers_next_arg##1{#1{##1}}%
- \doifnextbgroupelse\syst_helpers_next_arg{\doifnextcharelse\par{#1{}}\syst_helpers_next_par}}
+ \doifelsenextbgroup\syst_helpers_next_arg{\doifelsenextchar\par{#1{}}\syst_helpers_next_par}}
%D The \type{p} in the previous command stands for paragraph.
%D When we want to act upon words we can use the \type{w}
@@ -4656,7 +4759,7 @@
\unexpanded\def\dowithwargument#1%
{\def\syst_helpers_next_war##1 {#1{##1}}%
\def\syst_helpers_next_arg##1{#1{##1}}%
- \doifnextbgroupelse\syst_helpers_next_arg\syst_helpers_next_war}
+ \doifelsenextbgroup\syst_helpers_next_arg\syst_helpers_next_war}
%D \macros
%D {dorepeat,dorepeatwithcommand}
@@ -4751,11 +4854,13 @@
\expandafter\firstoftwoarguments
\fi}
-\def\doifstringinstringelse#1#2%
+\def\doifelsestringinstring#1#2%
{\expandafter\def\expandafter\syst_helpers_if_instring_else\expandafter##\expandafter1#1##2##3\_e_o_s_
{\syst_helpers_if_instring_else_indeed##2}%
\expandafter\expandafter\expandafter\syst_helpers_if_instring_else\expandafter#2#1@@\_e_o_s_}
+\let\doifstringinstringelse\doifelsestringinstring
+
%D \macros
%D {appendtoks,prependtoks,appendtoksonce,prependtoksonce,
%D doifintokselse,flushtoks,dotoks}
@@ -4801,19 +4906,21 @@
\def\syst_helpers_append_toks_once#1\to#2%
{\let\m_syst_helpers_scratch#2%
\t_syst_helpers_scratch\expandafter{\gobbleoneargument#1}%
- \doifintokselse\t_syst_helpers_scratch\m_syst_helpers_scratch\donothing\syst_helpers_append_toks_indeed}
+ \doifelseintoks\t_syst_helpers_scratch\m_syst_helpers_scratch\donothing\syst_helpers_append_toks_indeed}
\def\syst_helpers_prepend_toks_once#1\to#2%
{\let\m_syst_helpers_scratch#2%
\t_syst_helpers_scratch\expandafter{\gobbleoneargument#1}%
- \doifintokselse\t_syst_helpers_scratch\m_syst_helpers_scratch\donothing\syst_helpers_prepend_toks_indeed}
+ \doifelseintoks\t_syst_helpers_scratch\m_syst_helpers_scratch\donothing\syst_helpers_prepend_toks_indeed}
%D The test macro:
-\unexpanded\def\doifintokselse#1#2% #1 en #2 zijn toks
+\unexpanded\def\doifelseintoks#1#2% #1 en #2 zijn toks
{\edef\asciia{\detokenize\expandafter{\the#1}}%
\edef\asciib{\detokenize\expandafter{\the#2}}%
- \doifstringinstringelse\asciia\asciib}
+ \doifelsestringinstring\asciia\asciib}
+
+\let\doifintokselse\doifelseintoks
%D A nice one too:
@@ -5007,24 +5114,26 @@
{\dodoglobal\edef#2{#1\ifx#2\empty\else,#2\fi}}
\unexpanded\def\addtocommalist#1#2% {item} \cs
- {\rawdoifinsetelse{#1}#2\resetglobal
+ {\rawdoifelseinset{#1}#2\resetglobal
{\dodoglobal\edef#2{\ifx#2\empty\else#2,\fi#1}}}
\unexpanded\def\pretocommalist#1#2% {item} \cs
- {\rawdoifinsetelse{#1}#2\resetglobal
+ {\rawdoifelseinset{#1}#2\resetglobal
{\dodoglobal\edef#2{#1\ifx#2\empty\else,#2\fi}}}
-\unexpanded\def\robustdoifinsetelse#1#2%
+\unexpanded\def\robustdoifelseinset#1#2%
{\edef\m_syst_string_one{\detokenize\expandafter{\normalexpanded{#1}}}%
\edef\m_syst_string_two{\detokenize\expandafter{\normalexpanded{#2}}}%
- \rawdoifinsetelse\m_syst_string_one\m_syst_string_two}
+ \rawdoifelseinset\m_syst_string_one\m_syst_string_two}
+
+\let\robustdoifinsetelse\robustdoifelseinset
\unexpanded\def\robustaddtocommalist#1#2% {item} \cs
- {\robustdoifinsetelse{#1}#2\resetglobal
+ {\robustdoifelseinset{#1}#2\resetglobal
{\dodoglobal\edef#2{\ifx#2\empty\else#2,\fi#1}}}
\unexpanded\def\robustpretocommalist#1#2% {item} \cs
- {\robustdoifinsetelse{#1}#2\resetglobal
+ {\robustdoifelseinset{#1}#2\resetglobal
{\dodoglobal\edef#2{#1\ifx#2\empty\else,#2\fi}}}
\unexpanded\def\xsplitstring#1#2% \cs {str}
@@ -5038,7 +5147,7 @@
\def\acleanedupcommalist#1,,#2\relax{#1}
\unexpanded\def\removefromcommalist#1#2% to be sped up
- {\rawdoifinsetelse{#1}#2%
+ {\rawdoifelseinset{#1}#2%
{\normalexpanded{\xsplitstring\noexpand#2{#1}}%
\dodoglobal\edef#2%
{\ifx\m_syst_string_one\empty
@@ -5276,7 +5385,7 @@
\let\popmacro \localpopmacro
%D \macros
-%D {setlocalhsize}
+%D {setlocalhsize,distributedhsize}
%D
%D Sometimes we need to work with the \type{\hsize} that is
%D corrected for indentation and left and right skips. The
@@ -5295,7 +5404,7 @@
\newdimen\localhsize
\unexpanded\def\setlocalhsize % don't change !
- {\doifnextoptionalelse
+ {\doifelsenextoptional
\syst_helpers_set_local_hsize_yes
\syst_helpers_set_local_hsize_nop}
@@ -5314,6 +5423,12 @@
\fi
\relax}
+\def\distributedhsize#1#2#3%
+ {\dimexpr(#1-\numexpr#3-1\relax\dimexpr#2\relax)/#3\relax}
+
+\def\hsizefraction#1#2%
+ {\dimexpr#1/#2\relax}
+
%D \macros
%D {doifvalue,doifnotvalue,doifelsevalue,
%D doifnothing,doifsomething,doifelsenothing,
@@ -5376,7 +5491,7 @@
\expandafter\secondoftwoarguments
\fi}
-\unexpanded\def\doifsomethingelse#1%
+\unexpanded\def\doifelsesomething#1%
{\edef\m_syst_string_one{#1}%
\ifx\m_syst_string_one\empty
\expandafter\secondoftwoarguments
@@ -5408,18 +5523,25 @@
\expandafter\secondoftwoarguments
\fi}
+\let\doifvalueelse \doifelsevalue
+\let\doifnothingelse \doifelsenothing
+\let\doifsomethingelse \doifelsesomething
+\let\doifvaluenothingelse\doifelsevaluenothing
+
%D \macros
%D {doifemptyelsevalue, doifemptyvalue, doifnotemptyvalue}
%D
%D Also handy:
-\def\doifemptyelsevalue#1%
+\def\doifelseemptyvalue#1%
{\expandafter\ifx\csname#1\endcsname\empty
\expandafter\firstoftwoarguments
\else
\expandafter\secondoftwoarguments
\fi}
+\let\doifemptyvalueelse\doifelseemptyvalue
+
\def\doifemptyvalue#1%
{\expandafter\ifx\csname#1\endcsname\empty
\expandafter\firstofoneargument
@@ -5449,10 +5571,12 @@
\processcommalist[#3]\syst_helpers_do_common_check_all
\ifdone\expandafter#1\else\expandafter#2\fi}
-\unexpanded\def\doifallcommonelse{\syst_helpers_do_if_all_common_else\firstoftwoarguments\secondoftwoarguments}
+\unexpanded\def\doifelseallcommon{\syst_helpers_do_if_all_common_else\firstoftwoarguments\secondoftwoarguments}
\unexpanded\def\doifallcommon {\syst_helpers_do_if_all_common_else\firstofonearguments\gobbleoneargument }
\unexpanded\def\doifnotallcommon {\syst_helpers_do_if_all_common_else\gobbleoneargument \firstofonearguments }
+\let\doifallcommonelse\doifelseallcommon
+
%D \macros
%D {DOIF,DOIFELSE,DOIFNOT}
%D
@@ -5656,13 +5780,15 @@
\def\syst_helpers_if_some_space_else#1 #2#3\_e_o_s_{\if\noexpand#2@}
-\def\doifsomespaceelse#1% % #2#3%
+\def\doifelsesomespace#1% % #2#3%
{\syst_helpers_if_some_space_else#1 @ @\_e_o_s_ % #3\else#2\fi}
\expandafter\secondoftwoarguments
\else
\expandafter\firstoftwoarguments
\fi}
+\let\doifsomespaceelse\doifelsesomespace
+
%D \macros
%D {processseparatedlist}
%D
@@ -5912,11 +6038,11 @@
%D These macros are sort of obsolete as we never use uppercase this
%D way. But nevertheless we provide them:
-\def\utfupper#1{\ctxcommand{upper(\!!bs#1\!!es)}} % expandable
-\def\utflower#1{\ctxcommand{lower(\!!bs#1\!!es)}} % expandable
+\def\utfupper#1{\clf_upper{#1}} % expandable
+\def\utflower#1{\clf_lower{#1}} % expandable
-\unexpanded\def\uppercasestring#1\to#2{\dodoglobal\edef#2{\ctxcommand{upper(\!!bs#1\!!es)}}}
-\unexpanded\def\lowercasestring#1\to#2{\dodoglobal\edef#2{\ctxcommand{lower(\!!bs#1\!!es)}}}
+\unexpanded\def\uppercasestring#1\to#2{\dodoglobal\edef#2{\clf_upper{#1}}}
+\unexpanded\def\lowercasestring#1\to#2{\dodoglobal\edef#2{\clf_lower{#1}}}
%D \macros
%D {handletokens}
@@ -6112,24 +6238,20 @@
% \def\threedigitrounding#1%
% {\expandafter\expandafter\expandafter\dothreedigitrounding\expandafter\WITHOUTPT\the\dimexpr#1\points+.0005\points\relax0000.*00\relax}
-\def\integerrounding #1{\cldcontext{"\letterpercent 0.0f",#1}}
-\def\onedigitrounding #1{\cldcontext{"\letterpercent 0.1f",#1}}
-\def\twodigitrounding #1{\cldcontext{"\letterpercent 0.2f",#1}}
-\def\threedigitrounding#1{\cldcontext{"\letterpercent 0.3f",#1}}
+\def\integerrounding #1{\clf_rounded\zerocount\numexpr#1\relax}
+\def\onedigitrounding #1{\clf_rounded\plusone \numexpr#1\relax}
+\def\twodigitrounding #1{\clf_rounded\plustwo \numexpr#1\relax}
+\def\threedigitrounding#1{\clf_rounded\plusthree\numexpr#1\relax}
%D \macros
%D {processcontent}
%D
-%D This is the first occasion where \TEX\ and \ETEX\ are no
-%D longer compatible, although in many cases things go ok.
-%D Beware of verbatim, i.e. catcode changes.
+%D This macro is first used in the tabulation macros.
%D
%D \starttyping
%D \unexpanded\def\starthans%
%D {\processcontent{stophans}\test{\message{\test}\wait}}
%D \stoptyping
-%D
-%D This macro is first used in the tabulation macros.
\unexpanded\def\processcontent#1%
{\begingroup\expandafter\syst_helpers_process_content\csname#1\endcsname}
@@ -6195,7 +6317,7 @@
%D Not that fast I guess, but here's a way to test for token
%D registers being empty.
-\unexpanded\def\doifsometokselse#1%
+\unexpanded\def\doifelsesometoks#1%
{\edef\m_syst_string_one{\the#1}% one level expansion so quite ok
\ifx\m_syst_string_one\empty
\expandafter\secondoftwoarguments
@@ -6203,6 +6325,8 @@
\expandafter\firstoftwoarguments
\fi}
+\let\doifsometokselse\doifelsesometoks
+
\unexpanded\def\doifsometoks#1%
{\edef\m_syst_string_one{\the#1}% one level expansion so quite ok
\ifx\m_syst_string_one\empty
@@ -6241,9 +6365,11 @@
\unexpanded\def\stopstrictinspectnextcharacter
{\let\syst_helpers_inspect_next_character\syst_helpers_normal_inspect_next_character}
-\def\strictdoifnextoptionalelse#1#2%
+\unexpanded\def\strictdoifelsenextoptional#1#2%
{\startstrictinspectnextcharacter
- \doifnextcharelse[{\stopstrictinspectnextcharacter#1}{\stopstrictinspectnextcharacter#2}}
+ \doifelsenextchar[{\stopstrictinspectnextcharacter#1}{\stopstrictinspectnextcharacter#2}}
+
+\let\strictdoifnextoptionalelse\strictdoifelsenextoptional
%D \macros
%D {gobblespacetokens}
@@ -6436,9 +6562,11 @@
%D
%D This is a dirty one: we simply append a unit and discard it when needed.
-\def\doifdimensionelse#1%
+\def\doifelsedimension#1%
{\afterassignment\syst_helpers_if_dimension_else\scratchdimen#1pt\relax}
+\let\doifdimensionelse\doifelsedimension
+
\def\syst_helpers_if_dimension_else#1%
{\ifx#1\relax
\expandafter\secondoftwoarguments
@@ -6467,7 +6595,9 @@
\installsystemnamespace{dimencheckb}
\installsystemnamespace{dimencheckc}
-\def\doifdimenstringelse#1{\normalexpanded{\noexpand\dodimenteststageone#1}\empty\empty]}
+\def\doifelsedimenstring#1{\normalexpanded{\noexpand\dodimenteststageone#1}\empty\empty]}
+
+\let\doifdimenstringelse\doifelsedimenstring
\def\dodimenteststageone #1#2{\csname \??dimenchecka\ifcsname \??dimenchecka#2\endcsname#2\else x\fi\endcsname#2}
\def\dodimenteststagetwo #1#2{\csname \??dimencheckb\ifcsname \??dimencheckb#2\endcsname#2\else x\fi\endcsname#2}
@@ -6590,10 +6720,12 @@
% sometimes handy:
-\unexpanded\def\doifhasspaceelse#1%
+\unexpanded\def\doifelsehasspace#1%
{\edef\m_syst_string_one{#1}%
\normalexpanded{\syst_helpers_if_has_space_else#1\space}\empty\relax}
+\let\doifhasspaceelse\doifelsehasspace
+
\unexpanded\def\syst_helpers_if_has_space_else#1 #2#3\relax % \space\empty\relax
{\ifx\m_syst_string_one\space
\expandafter\firstoftwoarguments
@@ -6602,7 +6734,7 @@
\else
\doubleexpandafter\firstoftwoarguments
\fi\fi}
-
+
% this will replace loadfile once and alike !!! todo
\installsystemnamespace{flag}
@@ -6621,6 +6753,8 @@
\doubleexpandafter\secondoftwoarguments
\fi\fi}
+\let\doifflaggedelse\doifelseflagged
+
\def\doifnotflagged#1%
{\expandafter\ifx\csname\??flag#1\endcsname\relax
\expandafter\firstofoneargument
@@ -6629,10 +6763,10 @@
\else
\doubleexpandafter\firstofoneargument
\fi\fi}
-
+
\unexpanded\def\inheritparameter[#1]#2[#3]#4[#5]% tag tokey fromkey
{\expandafter\def\csname#1#3\expandafter\endcsname\expandafter{\csname#1#5\endcsname}}
-
+
\def\syst_helpers_if_non_zero_positive_else#1#2\end % #3#4%
{\ifx#1\relax
\ifcase\scratchcounter
@@ -6647,9 +6781,11 @@
\expandafter\secondoftwoarguments
\fi}
-\def\doifnonzeropositiveelse#1%
+\def\doifelsenonzeropositive#1%
{\begingroup\afterassignment\syst_helpers_if_non_zero_positive_else\scratchcounter=0#1\relax\empty\end}
-
+
+\let\doifnonzeropositiveelse\doifelsenonzeropositive
+
% here ?
\unexpanded\def\dosetrawvalue #1#2#3{\expandafter \def\csname#1#2\endcsname{#3}}
@@ -6693,8 +6829,8 @@
% \fi
% \def\elapsedseconds{\expandafter\withoutpt\the\dimexpr\elapsedtime sp\relax}
-\def\resettimer {\ctxcommand{resettimer()}}
-\def\elapsedtime {\ctxcommand{elapsedtime()}}
+\let\resettimer \clf_resettimer
+\let\elapsedtime \clf_elapsedtime
\let\elapsedseconds \elapsedtime
\newcount\c_syst_helpers_test_feature_n
@@ -6808,7 +6944,7 @@
%D \typebuffer \getbuffer
\unexpanded\def\ignoreimplicitspaces
- {\doifnextcharelse\relax\relax\relax}
+ {\doifelsenextchar\relax\relax\relax}
%D \macros
%D {processwords}
@@ -6871,7 +7007,7 @@
\def\syst_helpers_direct_double_empty_one_nop#1{#1[][]}
\def\syst_helpers_direct_double_empty_two_nop#1[#2]{#1[#2][]}
-%D Used in math definitions (in an type {\edef}):
+%D Used in math definitions (in an \type {\edef}):
%D \startbuffer
%D [\docheckedpair{}]
@@ -6985,8 +7121,80 @@
% expandable:
-%def\getsubstring#1#2#3{\cldcontext{utf.sub([[#3]],tonumber("#1"),tonumber("#2"))}}
-\def\getsubstring#1#2#3{\ctxcommand{getsubstring(\!!bs#3\!!es,"#1","#2")}}
+\def\getsubstring#1#2#3{\clf_getsubstring{#3}{#1}{#2}}
+
+%D Other dimensions than pt (used in mb-mp)
+
+\def\converteddimen#1#2{\clf_converteddimen\dimexpr#1\relax{#2}}
+
+%D Maybe (looks ugly):
+%D
+%D \starttyping
+%D \doifcase {foo}
+%D {bar} {BAR}
+%D {foo} {FOO}
+%D {default} {DEFAULT}
+%D
+%D \doifcase {foo}
+%D {bar} {BAR}
+%D {foo} {\doifcase {bar}
+%D {bar} {BAR}
+%D {foo} {FOO}
+%D {default} {DEFAULT}
+%D }
+%D {default} {DEFAULT}
+%D \stoptyping
+
+% \doifcase {\btxfoundname{author}}
+% {author} {\btxflush{author}}
+% {editor} {\texdefinition{btx:apa:editor-or-editors}}
+% {title} {\texdefinition{btx:apa:title-subtitle-type}}
+% {default} {\btxflush{author}}
+
+% \unexpanded\def\doifcase#1%
+% {\edef\m_case_asked{#1}%
+% \syst_aux_case}
+%
+% \def\syst_aux_case#1%
+% {\edef\m_case_temp{#1}%
+% \ifx\m_case_temp\m_case_asked
+% \expandafter\syst_aux_case_yes
+% \else\ifx\m_case_temp\s!default
+% \doubleexpandafter\firstofoneargument
+% \else
+% \doubleexpandafter\syst_aux_case_nop
+% \fi\fi}
+%
+% \def\syst_aux_skip#1#2%
+% {\edef\m_case_temp{#1}%
+% \ifx\m_case_temp\s!default
+% \expandafter\syst_aux_done
+% \else
+% \expandafter\syst_aux_skip
+% \fi}
+%
+% \def\syst_aux_case_yes#1%
+% {\def\syst_aux_done{#1}%
+% \syst_aux_skip}
+%
+% \def\syst_aux_case_nop#1%
+% {\syst_aux_case}
+
+%D \macros
+%D {ntimes}
+%D
+%D some repetition:
+%D
+%D \startbuffer
+%D \ntimes{*}{20}
+%D \stopbuffer
+%D
+%D \typebuffer \blank gives: \getbuffer \blank
+%D
+%D This is not real fast but quite okay:
+
+%def\ntimes#1#2{\ifnum#2>\zerocount#1\ntimes{#1}{\numexpr#2-\plusone\relax}\fi} % 1.72
+\def\ntimes#1#2{\clf_ntimes{#1}\numexpr#2\relax} % 0.33
\protect \endinput