diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/syst-aux.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/syst-aux.mkiv | 3670 |
1 files changed, 1718 insertions, 1952 deletions
diff --git a/Master/texmf-dist/tex/context/base/syst-aux.mkiv b/Master/texmf-dist/tex/context/base/syst-aux.mkiv index 0e43a6202bd..a5551b954d9 100644 --- a/Master/texmf-dist/tex/context/base/syst-aux.mkiv +++ b/Master/texmf-dist/tex/context/base/syst-aux.mkiv @@ -11,10 +11,6 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -%D Some of the macros will move to syst-obs as they might become -%D obsolete once we've redone the bibliography module. Of course -%D the handy helpers will stay. -%D %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 @@ -38,13 +34,13 @@ %D is used in \CONTEXT\ and therefore we might also assume that %D some basic functionality is available. %D -%D Some of the macros here are used in the bibliography module. They -%D will be moved to a separate syst module some once the bib module -%D is made \MKIV. -%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. + \unprotect %D \macros @@ -62,6 +58,36 @@ \let\unexpanded\normalprotected +% %D \macros +% %D {expunded} +% %D +% %D \unexpanded\edef\TestA{zzz} +% %D \edef\TestB{zzz} +% %D +% %D \doifelse {\TestA} {\TestB} {WRONG} {OKAY} \par +% %D \doifelse {\TestA} {\expunded\TestB} {WRONG} {OKAY} \par +% %D \doifelse {\expunded\TestA} {\TestB} {OKAY} {WRONG} \par +% %D \doifelse {\expunded\TestA} {\expunded\TestB} {OKAY} {WRONG} \par + +% %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 + +\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 + +\unexpanded\def\installsystemnamespace#1% maybe move this to syst-ini + {\ifcsname ??#1\endcsname + \writestatus\m!system{duplicate system namespace '#1'}\wait + \else + \global\advance\c_syst_helpers_n_of_namespaces\plusone + \expandafter\edef\csname ??#1\endcsname{\v_interfaces_prefix_template_system}% + \fi} + %D \macros %D {normalspace} %D @@ -150,34 +176,35 @@ \let\@NX \noexpand \def\@EAEA {\expandafter\expandafter} % can often be avoided -%D Sometimes we pass macros as arguments to commands that -%D don't expand them before interpretation. Such commands can -%D be enclosed with \type{\expanded}, like: +%D Sometimes we pass macros as arguments to commands that don't expand them +%D before interpretation. Such commands can be enclosed with \type {\expanded}, +%D like: %D %D \starttyping %D \expanded{\setupsomething[\alfa]} %D \stoptyping %D -%D Such situations occur for instance when \type{\alfa} is a -%D commalist or when data stored in macros is fed to index of -%D list commands. If needed, one should use \type{\noexpand} -%D inside the argument. Later on we will meet some more clever -%D alternatives to this command. Beware, only the simple one -%D has \type {\noexpand} before its argument. +%D Such situations occur for instance when \type{\alfa} is a commalist or when data +%D stored in macros is fed to index of list commands. If needed, one should use +%D \type{\noexpand} inside the argument. Later on we will meet some more clever +%D alternatives to this command. Beware, only the simple one has \type {\noexpand} +%D before its argument. -\let\@@expanded\empty % always long and global (less restores) +\let\m_syst_helpers_expanded\empty \unexpanded\def\expanded#1% - {\xdef\@@expanded{\noexpand#1}\@@expanded} + {\xdef\m_syst_helpers_expanded{\noexpand#1}\m_syst_helpers_expanded} -\unexpanded\def\startexpanded#1\stopexpanded % see x-fo for example - {\xdef\@@expanded{#1}\@@expanded} +\unexpanded\def\startexpanded#1\stopexpanded + {\xdef\m_syst_helpers_expanded{#1}\m_syst_helpers_expanded} \let\stopexpanded\relax -%D Recent \TEX's have a primitive \expanded +%D Recent \TEX\ engines have a primitive \type {\expanded} and we will use that when +%D possible. After all, we can make not expandable macros now. -% not yet as we need to adapt ##'s in calls +% We cannot use the next variant as first we need to adapt \type {##}'s +% in callers: % % \def\expanded#1% % {\normalexpanded{\noexpand#1}} @@ -188,8 +215,8 @@ %D \macros %D {gobbleoneargument,gobble...arguments} %D -%D The next set of macros just do nothing, except that they -%D get rid of a number of arguments. +%D The next set of macros just do nothing, except that they get rid of a number of +%D arguments. \def\gobbleoneargument #1{} \def\gobbletwoarguments #1#2{} @@ -208,6 +235,18 @@ \def\gobblefouroptionals [#1][#2][#3][#4]{} \def\gobblefiveoptionals [#1][#2][#3][#4][#5]{} +%D Reserved macros for tests: + +\let\donothing\empty + +\let\m_syst_string_one \empty +\let\m_syst_string_two \empty +\let\m_syst_string_three\empty +\let\m_syst_string_four \empty + +\let\m_syst_action_yes \empty +\let\m_syst_action_nop \empty + %D \macros %D {doifnextcharelse} %D @@ -235,8 +274,8 @@ \unexpanded\def\doifnextcharelse#1#2#3% #1 should not be {} ! {\let\charactertoken=#1% = needed here - \def\!!stringa{#2}% - \def\!!stringb{#3}% + \def\m_syst_action_yes{#2}% + \def\m_syst_action_nop{#3}% \futurelet\nexttoken\syst_helpers_inspect_next_character} \def\syst_helpers_inspect_next_character @@ -248,9 +287,9 @@ \def\syst_helpers_inspect_next_character_indeed {\ifx\nexttoken\charactertoken - \expandafter\!!stringa + \expandafter\m_syst_action_yes \else - \expandafter\!!stringb + \expandafter\m_syst_action_nop \fi} %D Because we will mostly use this macro for testing if the next @@ -274,14 +313,14 @@ \let\syst_helpers_next_optional_character_token=[ \unexpanded\def\doifnextoptionalelse#1#2% - {\def\syst_helpers_next_optional_command_yes{#1}% - \def\syst_helpers_next_optional_command_nop{#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) - {\let\syst_helpers_next_optional_command_yes#1% - \let\syst_helpers_next_optional_command_nop#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_optional_character} @@ -294,16 +333,16 @@ \def\syst_helpers_inspect_next_optional_character_indeed {\ifx\nexttoken\syst_helpers_next_optional_character_token - \expandafter\syst_helpers_next_optional_command_yes + \expandafter\m_syst_action_yes \else - \expandafter\syst_helpers_next_optional_command_nop + \expandafter\m_syst_action_nop \fi} \let\syst_helpers_next_bgroup_character_token\bgroup \unexpanded\def\doifnextbgroupelse#1#2% - {\def\syst_helpers_next_bgroup_command_yes{#1}% - \def\syst_helpers_next_bgroup_command_nop{#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} @@ -316,16 +355,16 @@ \def\syst_helpers_inspect_next_bgroup_character_indeed {\ifx\nexttoken\syst_helpers_next_bgroup_character_token - \expandafter\syst_helpers_next_bgroup_command_yes + \expandafter\m_syst_action_yes \else - \expandafter\syst_helpers_next_bgroup_command_nop + \expandafter\m_syst_action_nop \fi} \let\syst_helpers_next_parenthesis_character_token( \unexpanded\def\doifnextparenthesiselse#1#2% - {\def\syst_helpers_next_parenthesis_command_yes{#1}% - \def\syst_helpers_next_parenthesis_command_nop{#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} @@ -338,44 +377,39 @@ \def\syst_helpers_inspect_next_parenthesis_character_indeed {\ifx\nexttoken\syst_helpers_next_parenthesis_character_token - \expandafter\syst_helpers_next_parenthesis_command_yes + \expandafter\m_syst_action_yes \else - \expandafter\syst_helpers_next_parenthesis_command_nop + \expandafter\m_syst_action_nop \fi} %D The next one is handy in predictable situations: \unexpanded\def\doiffastoptionalcheckelse#1#2% - {\def\syst_helpers_next_optional_command_yes{#1}% - \def\syst_helpers_next_optional_command_nop{#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 - {\let\syst_helpers_next_optional_command_yes#1% - \let\syst_helpers_next_optional_command_nop#2% + {\let\m_syst_action_yes#1% + \let\m_syst_action_nop#2% \futurelet\nexttoken\syst_helpers_do_if_fast_optional_check_else} \def\syst_helpers_do_if_fast_optional_check_else {\ifx\nexttoken\syst_helpers_next_optional_character_token - \expandafter\syst_helpers_next_optional_command_yes + \expandafter\m_syst_action_yes \else - \expandafter\syst_helpers_next_optional_command_nop + \expandafter\m_syst_action_nop \fi} -%D This macro uses some auxiliary macros. Although we were able -%D to program quite complicated things, I only understood these -%D after rereading the \TEX book. The trick is in using a -%D command with a one character name. Such commands differ from -%D the longer ones in the fact that trailing spaces are {\em -%D not} skipped. This enables us to indirectly define a long -%D named macro that gobbles a space. -%D -%D In the first line we define \type{\blankspace}. Next we -%D make \type{\:} equivalent to \type{\reinspect...}. This -%D one||character command is expanded before the next -%D \type{\def} comes into action. This way the space after -%D \type{\:} becomes a delimiter of the longer named -%D \type{\reinspectnextcharacter}. +%D This macro uses some auxiliary macros. Although we were able to program quite +%D complicated things, I only understood these after rereading the \TEX book. The +%D trick is in using a command with a one character name. Such commands differ from +%D the longer ones in the fact that trailing spaces are {\em not} skipped. This +%D enables us to indirectly define a long named macro that gobbles a space. In the +%D first line we define \type {\blankspace}. Next we make \type {\:} equivalent to +%D \type {\reinspect...}. This one||character command is expanded before the next +%D \type {\def} comes into action. This way the space after \type {\:} becomes a +%D delimiter of the longer named \type {\reinspectnextcharacter}. % try: \expandafter\def\firstofoneargument{\syst_helpers_reinspect_next_character} {...} @@ -402,10 +436,9 @@ %D letvalue,letgvalue,getvalue,resetvalue, %D undefinevalue,ignorevalue} %D -%D \TEX's primitive \type{\csname} can be used to construct -%D all kind of commands that cannot be defined with -%D \type{\def} and \type{\let}. Every macro programmer sooner -%D or later wants macros like these. +%D \TEX's primitive \type {\csname} can be used to construct all kind of commands +%D that cannot be defined with \type {\def} and \type {\let}. Every macro programmer +%D sooner or later wants macros like these. %D %D \starttyping %D \setvalue {name}{...} = \def\name{...} @@ -418,9 +451,8 @@ %D \resetvalue {name} = \def\name{} %D \stoptyping %D -%D As we will see, \CONTEXT\ uses these commands many times, -%D which is mainly due to its object oriented and parameter -%D driven character. +%D As we will see, \CONTEXT\ uses these commands many times, which is mainly due to +%D its object oriented and parameter driven character. \def\setvalue #1{\expandafter \def\csname#1\endcsname} \def\setgvalue #1{\expandafter\gdef\csname#1\endcsname} @@ -441,22 +473,20 @@ %D \macros %D {globallet,glet} %D -%D In \CONTEXT\ of May 2000 using \type {\globallet} -%D instead of the two tokens will save us some -%D $300\times4=1200$ bytes of format file on a 32~bit -%D system. So: +%D In \CONTEXT\ of May 2000 using \type {\globallet} instead of the two +%D tokens will save us some $300\times4=1200$ bytes of format file on a 32~bit +%D system. Not that it matters much today. This shortcut is already defined: -\def\globallet{\global\let} \let\glet\globallet +\unexpanded\def\glet{\global\let} \let\globallet\glet %D \macros %D {doifundefined,doifdefined, %D doifundefinedelse,doifdefinedelse, %D doifalldefinedelse} %D -%D The standard way of testing if a macro is defined is -%D comparing its meaning with another undefined one, usually -%D \type{\undefined}. To garantee correct working of the next -%D set of macros, \type{\undefined} may never be defined! +%D The standard way of testing if a macro is defined is comparing its meaning with +%D another undefined one, usually \type{\undefined}. To garantee correct working of +%D the next set of macros, \type{\undefined} may never be defined! %D %D \starttyping %D \doifundefined {string} {...} @@ -466,13 +496,12 @@ %D \doifalldefinedelse {commalist} {then ...} {else ...} %D \stoptyping %D -%D Every macroname that \TEX\ builds gets an entry in the hash -%D table, which is of limited size. It is expected that e-\TeX\ -%D will offer a less memory||consuming alternative. +%D Every macroname that \TEX\ builds gets an entry in the hash table, which is of +%D limited size. It is expected that \ETEX\ will offer a less memory||consuming +%D alternative. -%D Although it will probably never be a big problem, it is good -%D to be aware of the difference between testing on a macro -%D name to be build by using \type{\csname} and +%D Although it will probably never be a big problem, it is good to be aware of the +%D difference between testing on a macro name to be build by using \type{\csname} and %D \type{\endcsname} and testing the \type{\name} directly. %D %D \starttyping @@ -481,11 +510,6 @@ %D \ifundefined\NameB ... \else ... \fi %D \stoptyping -% \def\ifundefined#1% obsolete -% {\unless\ifcsname#1\endcsname} -% -% use a real if like \ifcsname#1\endcsname\else instead - \suppressifcsnameerror\plusone \def\doifundefinedelse#1% @@ -511,12 +535,10 @@ %D \macros %D {letbeundefined} %D -%D Testing for being undefined comes down to testing on \type -%D {\relax} when we use \type {\csname}, but when using \type -%D {\ifx}, we test on being \type {\undefined}! In \ETEX\ we -%D have \type {\ifcsname} and that way of testing on existance -%D is not the same as the one described here. Therefore we -%D introduce: +%D Testing for being undefined comes down to testing on \type {\relax} when we use +%D \type {\csname}, but when using \type {\ifx}, we test on being \type +%D {\undefined}! In \ETEX\ we have \type {\ifcsname} and that way of testing on +%D existance is not the same as the one described here. Therefore we introduce: \def\letbeundefined#1% potential stack buildup when used \global {\expandafter\let\csname#1\endcsname\undefined} @@ -527,13 +549,11 @@ \def\globalundefine#1% conditional {\ifcsname#1\endcsname\expandafter\global\let\csname#1\endcsname\undefined\fi} -%D Beware, being \type {\undefined} in \ETEX\ means that the macro -%D {\em is} defined! - -%D When we were developing the scientific units module, we -%D encountered different behavior in text and math mode, which -%D was due to this grouping subtilities. We therefore decided -%D to use \type{\begingroup} instead of \type{\bgroup}. +%D Beware, being \type {\undefined} in \ETEX\ means that the macro {\em is} defined! +%D +%D When we were developing the scientific units module, we encountered different +%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% {\begingroup @@ -554,15 +574,13 @@ %D \macros %D {doif,doifelse,doifnot} %D -%D Programming in \TEX\ differs from programming in procedural -%D languages like \MODULA. This means that one --- well, let me -%D speek for myself --- tries to do the things in the well -%D known way. Therefore the next set of \type{\ifthenelse} -%D commands were between the first ones we needed. A few years -%D later, the opposite became true: when programming in -%D \MODULA, I sometimes miss handy things like grouping, -%D runtime redefinition, expansion etc. While \MODULA\ taught -%D me to structure, \TEX\ taught me to think recursive. +%D Programming in \TEX\ differs from programming in procedural languages like +%D \MODULA. This means that one --- well, let me speek for myself --- tries to do +%D the things in the well known way. Therefore the next set of \type{\ifthenelse} +%D commands were between the first ones we needed. A few years later, the opposite +%D became true: when programming in \MODULA, I sometimes miss handy things like +%D grouping, runtime redefinition, expansion etc. While \MODULA\ taught me to +%D structure, \TEX\ taught me to think recursive. %D %D \starttyping %D \doif {string1} {string2} {...} @@ -571,27 +589,27 @@ %D \stoptyping \unexpanded\def\doif#1#2% - {\edef\!!stringa{#1}% - \edef\!!stringb{#2}% - \ifx\!!stringa\!!stringb + {\edef\m_syst_string_one{#1}% + \edef\m_syst_string_two{#2}% + \ifx\m_syst_string_one\m_syst_string_two \expandafter\firstofoneargument \else \expandafter\gobbleoneargument \fi} \unexpanded\def\doifnot#1#2% - {\edef\!!stringa{#1}% - \edef\!!stringb{#2}% - \ifx\!!stringa\!!stringb + {\edef\m_syst_string_one{#1}% + \edef\m_syst_string_two{#2}% + \ifx\m_syst_string_one\m_syst_string_two \expandafter\gobbleoneargument \else \expandafter\firstofoneargument \fi} \unexpanded\def\doifelse#1#2% - {\edef\!!stringa{#1}% - \edef\!!stringb{#2}% - \ifx\!!stringa\!!stringb + {\edef\m_syst_string_one{#1}% + \edef\m_syst_string_two{#2}% + \ifx\m_syst_string_one\m_syst_string_two \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments @@ -611,24 +629,24 @@ %D This time, the string is not expanded. \unexpanded\def\doifemptyelse#1% - {\def\!!stringa{#1}% - \ifx\!!stringa\empty + {\def\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments \fi} \unexpanded\def\doifempty#1% - {\def\!!stringa{#1}% - \ifx\!!stringa\empty + {\def\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\firstofoneargument \else \expandafter\gobbleoneargument \fi} \unexpanded\def\doifnotempty#1% - {\def\!!stringa{#1}% - \ifx\!!stringa\empty + {\def\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\gobbleoneargument \else \expandafter\firstofoneargument @@ -637,9 +655,8 @@ %D \macros %D {doifinset,doifnotinset,doifinsetelse} %D -%D We can check if a string is present in a comma separated -%D set of strings. Depending on the result, some action is -%D taken. +%D We can check if a string is present in a comma separated set of strings. +%D Depending on the result, some action is taken. %D %D \starttyping %D \doifinset {string} {string,...} {...} @@ -680,119 +697,119 @@ \def\syst_helpers_do_quit_if_item_in_set #1],\relax{\firstofoneargument} \def\syst_helpers_do_quit_if_item_not_in_set #1],\relax{\gobbleoneargument} -\def\syst_helpers_re_do_if_in_set_else{\expandafter\syst_helpers_do_check_if_item_in_set_else\!!stringb,],\relax} -\def\syst_helpers_re_do_if_in_set {\expandafter\syst_helpers_do_check_if_item_in_set \!!stringb,],\relax} -\def\syst_helpers_re_do_if_not_in_set {\expandafter\syst_helpers_do_check_if_item_not_in_set \!!stringb,],\relax} +\def\syst_helpers_re_do_if_in_set_else{\expandafter\syst_helpers_do_check_if_item_in_set_else\m_syst_string_two,],\relax} +\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 - {\edef\!!stringa{#1}% - \ifx\!!stringa\empty + {\edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\thirdofthreearguments \else \expandafter\syst_helpers_do_if_in_set_else \fi} \def\syst_helpers_do_if_in_set_else#1% - {\edef\!!stringb{#1}% - \ifx\!!stringb\empty + {\edef\m_syst_string_two{#1}% + \ifx\m_syst_string_two\empty \expandafter\secondoftwoarguments \else \expandafter\syst_helpers_re_do_if_in_set_else \fi} \unexpanded\def\doifinset#1% - {\edef\!!stringa{#1}% - \ifx\!!stringa\empty + {\edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\gobbletwoarguments \else \expandafter\syst_helpers_do_if_in_set \fi} \def\syst_helpers_do_if_in_set#1% - {\edef\!!stringb{#1}% - \ifx\!!stringb\empty + {\edef\m_syst_string_two{#1}% + \ifx\m_syst_string_two\empty \expandafter\gobbleoneargument \else \expandafter\syst_helpers_re_do_if_in_set \fi} \unexpanded\def\doifnotinset#1% - {\edef\!!stringa{#1}% - \ifx\!!stringa\empty + {\edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\secondoftwoarguments \else \expandafter\syst_helpers_do_if_not_in_set \fi} \def\syst_helpers_do_if_not_in_set#1% - {\edef\!!stringb{#1}% - \ifx\!!stringb\empty + {\edef\m_syst_string_two{#1}% + \ifx\m_syst_string_two\empty \expandafter\firstofoneargument \else \expandafter\syst_helpers_re_do_if_not_in_set % ...]{true} \fi} \def\syst_helpers_do_check_if_item_in_set_else#1,#2% #2 eats up preceding space - {\edef\!!stringb{#1}% - \ifx\!!stringb\empty + {\edef\m_syst_string_two{#1}% + \ifx\m_syst_string_two\empty \expandafter\syst_helpers_do_check_if_item_in_set_else \else \expandafter\syst_helpers_do_do_check_if_item_in_set_else \fi#2} \def\syst_helpers_do_do_check_if_item_in_set_else - {\ifx\!!stringb\v_syst_helpers_right_optional_bracket + {\ifx\m_syst_string_two\v_syst_helpers_right_optional_bracket \expandafter\thirdofthreearguments \else \expandafter\syst_helpers_do_do_do_check_if_item_in_set_else \fi} \def\syst_helpers_do_do_do_check_if_item_in_set_else - {\ifx\!!stringa\!!stringb + {\ifx\m_syst_string_one\m_syst_string_two \expandafter\syst_helpers_do_quit_if_item_in_set_else \else \expandafter\syst_helpers_do_check_if_item_in_set_else \fi} \def\syst_helpers_do_check_if_item_in_set#1,#2% #2 eats up preceding space - {\edef\!!stringb{#1}% - \ifx\!!stringb\empty + {\edef\m_syst_string_two{#1}% + \ifx\m_syst_string_two\empty \expandafter\syst_helpers_do_check_if_item_in_set \else \expandafter\syst_helpers_do_do_check_if_item_in_set \fi#2} \def\syst_helpers_do_do_check_if_item_in_set - {\ifx\!!stringb\v_syst_helpers_right_optional_bracket + {\ifx\m_syst_string_two\v_syst_helpers_right_optional_bracket \expandafter\gobbletwoarguments \else \expandafter\syst_helpers_do_do_do_check_if_item_in_set \fi} \def\syst_helpers_do_do_do_check_if_item_in_set - {\ifx\!!stringa\!!stringb + {\ifx\m_syst_string_one\m_syst_string_two \expandafter\syst_helpers_do_quit_if_item_in_set \else \expandafter\syst_helpers_do_check_if_item_in_set \fi} \def\syst_helpers_do_check_if_item_not_in_set#1,#2% #2 eats up preceding space - {\edef\!!stringb{#1}% - \ifx\!!stringb\empty + {\edef\m_syst_string_two{#1}% + \ifx\m_syst_string_two\empty \expandafter\syst_helpers_do_check_if_item_not_in_set \else \expandafter\syst_helpers_do_do_check_if_item_not_in_set \fi#2} \def\syst_helpers_do_do_check_if_item_not_in_set - {\ifx\!!stringb\v_syst_helpers_right_optional_bracket + {\ifx\m_syst_string_two\v_syst_helpers_right_optional_bracket \expandafter\secondoftwoarguments \else \expandafter\syst_helpers_do_do_do_check_if_item_not_in_set \fi} \def\syst_helpers_do_do_do_check_if_item_not_in_set - {\ifx\!!stringa\!!stringb + {\ifx\m_syst_string_one\m_syst_string_two \expandafter\syst_helpers_do_quit_if_item_not_in_set \else \expandafter\syst_helpers_do_check_if_item_not_in_set @@ -801,8 +818,8 @@ %D \macros %D {doifcommon,doifnotcommon,doifcommonelse} %D -%D Probably the most time consuming tests are those that test -%D for overlap in sets of strings. +%D Probably the most time consuming tests are those that test for overlap in sets +%D of strings. %D %D \starttyping %D \doifcommon {string,...} {string,...} {...} @@ -890,16 +907,16 @@ %D {processcommalist,processcommacommand,quitcommalist, %D processcommalistwithparameters} %D -%D We've already seen some macros that take care of comma -%D separated lists. Such list can be processed with +%D We've already seen some macros that take care of comma separated lists. Such +%D list can be processed with %D %D \starttyping %D \processcommalist[string,string,...]\commando %D \stoptyping %D -%D The user supplied command \type{\commando} receives one -%D argument: the string. This command permits nesting and -%D spaces after commas are skipped. Empty sets are no problem. +%D The user supplied command \type{\commando} receives one argument: the string. +%D This command permits nesting and spaces after commas are skipped. Empty sets +%D are no problem. %D %D \startbuffer %D \def\dosomething#1{(#1)} @@ -920,8 +937,10 @@ \newcount\commalevel +\installsystemnamespace{nextcommalevel} + \def\syst_helpers_do_do_do_process_comma_item - {\csname\s!next\the\commalevel\endcsname} + {\csname\??nextcommalevel\the\commalevel\endcsname} \def\syst_helpers_do_do_process_comma_item {\ifx\nexttoken\blankspace @@ -940,9 +959,8 @@ \def\syst_helpers_do_process_comma_item {\futurelet\nexttoken\syst_helpers_do_do_process_comma_item} -%D Empty arguments are not processed. Empty items (\type{,,}) -%D however are treated. We have to check for the special case -%D \type{[{a,b,c}]}. +%D Empty arguments are not processed. Empty items (\type {,,}) however are +%D treated. We have to check for the special case \type {[{a,b,c}]}. \unexpanded\def\processcommalist[% {\futurelet\nexttoken\syst_helpers_do_check_comma_item} @@ -957,27 +975,27 @@ \def\syst_helpers_do_process_comma_list#1]#2% {\global\advance\commalevel \plusone - \expandafter\def\csname\s!next\the\commalevel\endcsname##1,% + \expandafter\def\csname\??nextcommalevel\the\commalevel\endcsname##1,% {#2{##1}\syst_helpers_do_process_comma_item}% \expandafter\syst_helpers_do_do_process_comma_item\gobbleoneargument#1,]\relax \global\advance\commalevel \minusone } %D One way of quitting a commalist halfway is: -\def\quitcommalist +\unexpanded\def\quitcommalist {\begingroup\let\syst_helpers_do_process_comma_item\syst_helpers_do_quit_comma_list} \def\syst_helpers_do_quit_comma_list#1]% {\endgroup} -\def\quitprevcommalist +\unexpanded\def\quitprevcommalist {\begingroup\let\syst_helpers_do_process_comma_item\syst_helpers_do_quit_prev_comma_list} \def\syst_helpers_do_quit_prev_comma_list#1]% {\let\syst_helpers_do_process_comma_item\syst_helpers_do_quit_comma_list} -%D The hack we used for checking the next character -%D \type {\doifnextcharelse} is also used here. +%D The hack we used for checking the next character \type {\doifnextcharelse} +%D is also used here. \let\next\: @@ -991,15 +1009,13 @@ %D %D \getbuffer -%D When a list is saved in a macro, we can use a construction -%D like: +%D When a list is saved in a macro, we can use a construction like: %D %D \starttyping %D \expandafter\processcommalist\expandafter[\list]\command %D \stoptyping %D -%D Such solutions suit most situations, but we wanted a bit -%D more. +%D Such solutions suit most situations, but we wanted a bit more. %D %D \starttyping %D \processcommacommand[string,\stringset,string]\commando @@ -1016,14 +1032,14 @@ %D \processcommacommand[\first,between,\second]\message %D \stoptyping %D -%D Commands that are part of the list are expanded, so the -%D use of this macro has its limits. +%D Commands that are part of the list are expanded, so the use of +%D this macro has its limits. \unexpanded\def\processcommacommand[#1]% {\normalexpanded{\processcommalist[#1]}} -%D The argument to \type{\command} is not delimited. Because -%D we often use \type{[]} as delimiters, we also have: +%D The argument to \type{\command} is not delimited. Because we often +%D use \type{[]} as delimiters, we also have: %D %D \starttyping %D \processcommalistwithparameters[string,string,...]\command @@ -1044,13 +1060,18 @@ %D %D Two more: +\let\syst_helpers_comma_list_step\relax + \unexpanded\def\startprocesscommalist[#1]#2\stopprocesscommalist - {\def\currentcommalistcommand##1{\def\currentcommalistitem{##1}#2}% - \processcommalist[#1]\currentcommalistcommand} + {\def\syst_helpers_comma_list_step##1{\def\currentcommalistitem{##1}#2}% + \processcommalist[#1]\syst_helpers_comma_list_step} \unexpanded\def\startprocesscommacommand[#1]#2\stopprocesscommacommand - {\def\currentcommalistcommand##1{\def\currentcommalistitem{##1}#2}% - \normalexpanded{\processcommalist[#1]}\currentcommalistcommand} + {\def\syst_helpers_comma_list_step##1{\def\currentcommalistitem{##1}#2}% + \normalexpanded{\processcommalist[#1]}\syst_helpers_comma_list_step} + +\let\stopprocesscommalist \relax +\let\stopprocesscommacommand\relax %D \macros %D {processaction, @@ -1097,8 +1118,8 @@ % obsolete: \def\expandactions{\let\expandedaction\edef} \expandactions (see mkii) \unexpanded\def\syst_helpers_do_compare_process_action_a[#1=>#2][#3]% - {\edef\!!stringb{#1}% - \ifx\!!stringb\s!default + {\edef\m_syst_string_two{#1}% + \ifx\m_syst_string_two\s!default \let\commalistelement\empty #2% \fi} @@ -1106,19 +1127,19 @@ % met \quitcommalist tot meer dan 25\% sneller \unexpanded\def\syst_helpers_do_compare_process_action_b[#1=>#2][#3]% - {\edef\!!stringb{#1}% - \ifx\!!stringa\!!stringb + {\edef\m_syst_string_two{#1}% + \ifx\m_syst_string_one\m_syst_string_two \def\commalistelement{#3}% #2% \expandafter\quitcommalist - \else\ifx\!!stringb\s!unknown + \else\ifx\m_syst_string_two\s!unknown \def\commalistelement{#3}% beware of loops #2% \fi\fi} \unexpanded\def\processaction[#1]#2[% - {\edef\!!stringa{#1}% - \ifx\!!stringa\empty + {\edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \let\syst_helpers_do_compare_process_action\syst_helpers_do_compare_process_action_a \else \let\syst_helpers_do_compare_process_action\syst_helpers_do_compare_process_action_b @@ -1127,23 +1148,23 @@ \processnextcommalist\relax\relax\syst_helpers_do_process_action[} \unexpanded\def\syst_helpers_do_compare_process_action_c[#1=>#2][#3]% - {\edef\!!stringa{#1}% - \edef\!!stringb{#3}% - \ifx\!!stringa\!!stringb + {\edef\m_syst_string_one{#1}% + \edef\m_syst_string_two{#3}% + \ifx\m_syst_string_one\m_syst_string_two \def\commalistelement{#3}% #2% \expandafter\quitprevcommalist \else - \edef\!!stringa{#1}% - \ifx\!!stringa\s!unknown + \edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\s!unknown \def\commalistelement{#3}% #2% \fi \fi} \unexpanded\def\processfirstactioninset[#1]% - {\edef\!!stringa{#1}% - \ifx\!!stringa\empty + {\edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\processaction \else \expandafter\syst_helpers_process_first_action_in_set_indeed @@ -1157,26 +1178,28 @@ \normalexpanded{\processcommalist[#1]}\syst_helpers_do_process_action} \unexpanded\def\syst_helpers_do_compare_process_action_d[#1=>#2][#3]% - {\edef\!!stringa{#1}% - \edef\!!stringb{#3}% - \ifx\!!stringa\!!stringb + {\edef\m_syst_string_one{#1}% + \edef\m_syst_string_two{#3}% + \ifx\m_syst_string_one\m_syst_string_two \def\commalistelement{#3}% #2% \expandafter\quitcommalist \else - \edef\!!stringa{#1}% - \ifx\!!stringa\s!unknown + \edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\s!unknown \def\commalistelement{#3}% #2% \fi \fi} +\installsystemnamespace{nextactionlevel} + \unexpanded\def\syst_helpers_do_process_all_actions_in_set - {\csname\s!do\the\processlevel\endcsname} + {\csname\??nextactionlevel\the\processlevel\endcsname} \unexpanded\def\processallactionsinset[#1]% - {\edef\!!stringa{#1}% - \ifx\!!stringa\empty + {\edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\processaction \else \expandafter\syst_helpers_process_all_actions_in_set_indeed @@ -1185,7 +1208,7 @@ \unexpanded\def\syst_helpers_process_all_actions_in_set_indeed[#1]#2[#3]% {\advance\processlevel \plusone - \expandafter\def\csname\s!do\the\processlevel\endcsname##1% + \expandafter\def\csname\??nextactionlevel\the\processlevel\endcsname##1% {\def\syst_helpers_do_do_process_action####1{\syst_helpers_do_compare_process_action_d[####1][##1]}% \processcommalist[#3]\syst_helpers_do_do_process_action}% \normalexpanded{\processcommalist[#1]}\syst_helpers_do_process_all_actions_in_set @@ -1197,7 +1220,7 @@ {#1% \let\nexttoken#4% \global\advance\commalevel \plusone - \expandafter\def\csname\s!next\the\commalevel\endcsname##1,% + \expandafter\def\csname\??nextcommalevel\the\commalevel\endcsname##1,% {#3{##1}\syst_helpers_do_process_comma_item}% \syst_helpers_do_do_process_comma_item#4#5,]\relax \global\advance\commalevel\minusone @@ -1231,46 +1254,48 @@ %D \doifinsetelse {substring} {string} {then ...} {else ...} %D \stoptyping +\let\m_syst_sub_string\empty + \unexpanded\def\doifinstringelse#1% - {\edef\@@@instring{#1}% expand #1 here - \ifx\@@@instring\empty + {\edef\m_syst_sub_string{#1}% expand #1 here + \ifx\m_syst_sub_string\empty \expandafter\thirdofthreearguments \else \expandafter\syst_helpers_do_if_in_string_else_indeed \fi} \unexpanded\def\syst_helpers_do_if_in_string_else_indeed#1% - {\syst_helpers_do_if_in_string_else\@@@instring{#1}% + {\syst_helpers_do_if_in_string_else\m_syst_sub_string{#1}% \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments \fi} \unexpanded\def\doifinstring#1%% - {\edef\@@@instring{#1}% expand #1 here - \ifx\@@@instring\empty + {\edef\m_syst_sub_string{#1}% expand #1 here + \ifx\m_syst_sub_string\empty \expandafter\gobbletwoarguments \else \expandafter\syst_helpers_do_if_in_string_indeed \fi} \unexpanded\def\syst_helpers_do_if_in_string_indeed#1% - {\syst_helpers_do_if_in_string_else\@@@instring{#1}% + {\syst_helpers_do_if_in_string_else\m_syst_sub_string{#1}% \expandafter\firstofoneargument \else \expandafter\gobbleoneargument \fi} \unexpanded\def\doifnotinstring#1%% - {\edef\@@@instring{#1}% expand #1 here - \ifx\@@@instring\empty + {\edef\m_syst_sub_string{#1}% expand #1 here + \ifx\m_syst_sub_string\empty \expandafter\gobbletwoarguments \else \expandafter\syst_helpers_do_if_not_in_string_indeed \fi} \unexpanded\def\syst_helpers_do_if_not_in_string_indeed#1% - {\syst_helpers_do_if_in_string_else\@@@instring{#1}% + {\syst_helpers_do_if_in_string_else\m_syst_sub_string{#1}% \expandafter\gobbleoneargument \else \expandafter\firstofoneargument @@ -1280,8 +1305,8 @@ \unexpanded\def\syst_helpers_do_if_in_string_else#1#2% ##2 can be {abc} {\expandafter\def\expandafter\syst_helpers_do_do_if_in_string_else - \expandafter##\expandafter1#1##2##3\war{\unless\if##2@}% expand #1 here - \expandafter\syst_helpers_do_do_if_in_string_else\normalexpanded{#2#1}@@\war} % expand #2 here + \expandafter##\expandafter1#1##2##3\_e_o_s_{\unless\if##2@}% expand #1 here + \expandafter\syst_helpers_do_do_if_in_string_else\normalexpanded{#2#1}@@\_e_o_s_} % expand #2 here %D The next alternative proved to be upto twice as fast on %D tasks like checking reserved words in pretty verbatim @@ -1297,33 +1322,31 @@ %D expansion. \unexpanded\def\syst_helpers_do_if_in_csname_else#1#2% - {\def\syst_helpers_do_do_if_in_csname_else##1#1##2##3\war + {\def\syst_helpers_do_do_if_in_csname_else##1#1##2##3\_e_o_s_ {\unless\if##2@}% - \expandafter\syst_helpers_do_do_if_in_csname_else#2#1@@\war} + \expandafter\syst_helpers_do_do_if_in_csname_else#2#1@@\_e_o_s_} \unexpanded\def\doifincsnameelse#1#2% - {\edef\@@@instring{#1}% - \expandafter\syst_helpers_do_if_in_csname_else\expandafter{\@@@instring}{#2}% + {\normalexpanded{\syst_helpers_do_if_in_csname_else{#1}}{#2}% \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments \fi} %D \macros -%D {doifnumberelse} +%D {doifnumberelse,doifnumber,doifnotnumber} %D -%D The next macro executes a command depending of the outcome -%D of a test on numerals. This is probably one of the fastest -%D test possible, exept from a less robust 10||step -%D \type{\if}||ladder or some tricky \type{\lcode} checking. +%D The next macro executes a command depending of the outcome of a test on +%D numerals. This is probably one of the fastest test possible, exept from +%D a less robust 10||step \type {\if}||ladder or some tricky \type {\lcode} +%D checking. %D %D \starttyping %D \doifnumberelse {string} {then ...} {else ...} %D \stoptyping %D -%D The macro accepts \type{123}, \type{abc}, \type{{}}, -%D \type{\getal} and \type{\the\count...}. This macro is a -%D rather dirty one. +%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) {\ifcase0\ifcase1#1\or\or\or\or\or\or\or\or\or\else1\fi\space @@ -1332,6 +1355,35 @@ \expandafter\firstoftwoarguments \fi} +\def\doifnumber#1% + {\ifcase0\ifcase1#1\or\or\or\or\or\or\or\or\or\else1\fi\space + \expandafter\firstofoneargument + \else + \expandafter\gobbleoneargument + \fi} + +\def\doifnotnumber#1% + {\ifcase0\ifcase1#1\or\or\or\or\or\or\or\or\or\else1\fi\space + \expandafter\gobbleoneargument + \else + \expandafter\firstofoneargument + \fi} + +%D \macros +%D {setpercentdimen} +%D +%D \starttyping +%D \scratchdimen=100pt \setpercentdimen\scratchdimen{10\letterpercent} +%D \scratchdimen=100pt \setpercentdimen\scratchdimen{5pt} +%D \scratchdimen \percentdimen \hsize {10\letterpercent} +%D \stoptyping + +\def\percentdimen#1#2% dimen percentage (with %) + {\dimexpr\ctxcommand{percentageof("#2",\number#1)}\relax} + +\unexpanded\def\setpercentdimen#1#2% dimen percentage (with %) + {#1=\ctxcommand{percentageof("#2",\number#1)}\relax} + %D \macros %D {makerawcommalist, %D rawdoinsetelse, @@ -1372,13 +1424,13 @@ \def\syst_helpers_raw_process_comma_item#1,#2% #2 eats up preceding space {\if]#1\else - \csname\s!next\the\commalevel\endcsname{#1}% + \csname\??nextcommalevel\the\commalevel\endcsname{#1}% \expandafter\syst_helpers_raw_process_comma_item \fi#2} \unexpanded\def\rawprocesscommalist[#1]#2% accepteert ook [\cs] {\global\advance\commalevel \plusone - \expandafter\let\csname\s!next\the\commalevel\endcsname#2% + \expandafter\let\csname\??nextcommalevel\the\commalevel\endcsname#2% \expandafter\syst_helpers_raw_process_comma_item#1,],% \relax \global\advance\commalevel \minusone } @@ -1388,33 +1440,33 @@ % \def\rawdoifinsetelse#1#2{\doifinstringelse{,#1,}{,#2,}} % \def\rawdoifinset #1#2{\doifinstring {,#1,}{,#2,}} -\def\@@rawempty{,,} +\def\m_syst_two_commas{,,} \unexpanded\def\rawdoifinsetelse#1% - {\edef\@@@instring{,#1,}% expand #1 here - \ifx\@@@instring\@@rawempty + {\edef\m_syst_sub_string{,#1,}% expand #1 here + \ifx\m_syst_sub_string\m_syst_two_commas \expandafter\thirdofthreearguments \else \expandafter\syst_helpers_raw_do_if_in_set_else \fi} \unexpanded\def\syst_helpers_raw_do_if_in_set_else#1% - {\syst_helpers_do_if_in_string_else\@@@instring{,#1,}% + {\syst_helpers_do_if_in_string_else\m_syst_sub_string{,#1,}% \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments \fi} \unexpanded\def\rawdoifinset#1% - {\edef\@@@instring{,#1,}% expand #1 here - \ifx\@@@instring\@@rawempty + {\edef\m_syst_sub_string{,#1,}% expand #1 here + \ifx\m_syst_sub_string\m_syst_two_commas \expandafter\gobbletwoarguments \else \expandafter\syst_helpers_raw_do_if_in_set \fi} \unexpanded\def\syst_helpers_raw_do_if_in_set#1%% - {\syst_helpers_do_if_in_string_else\@@@instring{,#1,}% + {\syst_helpers_do_if_in_string_else\m_syst_sub_string{,#1,}% \expandafter\firstofoneargument \else \expandafter\gobbleoneargument @@ -1423,42 +1475,40 @@ %D Some more raw material: \def\syst_helpers_do_raw_process_action[#1][#2]% - {\def\syst_helpers_do_do_raw_process_action##1,#1=>##2,##3\war + {\def\syst_helpers_do_do_raw_process_action##1,#1=>##2,##3\_e_o_s_ {\if##3@\else - \def\!!processaction{##2}% + \def\m_syst_helpers_process_action{##2}% \fi}% - \syst_helpers_do_do_raw_process_action,#2,#1=>,@\war} + \syst_helpers_do_do_raw_process_action,#2,#1=>,@\_e_o_s_} \unexpanded\def\rawprocessaction[#1]#2[#3]% - {\edef\!!stringa{#1}% - \edef\!!stringb{undefined}% better \!!undefined - \let\!!processaction\!!stringb - \ifx\!!stringa\empty + {\edef\m_syst_string_one{#1}% + \edef\m_syst_string_two{undefined}% better \!!undefined + \let\m_syst_helpers_process_action\m_syst_string_two + \ifx\m_syst_string_one\empty \expandafter\syst_helpers_do_raw_process_action\expandafter[\s!default][#3]% \else - \expandafter\syst_helpers_do_raw_process_action\expandafter[\!!stringa][#3]% - \ifx\!!processaction\!!stringb + \expandafter\syst_helpers_do_raw_process_action\expandafter[\m_syst_string_one][#3]% + \ifx\m_syst_helpers_process_action\m_syst_string_two \expandafter\syst_helpers_do_raw_process_action\expandafter[\s!unknown][#3]% \fi \fi - \ifx\!!processaction\!!stringb + \ifx\m_syst_helpers_process_action\m_syst_string_two \else - \!!processaction + \m_syst_helpers_process_action \fi} -%D When we process the list \type{a,b,c,d,e}, the raw routine -%D takes over 30\% less time, when we feed $20+$ character -%D strings we gain about 20\%. Alternatives which use -%D \type{\futurelet} perform worse. Part of the speedup is -%D due to the \type{\let} and \type{\expandafter} in the test. +%D When we process the list \type{a,b,c,d,e}, the raw routine takes over 30\% less +%D time, when we feed $20+$ character strings we gain about 20\%. Alternatives which +%D use \type{\futurelet} perform worse. Part of the speedup is due to the +%D \type{\let} and \type{\expandafter} in the test. %D \macros %D {dosetvalue,dosetevalue,dosetgvalue,docopyvalue,doresetvalue, %D dogetvalue} %D -%D When we are going to do assignments, we have to take -%D multi||linguality into account. For the moment we keep -%D things simple and single||lingual. +%D When we are going to do assignments, we have to take multi||linguality into account. +%D For the moment we keep things simple and single||lingual. %D %D \starttyping %D \dosetvalue {label} {variable} {value} @@ -1468,8 +1518,8 @@ %D \doresetvalue {label} {variable} %D \stoptyping %D -%D These macros are in fact auxiliary ones and are not meant -%D for use outside the assignment macros. +%D These macros are in fact auxiliary ones and are not meant for use outside the +%D assignment macros. \def\dosetvalue#1#2% #3 {\expandafter\def\csname#1#2\endcsname} % {#3}} @@ -1492,13 +1542,11 @@ %D \macros %D {doassign,undoassign,doassignempty} %D -%D Assignments are the backbone of \CONTEXT. Abhorred by the -%D concept of style file hacking, we took a considerable effort -%D in building a parameterized system. Unfortunately there is a -%D price to pay in terms of speed. Compared to other packages -%D and taking the functionality of \CONTEXT\ into account, the -%D total size of the format file is still very acceptable. Now -%D how are these assignments done. +%D Assignments are the backbone of \CONTEXT. Abhorred by the concept of style file +%D hacking, we took a considerable effort in building a parameterized system. +%D Unfortunately there is a price to pay in terms of speed. Compared to other +%D packages and taking the functionality of \CONTEXT\ into account, the total size +%D of the format file is still very acceptable. Now how are these assignments done. %D %D Assignments can be realized with: %D @@ -1519,38 +1567,36 @@ %D \def\labelvariable{value} %D \stoptyping %D -%D We do check for the presence of an \type{=} and loudly -%D complain of it's missed. We will redefine this macro later -%D on, when a more advanced message mechanism is implemented. +%D We do check for the presence of an \type{=} and loudly complain of it's missed. We +%D will redefine this macro later on, when a more advanced message mechanism is +%D implemented. \newif\iferrorisfatal -\def\waitonfatalerror +\unexpanded\def\waitonfatalerror {\iferrorisfatal\wait\fi} -\def\showassignerror#1#2% +\unexpanded\def\showassignerror#1#2% {\writestatus{setup}{missing or ungrouped '=' after '#1' in line #2}% \waitonfatalerror} -\def\doassignempty[#1][#2=#3]% +\unexpanded\def\doassignempty[#1][#2=#3]% {\ifcsname#1#2\endcsname\else\dosetvalue{#1}{#2}{#3}\fi} %D \macros %D {getparameters,geteparameters,getgparameters, %D forgetparameters} %D -%D Using the assignment commands directly is not our -%D ideal of user friendly interfacing, so we take some further -%D steps. +%D Using the assignment commands directly is not our ideal of user friendly interfacing, +%D so we take some further steps. %D %D \starttyping %D \getparameters [label] [...=...,...=...] %D \forgetparameters [label] [...=...,...=...] %D \stoptyping %D -%D Again, the label identifies the category a variable -%D belongs to. The second argument can be a comma separated -%D list of assignments. +%D Again, the label identifies the category a variable belongs to. The second argument +%D can be a comma separated list of assignments. %D %D \starttyping %D \getparameters @@ -1567,8 +1613,7 @@ %D \stoptyping %D %D -%D In the pre||multi||lingual stadium \CONTEXT\ took the next -%D approach. With +%D In the pre||multi||lingual stadium \CONTEXT\ took the next approach. With %D %D \starttyping %D \def\??demo {@@demo} @@ -1592,20 +1637,16 @@ %D \def\@@demobeta{2} %D \stoptyping %D -%D Because we want to be able to distinguish the \type{!!} -%D pre||tagged user supplied variables from internal -%D counterparts, we will introduce a slightly different tag in -%D the multi||lingual modules. There we will use \type{c!} or -%D \type{v!}, depending on the context. +%D Because we want to be able to distinguish the \type{!!} pre||tagged user supplied +%D variables from internal counterparts, we will introduce a slightly different tag +%D in the multi||lingual modules. There we will use \type{c!} or \type{v!}, +%D depending on the context. %D -%D By calling \type{\p!doassign} directly, we save ourselves -%D some argument passing and gain some speed. Whatever -%D optimizations we do, this command will always be one of the -%D bigger bottlenecks. -%D -%D The alternative \type{\geteparameters} --- it's funny to -%D see that this alternative saw the light so lately --- can be -%D used to do expanded assigments. +%D By calling \type{doassign} directly, we save ourselves some argument passing +%D and gain some speed. Whatever optimizations we do, this command will always be +%D one of the bigger bottlenecks. The alternative \type{\geteparameters} --- it's +%D funny to see that this alternative saw the light so lately --- can be used to do +%D expanded assigments. \let\currentvalue\empty @@ -1617,46 +1658,46 @@ \let\getexpandedparameters\geteparameters -\def\dogetparameters#1[#2]#3[#4% +\unexpanded\def\dogetparameters#1[#2]#3[#4% {\if\noexpand#4]% \expandafter\gobbleoneargument \else \let\setsomevalue#1% - \def\p!dogetparameter{\p!doassign#2}% - \expandafter\xdogetparameters + \def\syst_helpers_get_parameters_assign{\syst_helpers_get_parameters_assign_indeed#2}% + \expandafter\syst_helpers_get_parameters \fi#4} -\def\xdogetparameters#1]% - {\xprocesscommaitem#1,],\@relax@} +\def\syst_helpers_get_parameters#1]% + {\xprocesscommaitem#1,],\_e_o_p_} -\def\xprocesscommaitem#1,#2% #2 takes space before , +\def\syst_helpers_process_comma_item#1,#2% #2 takes space before , {\if,#1,% dirty trick for testing #1=empty - \expandafter\xprocesscommaitem + \expandafter\syst_helpers_process_comma_item \else\if]#1% \doubleexpandafter\gobbleoneargument \else - \p!dogetparameter\@relax@#1==\empty\@relax@ - \doubleexpandafter\xprocesscommaitem + \syst_helpers_get_parameters_assign\_e_o_p_#1==\empty\_e_o_p_ + \doubleexpandafter\syst_helpers_process_comma_item \fi\fi#2} -\def\xshowassignerror#1#2#3% +\def\syst_helpers_assign_error#1#2#3% {\showassignerror{#2}{\the\inputlineno\space(#1)}} -\def\p!n!doassign#1\@relax@#2=#3=#4#5\@relax@ +\def\syst_helpers_get_parameters_assign_normal#1\_e_o_p_#2=#3=#4#5\_e_o_p_ {\ifx\empty#2\empty - \expandafter\xshowassignerror + \expandafter\syst_helpers_assign_error \else\ifx#4\empty - \doubleexpandafter\xshowassignerror + \doubleexpandafter\syst_helpers_assign_error \else \doubleexpandafter\setsomevalue \fi\fi {#1}{#2}{#3}} -\def\p!e!doassign#1\@relax@#2=#3=#4#5\@relax@ +\def\syst_helpers_get_parameters_assign_error#1\_e_o_p_#2=#3=#4#5\_e_o_p_ {\ifx\empty#2\empty - \expandafter\xshowassignerror + \expandafter\syst_helpers_assign_error \else\ifx#4\empty - \doubleexpandafter\xshowassignerror + \doubleexpandafter\syst_helpers_assign_error \else \ifcsname#1#2\endcsname \expandafter\let\expandafter\currentvalue\csname#1#2\endcsname @@ -1667,11 +1708,11 @@ \fi\fi {#1}{#2}{#3}} -\let\p!doassign\p!n!doassign +\let\syst_helpers_get_parameters_assign_indeed\syst_helpers_get_parameters_assign_normal -\def\doassign [#1][#2]{\let\setsomevalue\dosetvalue \p!doassign#1\@relax@#2==\empty\@relax@} -\def\doeassign [#1][#2]{\let\setsomevalue\dosetevalue \p!doassign#1\@relax@#2==\empty\@relax@} -\def\undoassign[#1][#2]{\let\setsomevalue\doresetvalue\p!doassign#1\@relax@#2==\empty\@relax@} +\unexpanded\def\doassign [#1][#2]{\let\setsomevalue\dosetvalue \syst_helpers_get_parameters_assign_indeed#1\_e_o_p_#2==\empty\_e_o_p_} +\unexpanded\def\doeassign [#1][#2]{\let\setsomevalue\dosetevalue \syst_helpers_get_parameters_assign_indeed#1\_e_o_p_#2==\empty\_e_o_p_} +\unexpanded\def\undoassign[#1][#2]{\let\setsomevalue\doresetvalue\syst_helpers_get_parameters_assign_indeed#1\_e_o_p_#2==\empty\_e_o_p_} %D \macros %D {processassignmentlist,processassignmentcommand, @@ -1688,8 +1729,8 @@ %D worth the trouble and tokens. \unexpanded\def\processassignmentlist[#1]#2% #2 == \command{key}{value] - {\def\doprocessassignmententry##1{#2}% {##2}{##3} % namespace is ignored - \dogetparameters\doprocessassignmententry[][#1]} + {\def\syst_helpers_process_assignment_entry##1{#2}% {##2}{##3} % namespace is ignored + \dogetparameters\syst_helpers_process_assignment_entry[][#1]} \unexpanded\def\processassignmentcommand[#1]% {\normalexpanded{\processassignmentlist[#1]}} @@ -1704,9 +1745,8 @@ %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. +%D Just in case a \type{\getparameter} argument itself ends up inside a \type +%D {\write} or other expandable location, our new macro needs a default value. %D %D \starttyping %D \getparameters[xxx][aaa=bbb]\par @@ -1716,7 +1756,8 @@ %D \getparameters[xxx][aaa]\par %D \stoptyping -%D \macros {expandparameters} +%D \macros +%D {expandparameters} %D %D Example usage: %D @@ -1733,26 +1774,27 @@ %D \startlines %D \getbuffer %D \stoplines - +%D %D Here we hook in the code (beware, this is the optimized get **): -\def\xdoget@n@parameters#1]% - {\xprocesscommaitem#1,],\@relax@} +\def\syst_helpers_get_parameters_normal#1]% + {\syst_helpers_process_comma_item#1,],\_e_o_p_} -\def\xdoget@e@parameters#1]% +\def\syst_helpers_get_parameters_expanded#1]% {\let\dosetnvalue\setsomevalue \let\setsomevalue\dosetevalue - \let\p!doassign\p!e!doassign + \let\syst_helpers_get_parameters_assign_indeed\syst_helpers_get_parameters_assign_error \let\setsomevalue\dosetevalue - \xprocesscommaitem#1,],\@relax@ - \let\p!doassign\p!n!doassign + \syst_helpers_process_comma_item#1,],\_e_o_p_ + \let\syst_helpers_get_parameters_assign_indeed\syst_helpers_get_parameters_assign_normal \let\setsomevalue\dosetnvalue - \let\xdogetparameters\xdoget@n@parameters + \let\syst_helpers_get_parameters\syst_helpers_get_parameters_normal \let\currentvalue\empty} -\let\xdogetparameters\xdoget@n@parameters % ** +\let\syst_helpers_get_parameters\syst_helpers_get_parameters_normal % ** -\def\expandparameters{\let\xdogetparameters\xdoget@e@parameters} +\unexpanded\def\expandparameters + {\let\syst_helpers_get_parameters\syst_helpers_get_parameters_expanded} %D \macros %D {getemptyparameters} @@ -1764,9 +1806,9 @@ %D \getemptyparameters [label] [...=...,...=...] %D \stoptyping -\def\getemptyparameters[#1]#2[#3]% - {\def\p!dogetemptyparameter##1{\doassignempty[#1][##1]}% - \processcommalist[#3]\p!dogetemptyparameter} +\unexpanded\def\getemptyparameters[#1]#2[#3]% + {\def\syst_helpers_get_empty_parameters##1{\doassignempty[#1][##1]}% + \processcommalist[#3]\syst_helpers_get_empty_parameters} %D \macros %D {copyparameters} @@ -1801,8 +1843,8 @@ \unexpanded\def\copyparameters[#1]#2[#3]#4[#5]% {\doifnot{#1}{#3} - {\def\docopyparameter{\docopyvalue{#1}{#3}}% ##1 - \processcommalist[#5]\docopyparameter}} + {\def\syst_helpers_copy_parameter{\docopyvalue{#1}{#3}}% ##1 + \processcommalist[#5]\syst_helpers_copy_parameter}} %D \macros %D {ifparameters,checkparameters} @@ -1820,58 +1862,60 @@ \newif\ifparameters -\def\p!checkparameters#1=#2#3\war% +\def\syst_helpers_check_parameters#1=#2#3\_e_o_s_ {\if#2@\parametersfalse\else\parameterstrue\fi} -\def\checkparameters[#1]% - {\p!checkparameters#1=@@\war} +\unexpanded\def\checkparameters[#1]% + {\syst_helpers_check_parameters#1=@@\_e_o_s_} %D \macros %D {getfromcommalist,getfromcommacommand, %D commalistelement, %D getcommalistsize,getcommacommandsize} %D -%D It's possible to get an element from a commalist or a -%D command representing a commalist. +%D It's possible to get an element from a commalist or a command representing +%D a commalist. %D %D \starttyping %D \getfromcommalist [string] [n] %D \getfromcommacommand [string,\strings,string,...] [n] %D \stoptyping %D -%D The difference betwee the two of them is the same as the -%D difference between \type{\processcomma...}. The found string -%D is stored in \type{\commalistelement}. +%D The difference betwee the two of them is the same as the difference between +%D \type {\processcomma...}. The found string is stored in \type +%D {\commalistelement}. %D -%D We can calculate the size of a comma separated list by -%D using: +%D We can calculate the size of a comma separated list by using: %D %D \starttyping %D \getcommalistsize [string,string,...] %D \getcommacommandsize [string,\strings,string,...] %D \stoptyping %D -%D Afterwards, the length is available in the macro -%D \type{\commalistsize} (not a \COUNTER). +%D Afterwards, the length is available in the macro \type {\commalistsize} +%D (not a \COUNTER). \newcount\commalistcounter \def\commalistsize{0} -\def\p!dogetcommalistsize#1% +\def\syst_helpers_get_comma_list_size#1% {\advance\commalistcounter\plusone} -\def\getcommalistsize#1]% don't loose [{#1}] +\unexpanded\def\getcommalistsize#1]% don't loose [{#1}] {\commalistcounter\zerocount - \processcommalist#1]\p!dogetcommalistsize % was [{#1}] + \processcommalist#1]\syst_helpers_get_comma_list_size % was [{#1}] \edef\commalistsize{\the\commalistcounter}} -\def\getcommacommandsize[#1]% - {\edef\commacommand{#1}% - \scratchtoks\expandafter{\expandafter[\commacommand]}% - \expandafter\getcommalistsize\the\scratchtoks } +% \def\getcommacommandsize[#1]% +% {\edef\commacommand{#1}% +% \scratchtoks\expandafter{\expandafter[\commacommand]}% +% \expandafter\getcommalistsize\the\scratchtoks } + +\unexpanded\def\getcommacommandsize[#1]% + {\normalexpanded{\getcommalistsize[#1]}} -\def\p!dogetfromcommalist#1% +\def\syst_helpers_get_from_comma_list#1% {\advance\commalistcounter \minusone \ifcase\commalistcounter \def\commalistelement{#1}% @@ -1881,7 +1925,7 @@ \unexpanded\def\getfromcommalist[#1]#2[#3]% {\let\commalistelement\empty \commalistcounter#3\relax - \processcommalist[#1]\p!dogetfromcommalist} + \processcommalist[#1]\syst_helpers_get_from_comma_list} \unexpanded\def\getfromcommacommand[#1]% {\normalexpanded{\getfromcommalist[#1]}} @@ -1919,16 +1963,11 @@ %D \dogetcommalistelement1\from a,b,c\to\commalistelement %D \stoptyping -\def\dodogetcommalistelement#1\from#2,#3,#4,#5,#6,#7,#8\to#9% +\def\syst_helpers_get_comma_list_element#1\from#2,#3,#4,#5,#6,#7,#8\to#9% {\edef#9{\ifcase#1\relax\or#2\or#3\or#4\or#5\or#6\or#7\or#8\fi}} -\def\dogetcommalistelement#1\from#2\to% - {\dodogetcommalistelement#1\from#2,,,,,,\to} - -% check sources - \def\dogetcommacommandelement#1\from#2\to% - {\expandafter\dodogetcommalistelement\expandafter#1\expandafter\from#2,,,,,,\to} + {\expandafter\syst_helpers_get_comma_list_element\expandafter#1\expandafter\from#2,,,,,,\to} %D \macros %D {dosingleargument,dodoubleargument,dotripleargument, @@ -1984,13 +2023,15 @@ %D us to do some checking, we reimplemented the non||empty %D ones. -\unexpanded\def\dosingleargument {\let\expectedarguments\plusone \dosingleempty } -\unexpanded\def\dodoubleargument {\let\expectedarguments\plustwo \dodoubleempty } -\unexpanded\def\dotripleargument {\let\expectedarguments\plusthree \dotripleempty } -\unexpanded\def\doquadrupleargument {\let\expectedarguments\plusfour \doquadrupleempty } -\unexpanded\def\doquintupleargument {\let\expectedarguments\plusfive \doquintupleempty } -\unexpanded\def\dosixtupleargument {\let\expectedarguments\plussix \dosixtupleempty } -\unexpanded\def\doseventupleargument{\let\expectedarguments\plusseven \doseventupleempty} +% no longer a mesage: +% +% \unexpanded\def\dosingleargument {\let\expectedarguments\plusone \dosingleempty } +% \unexpanded\def\dodoubleargument {\let\expectedarguments\plustwo \dodoubleempty } +% \unexpanded\def\dotripleargument {\let\expectedarguments\plusthree \dotripleempty } +% \unexpanded\def\doquadrupleargument {\let\expectedarguments\plusfour \doquadrupleempty } +% \unexpanded\def\doquintupleargument {\let\expectedarguments\plusfive \doquintupleempty } +% \unexpanded\def\dosixtupleargument {\let\expectedarguments\plussix \dosixtupleempty } +% \unexpanded\def\doseventupleargument{\let\expectedarguments\plusseven \doseventupleempty} %D \macros %D {iffirstagument,ifsecondargument,ifthirdargument, @@ -2013,8 +2054,7 @@ %D doquadrupleempty,doquintupleempty,dosixtupeempty, %D doseventupleempty} %D -%D The empty argument supplying macros mentioned before, look -%D like: +%D The empty argument supplying macros mentioned before, look like: %D %D \starttyping %D \dosingleempty \command @@ -2022,11 +2062,11 @@ %D \dotripleempty \command %D \doquadrupleempty \command %D \doquintupleempty \command -%D \dosixtupleempty \command +%D \dosixtuple_empty \command %D \doseventupleempty\command %D \stoptyping %D -%D So \type{\dodoubleempty} leades to: +%D So \type{\dodoubleempty} leads to: %D %D \starttyping %D \command[#1][#2] @@ -2041,16 +2081,16 @@ \setnewconstant\noexpectedarguments\zerocount \setnewconstant\expectedarguments \zerocount -\def\showargumenterror#1#2% +\unexpanded\def\showargumenterror#1#2% {\writestatus{system}{\number#1 argument(s) expected in line #2}} -\def\doshowargumenterror +\unexpanded\def\syst_helpers_argument_error {\ifnum\expectedarguments>\noexpectedarguments \showargumenterror{\number\expectedarguments}{\number\inputlineno}% \fi - \noshowargumenterror} + \syst_helpers_argument_reset} -\def\noshowargumenterror +\unexpanded\def\syst_helpers_argument_reset {\let\expectedarguments\noexpectedarguments} % \def\test[#1]{(#1)} @@ -2074,193 +2114,193 @@ %D Single: \unexpanded\def\dosingleempty#1% - {\noshowargumenterror + {\syst_helpers_argument_reset \doifnextoptionalelse {\firstargumenttrue#1}% - {\dosingleemptyNOPone#1}} + {\syst_helpers_single_empty_one_nop#1}} -\def\dosingleemptyNOPone#1% +\def\syst_helpers_single_empty_one_nop#1% {\firstargumentfalse #1[]} %D Double \unexpanded\def\dodoubleempty#1% - {\noshowargumenterror + {\syst_helpers_argument_reset \doifnextoptionalelse - {\dodoubleemptyYESone#1}% - {\dodoubleemptyNOPone#1}} + {\syst_helpers_double_empty_one_yes#1}% + {\syst_helpers_double_empty_one_nop#1}} -\def\dodoubleemptyYESone#1[#2]% +\def\syst_helpers_double_empty_one_yes#1[#2]% {\firstargumenttrue \doifnextoptionalelse {\secondargumenttrue#1[{#2}]}% - {\dodoubleemptyNOPtwo#1{#2}}} + {\syst_helpers_double_empty_two_nop#1{#2}}} -\def\dodoubleemptyNOPone#1% +\def\syst_helpers_double_empty_one_nop#1% {\firstargumentfalse \secondargumentfalse #1[][]} -\def\dodoubleemptyNOPtwo +\def\syst_helpers_double_empty_two_nop {\secondargumentfalse \if_next_blank_space_token - \expandafter\dodoubleemptyonespaced + \expandafter\syst_helpers_double_empty_one_spaced \else - \expandafter\dodoubleemptyonenormal + \expandafter\syst_helpers_double_empty_one_normal \fi} -\def\dodoubleemptyonespaced#1#2{#1[{#2}][] } -\def\dodoubleemptyonenormal#1#2{#1[{#2}][]} +\def\syst_helpers_double_empty_one_spaced#1#2{#1[{#2}][] } +\def\syst_helpers_double_empty_one_normal#1#2{#1[{#2}][]} % Three \unexpanded\def\dotripleempty#1% - {\noshowargumenterror + {\syst_helpers_argument_reset \doifnextoptionalelse - {\dotripleemptyYESone#1}% - {\dotripleemptyNOPone#1}} + {\syst_helpers_triple_empty_one_yes#1}% + {\syst_helpers_triple_empty_one_nop#1}} -\def\dotripleemptyYESone#1[#2]% +\def\syst_helpers_triple_empty_one_yes#1[#2]% {\firstargumenttrue \doifnextoptionalelse - {\dotripleemptyYEStwo#1{#2}}% - {\dotripleemptyNOPtwo#1{#2}}} + {\syst_helpers_triple_empty_two_yes#1{#2}}% + {\syst_helpers_triple_empty_two_nop#1{#2}}} -\def\dotripleemptyYEStwo#1#2[#3]% +\def\syst_helpers_triple_empty_two_yes#1#2[#3]% {\secondargumenttrue \doifnextoptionalelse {\thirdargumenttrue#1[{#2}][{#3}]}% - {\dotripleemptyNOPthree#1{#2}{#3}}} + {\syst_helpers_triple_empty_three_nop#1{#2}{#3}}} -\def\dotripleemptyNOPone#1% +\def\syst_helpers_triple_empty_one_nop#1% {\firstargumentfalse \secondargumentfalse \thirdargumentfalse #1[][][]} -\def\dotripleemptyNOPtwo +\def\syst_helpers_triple_empty_two_nop {\secondargumentfalse \thirdargumentfalse \if_next_blank_space_token - \expandafter\dotripleemptytwospaced + \expandafter\syst_helpers_triple_empty_two_spaced \else - \expandafter\dotripleemptytwonormal + \expandafter\syst_helpers_triple_empty_two_normal \fi} -\def\dotripleemptyNOPthree +\def\syst_helpers_triple_empty_three_nop {\thirdargumentfalse \if_next_blank_space_token - \expandafter\dotripleemptythreespaced + \expandafter\syst_helpers_triple_empty_three_spaced \else - \expandafter\dotripleemptythreenormal + \expandafter\syst_helpers_triple_empty_three_normal \fi} -\def\dotripleemptytwospaced #1#2{#1[{#2}][][] } -\def\dotripleemptytwonormal #1#2{#1[{#2}][][]} -\def\dotripleemptythreespaced#1#2#3{#1[{#2}][{#3}][] } -\def\dotripleemptythreenormal#1#2#3{#1[{#2}][{#3}][]} +\def\syst_helpers_triple_empty_two_spaced #1#2{#1[{#2}][][] } +\def\syst_helpers_triple_empty_two_normal #1#2{#1[{#2}][][]} +\def\syst_helpers_triple_empty_three_spaced#1#2#3{#1[{#2}][{#3}][] } +\def\syst_helpers_triple_empty_three_normal#1#2#3{#1[{#2}][{#3}][]} %D Four: \unexpanded\def\doquadrupleempty#1% - {\noshowargumenterror + {\syst_helpers_argument_reset \doifnextoptionalelse - {\doquadrupleemptyYESone#1}% - {\doquadrupleemptyNOPone#1}} + {\syst_helpers_quadruple_empty_one_yes#1}% + {\syst_helpers_quadruple_empty_one_nop#1}} -\def\doquadrupleemptyYESone#1[#2]% +\def\syst_helpers_quadruple_empty_one_yes#1[#2]% {\firstargumenttrue \doifnextoptionalelse - {\doquadrupleemptyYEStwo#1{#2}}% - {\doquadrupleemptyNOPtwo#1{#2}}} + {\syst_helpers_quadruple_empty_two_yes#1{#2}}% + {\syst_helpers_quadruple_empty_two_nop#1{#2}}} -\def\doquadrupleemptyYEStwo#1#2[#3]% +\def\syst_helpers_quadruple_empty_two_yes#1#2[#3]% {\secondargumenttrue \doifnextoptionalelse - {\doquadrupleemptyYESthree#1{#2}{#3}}% - {\doquadrupleemptyNOPthree#1{#2}{#3}}} + {\syst_helpers_quadruple_empty_three_yes#1{#2}{#3}}% + {\syst_helpers_quadruple_empty_three_nop#1{#2}{#3}}} -\def\doquadrupleemptyYESthree#1#2#3[#4]% +\def\syst_helpers_quadruple_empty_three_yes#1#2#3[#4]% {\thirdargumenttrue \doifnextoptionalelse {\fourthargumenttrue#1[{#2}][{#3}][{#4}]}% - {\doquadrupleemptyNOPfour#1{#2}{#3}{#4}}} + {\syst_helpers_quadruple_empty_four_nop#1{#2}{#3}{#4}}} -\def\doquadrupleemptyNOPone#1% +\def\syst_helpers_quadruple_empty_one_nop#1% {\firstargumentfalse \secondargumentfalse \thirdargumentfalse \fourthargumentfalse #1[][][][]} -\def\doquadrupleemptyNOPtwo +\def\syst_helpers_quadruple_empty_two_nop {\secondargumentfalse \thirdargumentfalse \fourthargumentfalse \if_next_blank_space_token - \expandafter\doquadrupleemptytwospaced + \expandafter\syst_helpers_quadruple_empty_two_spaced \else - \expandafter\doquadrupleemptytwonormal + \expandafter\syst_helpers_quadruple_empty_two_normal \fi} -\def\doquadrupleemptyNOPthree +\def\syst_helpers_quadruple_empty_three_nop {\thirdargumentfalse \fourthargumentfalse \if_next_blank_space_token - \expandafter\doquadrupleemptythreespaced + \expandafter\syst_helpers_quadruple_empty_three_spaced \else - \expandafter\doquadrupleemptythreenormal + \expandafter\syst_helpers_quadruple_empty_three_normal \fi} -\def\doquadrupleemptyNOPfour +\def\syst_helpers_quadruple_empty_four_nop {\fourthargumentfalse \if_next_blank_space_token - \expandafter\doquadrupleemptyfourspaced + \expandafter\syst_helpers_quadruple_empty_four_spaced \else - \expandafter\doquadrupleemptyfournormal + \expandafter\syst_helpers_quadruple_empty_four_normal \fi} -\def\doquadrupleemptytwospaced #1#2{#1[{#2}][][][] } -\def\doquadrupleemptytwonormal #1#2{#1[{#2}][][][]} -\def\doquadrupleemptythreespaced #1#2#3{#1[{#2}][{#3}][][] } -\def\doquadrupleemptythreenormal #1#2#3{#1[{#2}][{#3}][][]} -\def\doquadrupleemptyfourspaced #1#2#3#4{#1[{#2}][{#3}][{#4}][] } -\def\doquadrupleemptyfournormal #1#2#3#4{#1[{#2}][{#3}][{#4}][]} +\def\syst_helpers_quadruple_empty_two_spaced #1#2{#1[{#2}][][][] } +\def\syst_helpers_quadruple_empty_two_normal #1#2{#1[{#2}][][][]} +\def\syst_helpers_quadruple_empty_three_spaced #1#2#3{#1[{#2}][{#3}][][] } +\def\syst_helpers_quadruple_empty_three_normal #1#2#3{#1[{#2}][{#3}][][]} +\def\syst_helpers_quadruple_empty_four_spaced #1#2#3#4{#1[{#2}][{#3}][{#4}][] } +\def\syst_helpers_quadruple_empty_four_normal #1#2#3#4{#1[{#2}][{#3}][{#4}][]} %D Five: \unexpanded\def\doquintupleempty#1% - {\noshowargumenterror + {\syst_helpers_argument_reset \doifnextoptionalelse - {\doquintupleemptyYESone#1}% - {\doquintupleemptyNOPone#1}} + {\syst_helpers_quintuple_empty_one_yes#1}% + {\syst_helpers_quintuple_empty_one_nop#1}} -\def\doquintupleemptyYESone#1[#2]% +\def\syst_helpers_quintuple_empty_one_yes#1[#2]% {\firstargumenttrue \doifnextoptionalelse - {\doquintupleemptyYEStwo#1{#2}}% - {\doquintupleemptyNOPtwo#1{#2}}} + {\syst_helpers_quintuple_empty_two_yes#1{#2}}% + {\syst_helpers_quintuple_empty_two_nop#1{#2}}} -\def\doquintupleemptyYEStwo#1#2[#3]% +\def\syst_helpers_quintuple_empty_two_yes#1#2[#3]% {\secondargumenttrue \doifnextoptionalelse - {\doquintupleemptyYESthree#1{#2}{#3}}% - {\doquintupleemptyNOPthree#1{#2}{#3}}} + {\syst_helpers_quintuple_empty_three_yes#1{#2}{#3}}% + {\syst_helpers_quintuple_empty_three_nop#1{#2}{#3}}} -\def\doquintupleemptyYESthree#1#2#3[#4]% +\def\syst_helpers_quintuple_empty_three_yes#1#2#3[#4]% {\thirdargumenttrue \doifnextoptionalelse - {\doquintupleemptyYESfour#1{#2}{#3}{#4}}% - {\doquintupleemptyNOPfour#1{#2}{#3}{#4}}} + {\syst_helpers_quintuple_empty_four_yes#1{#2}{#3}{#4}}% + {\syst_helpers_quintuple_empty_four_nop#1{#2}{#3}{#4}}} -\def\doquintupleemptyYESfour#1#2#3#4[#5]% +\def\syst_helpers_quintuple_empty_four_yes#1#2#3#4[#5]% {\fourthargumenttrue \doifnextoptionalelse {\fifthargumenttrue#1[{#2}][{#3}][{#4}][{#5}]}% - {\doquintupleemptyNOPfive#1{#2}{#3}{#4}{#5}}} + {\syst_helpers_quintuple_empty_five_nop#1{#2}{#3}{#4}{#5}}} -\def\doquintupleemptyNOPone#1% +\def\syst_helpers_quintuple_empty_one_nop#1% {\firstargumentfalse \secondargumentfalse \thirdargumentfalse @@ -2268,92 +2308,92 @@ \fifthargumentfalse #1[][][][][]} -\def\doquintupleemptyNOPtwo +\def\syst_helpers_quintuple_empty_two_nop {\secondargumentfalse \thirdargumentfalse \fourthargumentfalse \fifthargumentfalse \if_next_blank_space_token - \expandafter\doquintupleemptytwospaced + \expandafter\syst_helpers_quintuple_empty_two_spaced \else - \expandafter\doquintupleemptytwonormal + \expandafter\syst_helpers_quintuple_empty_two_normal \fi} -\def\doquintupleemptyNOPthree +\def\syst_helpers_quintuple_empty_three_nop {\thirdargumentfalse \fourthargumentfalse \fifthargumentfalse \if_next_blank_space_token - \expandafter\doquintupleemptythreespaced + \expandafter\syst_helpers_quintuple_empty_three_spaced \else - \expandafter\doquintupleemptythreenormal + \expandafter\syst_helpers_quintuple_empty_three_normal \fi} -\def\doquintupleemptyNOPfour +\def\syst_helpers_quintuple_empty_four_nop {\fourthargumentfalse \fifthargumentfalse \if_next_blank_space_token - \expandafter\doquintupleemptyfourspaced + \expandafter\syst_helpers_quintuple_empty_four_spaced \else - \expandafter\doquintupleemptyfournormal + \expandafter\syst_helpers_quintuple_empty_four_normal \fi} -\def\doquintupleemptyNOPfive +\def\syst_helpers_quintuple_empty_five_nop {\fifthargumentfalse \if_next_blank_space_token - \expandafter\doquintupleemptyfivespaced + \expandafter\syst_helpers_quintuple_empty_five_spaced \else - \expandafter\doquintupleemptyfivenormal + \expandafter\syst_helpers_quintuple_empty_five_normal \fi} -\def\doquintupleemptytwospaced #1#2{#1[{#2}][][][][] } -\def\doquintupleemptytwonormal #1#2{#1[{#2}][][][][]} -\def\doquintupleemptythreespaced #1#2#3{#1[{#2}][{#3}][][][] } -\def\doquintupleemptythreenormal #1#2#3{#1[{#2}][{#3}][][][]} -\def\doquintupleemptyfourspaced #1#2#3#4{#1[{#2}][{#3}][{#4}][][] } -\def\doquintupleemptyfournormal #1#2#3#4{#1[{#2}][{#3}][{#4}][][]} -\def\doquintupleemptyfivespaced #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][] } -\def\doquintupleemptyfivenormal #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][]} +\def\syst_helpers_quintuple_empty_two_spaced #1#2{#1[{#2}][][][][] } +\def\syst_helpers_quintuple_empty_two_normal #1#2{#1[{#2}][][][][]} +\def\syst_helpers_quintuple_empty_three_spaced #1#2#3{#1[{#2}][{#3}][][][] } +\def\syst_helpers_quintuple_empty_three_normal #1#2#3{#1[{#2}][{#3}][][][]} +\def\syst_helpers_quintuple_empty_four_spaced #1#2#3#4{#1[{#2}][{#3}][{#4}][][] } +\def\syst_helpers_quintuple_empty_four_normal #1#2#3#4{#1[{#2}][{#3}][{#4}][][]} +\def\syst_helpers_quintuple_empty_five_spaced #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][] } +\def\syst_helpers_quintuple_empty_five_normal #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][]} %D Six \unexpanded\def\dosixtupleempty#1% - {\noshowargumenterror + {\syst_helpers_argument_reset \doifnextoptionalelse - {\dosixtupleemptyYESone#1} - {\dosixtupleemptyNOPone#1}} + {\syst_helpers_sixtuple_empty_one_yes#1} + {\syst_helpers_sixtuple_empty_one_nop#1}} -\def\dosixtupleemptyYESone#1[#2]% +\def\syst_helpers_sixtuple_empty_one_yes#1[#2]% {\firstargumenttrue \doifnextoptionalelse - {\dosixtupleemptyYEStwo#1{#2}}% - {\dosixtupleemptyNOPtwo#1{#2}}} + {\syst_helpers_sixtuple_empty_two_yes#1{#2}}% + {\syst_helpers_sixtuple_empty_two_nop#1{#2}}} -\def\dosixtupleemptyYEStwo#1#2[#3]% +\def\syst_helpers_sixtuple_empty_two_yes#1#2[#3]% {\secondargumenttrue \doifnextoptionalelse - {\dosixtupleemptyYESthree#1{#2}{#3}}% - {\dosixtupleemptyNOPthree#1{#2}{#3}}} + {\syst_helpers_sixtuple_empty_three_yes#1{#2}{#3}}% + {\syst_helpers_sixtuple_empty_three_nop#1{#2}{#3}}} -\def\dosixtupleemptyYESthree#1#2#3[#4]% +\def\syst_helpers_sixtuple_empty_three_yes#1#2#3[#4]% {\thirdargumenttrue \doifnextoptionalelse - {\dosixtupleemptyYESfour#1{#2}{#3}{#4}}% - {\dosixtupleemptyNOPfour#1{#2}{#3}{#4}}} + {\syst_helpers_sixtuple_empty_four_yes#1{#2}{#3}{#4}}% + {\syst_helpers_sixtuple_empty_four_nop#1{#2}{#3}{#4}}} -\def\dosixtupleemptyYESfour#1#2#3#4[#5]% +\def\syst_helpers_sixtuple_empty_four_yes#1#2#3#4[#5]% {\fourthargumenttrue \doifnextoptionalelse - {\dosixtupleemptyYESfive#1{#2}{#3}{#4}{#5}}% - {\dosixtupleemptyNOPfive#1{#2}{#3}{#4}{#5}}} + {\syst_helpers_sixtuple_empty_five_yes#1{#2}{#3}{#4}{#5}}% + {\syst_helpers_sixtuple_empty_five_nop#1{#2}{#3}{#4}{#5}}} -\def\dosixtupleemptyYESfive#1#2#3#4#5[#6]% +\def\syst_helpers_sixtuple_empty_five_yes#1#2#3#4#5[#6]% {\fifthargumenttrue \doifnextoptionalelse {\sixthargumenttrue#1[{#2}][{#3}][{#4}][{#5}][{#6}]}% - {\dosixtupleemptyNOPsix#1{#2}{#3}{#4}{#5}{#6}}} + {\syst_helpers_sixtuple_empty_six_nop#1{#2}{#3}{#4}{#5}{#6}}} -\def\dosixemptyNOPone#1% +\def\syst_helpers_sixtuple_empty_one_nop#1% {\firstargumentfalse \secondargumentfalse \thirdargumentfalse @@ -2362,112 +2402,112 @@ \sixthargumentfalse #1[][][][][][]} -\def\dosixtupleemptyNOPtwo +\def\syst_helpers_sixtuple_empty_two_nop {\secondargumentfalse \thirdargumentfalse \fourthargumentfalse \fifthargumentfalse \sixthargumentfalse \if_next_blank_space_token - \expandafter\dosixemptytwospaced + \expandafter\syst_helpers_sixtuple_empty_two_spaced \else - \expandafter\dosixemptytwonormal + \expandafter\syst_helpers_sixtuple_empty_two_normal \fi} -\def\dosixtupleemptyNOPthree +\def\syst_helpers_sixtuple_empty_three_nop {\thirdargumentfalse \fourthargumentfalse \fifthargumentfalse \sixthargumentfalse \if_next_blank_space_token - \expandafter\dosixemptythreespaced + \expandafter\syst_helpers_sixtuple_empty_three_spaced \else - \expandafter\dosixemptythreenormal + \expandafter\syst_helpers_sixtuple_empty_three_normal \fi} -\def\dosixtupleemptyNOPfour +\def\syst_helpers_sixtuple_empty_four_nop {\fourthargumentfalse \fifthargumentfalse \sixthargumentfalse \if_next_blank_space_token - \expandafter\dosixemptyfourspaced + \expandafter\syst_helpers_sixtuple_empty_four_spaced \else - \expandafter\dosixemptyfournormal + \expandafter\syst_helpers_sixtuple_empty_four_normal \fi} -\def\dosixtupleemptyNOPfive +\def\syst_helpers_sixtuple_empty_five_nop {\fifthargumentfalse \sixthargumentfalse \if_next_blank_space_token - \expandafter\dosixemptyfivespaced + \expandafter\syst_helpers_sixtuple_empty_five_spaced \else - \expandafter\dosixemptyfivenormal + \expandafter\syst_helpers_sixtuple_empty_five_normal \fi} -\def\dosixtupleemptyNOPsix +\def\syst_helpers_sixtuple_empty_six_nop {\sixthargumentfalse \if_next_blank_space_token - \expandafter\dosixemptysixspaced + \expandafter\syst_helpers_sixtuple_empty_six_spaced \else - \expandafter\dosixemptysixnormal + \expandafter\syst_helpers_sixtuple_empty_six_normal \fi} -\def\dosixemptytwospaced #1#2{#1[{#2}][][][][][] } -\def\dosixemptytwonormal #1#2{#1[{#2}][][][][][]} -\def\dosixemptythreespaced #1#2#3{#1[{#2}][{#3}][][][][] } -\def\dosixemptythreenormal #1#2#3{#1[{#2}][{#3}][][][][]} -\def\dosixemptyfourspaced #1#2#3#4{#1[{#2}][{#3}][{#4}][][][] } -\def\dosixemptyfournormal #1#2#3#4{#1[{#2}][{#3}][{#4}][][][]} -\def\dosixemptyfivespaced #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][][] } -\def\dosixemptyfivenormal #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][][]} -\def\dosixemptysixspaced #1#2#3#4#5#6{#1[{#2}][{#3}][{#4}][{#5}][{#6}][] } -\def\dosixemptysixnormal #1#2#3#4#5#6{#1[{#2}][{#3}][{#4}][{#5}][{#6}][]} +\def\syst_helpers_sixtuple_empty_two_spaced #1#2{#1[{#2}][][][][][] } +\def\syst_helpers_sixtuple_empty_two_normal #1#2{#1[{#2}][][][][][]} +\def\syst_helpers_sixtuple_empty_three_spaced #1#2#3{#1[{#2}][{#3}][][][][] } +\def\syst_helpers_sixtuple_empty_three_normal #1#2#3{#1[{#2}][{#3}][][][][]} +\def\syst_helpers_sixtuple_empty_four_spaced #1#2#3#4{#1[{#2}][{#3}][{#4}][][][] } +\def\syst_helpers_sixtuple_empty_four_normal #1#2#3#4{#1[{#2}][{#3}][{#4}][][][]} +\def\syst_helpers_sixtuple_empty_five_spaced #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][][] } +\def\syst_helpers_sixtuple_empty_five_normal #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][][]} +\def\syst_helpers_sixtuple_empty_six_spaced #1#2#3#4#5#6{#1[{#2}][{#3}][{#4}][{#5}][{#6}][] } +\def\syst_helpers_sixtuple_empty_six_normal #1#2#3#4#5#6{#1[{#2}][{#3}][{#4}][{#5}][{#6}][]} %D Seven: \unexpanded\def\doseventupleempty#1% - {\noshowargumenterror + {\syst_helpers_argument_reset \doifnextoptionalelse - {\doseventupleemptyYESone#1}% - {\doseventupleemptyNOPone#1}} + {\syst_helpers_seventuple_empty_one_yes#1}% + {\syst_helpers_seventuple_empty_one_nop#1}} -\def\doseventupleemptyYESone#1[#2]% +\def\syst_helpers_seventuple_empty_one_yes#1[#2]% {\firstargumenttrue \doifnextoptionalelse - {\doseventupleemptyYEStwo#1{#2}}% - {\doseventupleemptyNOPtwo#1{#2}}} + {\syst_helpers_seventuple_empty_two_yes#1{#2}}% + {\syst_helpers_seventuple_empty_two_nop#1{#2}}} -\def\doseventupleemptyYEStwo#1#2[#3]% +\def\syst_helpers_seventuple_empty_two_yes#1#2[#3]% {\secondargumenttrue \doifnextoptionalelse - {\doseventupleemptyYESthree#1{#2}{#3}}% - {\doseventupleemptyNOPthree#1{#2}{#3}}} + {\syst_helpers_seventuple_empty_three_yes#1{#2}{#3}}% + {\syst_helpers_seventuple_empty_three_nop#1{#2}{#3}}} -\def\doseventupleemptyYESthree#1#2#3[#4]% +\def\syst_helpers_seventuple_empty_three_yes#1#2#3[#4]% {\thirdargumenttrue \doifnextoptionalelse - {\doseventupleemptyYESfour#1{#2}{#3}{#4}}% - {\doseventupleemptyNOPfour#1{#2}{#3}{#4}}} + {\syst_helpers_seventuple_empty_four_yes#1{#2}{#3}{#4}}% + {\syst_helpers_seventuple_empty_four_nop#1{#2}{#3}{#4}}} -\def\doseventupleemptyYESfour#1#2#3#4[#5]% +\def\syst_helpers_seventuple_empty_four_yes#1#2#3#4[#5]% {\fourthargumenttrue \doifnextoptionalelse - {\doseventupleemptyYESfive#1{#2}{#3}{#4}{#5}}% - {\doseventupleemptyNOPfive#1{#2}{#3}{#4}{#5}}} + {\syst_helpers_seventuple_empty_five_yes#1{#2}{#3}{#4}{#5}}% + {\syst_helpers_seventuple_empty_five_nop#1{#2}{#3}{#4}{#5}}} -\def\doseventupleemptyYESfive#1#2#3#4#5[#6]% +\def\syst_helpers_seventuple_empty_five_yes#1#2#3#4#5[#6]% {\fifthargumenttrue \doifnextoptionalelse - {\doseventupleemptyYESsix#1{#2}{#3}{#4}{#5}{#6}}% - {\doseventupleemptyNOPsix#1{#2}{#3}{#4}{#5}{#6}}} + {\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\doseventupleemptyYESsix#1#2#3#4#5#6[#7]% +\def\syst_helpers_seventuple_empty_six_yes#1#2#3#4#5#6[#7]% {\sixthargumenttrue \doifnextoptionalelse {\seventhargumenttrue#1[{#2}][{#3}][{#4}][{#5}][{#6}][{#7}]}% - {\doseventupleemptyNOPseven#1{#2}{#3}{#4}{#5}{#6}{#7}}} + {\syst_helpers_seventuple_empty_seven_nop#1{#2}{#3}{#4}{#5}{#6}{#7}}} -\def\dosevenemptyNOPone#1% +\def\syst_helpers_seventuple_empty_one_nop#1% {\firstargumentfalse \secondargumentfalse \thirdargumentfalse @@ -2477,7 +2517,7 @@ \seventhargumentfalse #1[][][][][][][]} -\def\doseventupleemptyNOPtwo +\def\syst_helpers_seventuple_empty_two_nop {\secondargumentfalse \thirdargumentfalse \fourthargumentfalse @@ -2485,73 +2525,81 @@ \sixthargumentfalse \seventhargumentfalse \if_next_blank_space_token - \expandafter\dosevenemptytwospaced + \expandafter\syst_helpers_seventuple_empty_two_spaced \else - \expandafter\dosevenemptytwonormal + \expandafter\syst_helpers_seventuple_empty_two_normal \fi} -\def\doseventupleemptyNOPthree +\def\syst_helpers_seventuple_empty_three_nop {\thirdargumentfalse \fourthargumentfalse \fifthargumentfalse \sixthargumentfalse \seventhargumentfalse \if_next_blank_space_token - \expandafter\dosevenemptythreespaced + \expandafter\syst_helpers_seventuple_empty_three_spaced \else - \expandafter\dosevenemptythreenormal + \expandafter\syst_helpers_seventuple_empty_three_normal \fi} -\def\doseventupleemptyNOPfour +\def\syst_helpers_seventuple_empty_four_nop {\fourthargumentfalse \fifthargumentfalse \sixthargumentfalse \seventhargumentfalse \if_next_blank_space_token - \expandafter\dosevenemptyfourspaced + \expandafter\syst_helpers_seventuple_empty_four_spaced \else - \expandafter\dosevenemptyfournormal + \expandafter\syst_helpers_seventuple_empty_four_normal \fi} -\def\doseventupleemptyNOPfive +\def\syst_helpers_seventuple_empty_five_nop {\fifthargumentfalse \sixthargumentfalse \seventhargumentfalse \if_next_blank_space_token - \expandafter\dosevenemptyfivespaced + \expandafter\syst_helpers_seventuple_empty_five_spaced \else - \expandafter\dosevenemptyfivenormal + \expandafter\syst_helpers_seventuple_empty_five_normal \fi} -\def\doseventupleemptyNOPsix +\def\syst_helpers_seventuple_empty_six_nop {\sixthargumentfalse \seventhargumentfalse \if_next_blank_space_token - \expandafter\dosevenemptysixspaced + \expandafter\syst_helpers_seventuple_empty_six_spaced \else - \expandafter\dosevenemptysixnormal + \expandafter\syst_helpers_seventuple_empty_six_normal \fi} -\def\doseventupleemptyNOPseven +\def\syst_helpers_seventuple_empty_seven_nop {\seventhargumentfalse \if_next_blank_space_token - \expandafter\dosevenemptysevenspaced - \else - \expandafter\dosevenemptysevennormal - \fi} - -\def\dosevenemptytwospaced #1#2{#1[{#2}][][][][][][] } -\def\dosevenemptytwonormal #1#2{#1[{#2}][][][][][][]} -\def\dosevenemptythreespaced #1#2#3{#1[{#2}][{#3}][][][][][] } -\def\dosevenemptythreenormal #1#2#3{#1[{#2}][{#3}][][][][][]} -\def\dosevenemptyfourspaced #1#2#3#4{#1[{#2}][{#3}][{#4}][][][][] } -\def\dosevenemptyfournormal #1#2#3#4{#1[{#2}][{#3}][{#4}][][][][]} -\def\dosevenemptyfivespaced #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][][][] } -\def\dosevenemptyfivenormal #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][][][]} -\def\dosevenemptysixspaced #1#2#3#4#5#6{#1[{#2}][{#3}][{#4}][{#5}][{#6}][][] } -\def\dosevenemptysixnormal #1#2#3#4#5#6{#1[{#2}][{#3}][{#4}][{#5}][{#6}][][]} -\def\dosevenemptysevenspaced#1#2#3#4#5#6#7{#1[{#2}][{#3}][{#4}][{#5}][{#6}][{#7}][] } -\def\dosevenemptysevennormal#1#2#3#4#5#6#7{#1[{#2}][{#3}][{#4}][{#5}][{#6}][{#7}][]} + \expandafter\syst_helpers_seventuple_empty_seven_spaced + \else + \expandafter\syst_helpers_seventuple_empty_seven_normal + \fi} + +\def\syst_helpers_seventuple_empty_two_spaced #1#2{#1[{#2}][][][][][][] } +\def\syst_helpers_seventuple_empty_two_normal #1#2{#1[{#2}][][][][][][]} +\def\syst_helpers_seventuple_empty_three_spaced #1#2#3{#1[{#2}][{#3}][][][][][] } +\def\syst_helpers_seventuple_empty_three_normal #1#2#3{#1[{#2}][{#3}][][][][][]} +\def\syst_helpers_seventuple_empty_four_spaced #1#2#3#4{#1[{#2}][{#3}][{#4}][][][][] } +\def\syst_helpers_seventuple_empty_four_normal #1#2#3#4{#1[{#2}][{#3}][{#4}][][][][]} +\def\syst_helpers_seventuple_empty_five_spaced #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][][][] } +\def\syst_helpers_seventuple_empty_five_normal #1#2#3#4#5{#1[{#2}][{#3}][{#4}][{#5}][][][]} +\def\syst_helpers_seventuple_empty_six_spaced #1#2#3#4#5#6{#1[{#2}][{#3}][{#4}][{#5}][{#6}][][] } +\def\syst_helpers_seventuple_empty_six_normal #1#2#3#4#5#6{#1[{#2}][{#3}][{#4}][{#5}][{#6}][][]} +\def\syst_helpers_seventuple_empty_seven_spaced#1#2#3#4#5#6#7{#1[{#2}][{#3}][{#4}][{#5}][{#6}][{#7}][] } +\def\syst_helpers_seventuple_empty_seven_normal#1#2#3#4#5#6#7{#1[{#2}][{#3}][{#4}][{#5}][{#6}][{#7}][]} + +\let\dosingleargument \dosingleempty +\let\dodoubleargument \dodoubleempty +\let\dotripleargument \dotripleempty +\let\doquadrupleargument \doquadrupleempty +\let\doquintupleargument \doquintupleempty +\let\dosixtupleargument \dosixtupleempty +\let\doseventupleargument\doseventupleempty %D \macros %D {strippedcsname} @@ -2628,22 +2676,20 @@ %D worthwile to offer two more alternatives. Watch the build %D in protection. -\def\docomplexorsimple#1#2% +\unexpanded\def\syst_helpers_complex_or_simple#1#2% {\doifnextoptionalelse{\firstargumenttrue#1}{\firstargumentfalse#2}} -\def\docomplexorsimpleempty#1% +\unexpanded\def\syst_helpers_complex_or_simple_empty#1% {\doifnextoptionalelse{\firstargumenttrue#1}{\firstargumentfalse#1[]}} \unexpanded\def\definecomplexorsimple#1% - {\unexpanded\edef#1% - {\noexpand\docomplexorsimple - \expandafter\noexpand\csname\s!complex\strippedcsname#1\endcsname - \expandafter\noexpand\csname\s!simple \strippedcsname#1\endcsname}} + {\unexpanded\edef#1{\syst_helpers_complex_or_simple + \expandafter\noexpand\csname\s!complex\strippedcsname#1\endcsname + \expandafter\noexpand\csname\s!simple \strippedcsname#1\endcsname}} \unexpanded\def\definecomplexorsimpleempty#1% - {\unexpanded\edef#1% - {\noexpand\docomplexorsimpleempty - \expandafter\noexpand\csname\s!complex\strippedcsname#1\endcsname}} + {\unexpanded\edef#1{\syst_helpers_complex_or_simple_empty + \expandafter\noexpand\csname\s!complex\strippedcsname#1\endcsname}} %D These commands are called as: %D @@ -2679,8 +2725,10 @@ %D We can add additional definitions later when we have defined %D \type {\appendtoks}. -\def \permitspacesbetweengroups{\let\@@permitspacesbetweengroups\zerocount} -\def\dontpermitspacesbetweengroups{\let\@@permitspacesbetweengroups\plusone} +\newconditional\c_syst_helpers_permit_spaces_between_groups + +\unexpanded\def \permitspacesbetweengroups{\settrue \c_syst_helpers_permit_spaces_between_groups} +\unexpanded\def\dontpermitspacesbetweengroups{\setfalse\c_syst_helpers_permit_spaces_between_groups} \dontpermitspacesbetweengroups @@ -2689,94 +2737,94 @@ %D potentially being an \type {conditional} token. Okay, these macros %D are not called that often but it saves crap when tracing. -\def\dodogetgroupargument +\unexpanded\def\syst_helpers_get_grouped_argument#1#2% + {\let\syst_helpers_get_grouped_argument_yes#1% + \let\syst_helpers_get_grouped_argument_nop#2% + \futurelet\nextargument\syst_helpers_get_grouped_argument_indeed} + +\def\syst_helpers_get_grouped_argument_indeed {\ifx\nextargument\bgroup - \expandafter\dodogetgroupargumentA + \expandafter\syst_helpers_get_grouped_argument_a \else - \expandafter\dodogetgroupargumentB + \expandafter\syst_helpers_get_grouped_argument_b \fi} -\def\dodogetgroupargumentA - {\noshowargumenterror - \dogroupargumentyes\dodogetargument} +\def\syst_helpers_get_grouped_argument_a + {\syst_helpers_argument_reset + \syst_helpers_get_grouped_argument_yes\syst_helpers_get_grouped_argument_nested} -\def\dodogetgroupargumentB - {\ifcase\@@permitspacesbetweengroups - \expandafter\dodogetgroupargumentF +\def\syst_helpers_get_grouped_argument_b + {\ifconditional\c_syst_helpers_permit_spaces_between_groups + \expandafter\syst_helpers_get_grouped_argument_f \else - \expandafter\dodogetgroupargumentD + \expandafter\syst_helpers_get_grouped_argument_d \fi} -\def\dodogetgroupargumentD - {\doshowargumenterror - \dogroupargumentnop\dodogetargument{}} +\def\syst_helpers_get_grouped_argument_d + {\syst_helpers_argument_error + \syst_helpers_get_grouped_argument_nop\syst_helpers_get_grouped_argument_nested{}} \begingroup - \def\\ {\dogetgroupargument\dogroupargumentyes\dogroupargumentnop} - \global\let\dodogetgroupargumentE\\ + \def\\ {\syst_helpers_get_grouped_argument\syst_helpers_get_grouped_argument_yes\syst_helpers_get_grouped_argument_nop} + \global\let\syst_helpers_get_grouped_argument_e\\ \endgroup -\def\dodogetgroupargumentF +\def\syst_helpers_get_grouped_argument_f {\ifx\nextargument\blankspace - \expandafter\dodogetgroupargumentE % G + \expandafter\syst_helpers_get_grouped_argument_e % g \else - \expandafter\dodogetgroupargumentD % H + \expandafter\syst_helpers_get_grouped_argument_d % h \fi} -\def\dogetgroupargument#1#2% - {\let\dogroupargumentyes#1% - \let\dogroupargumentnop#2% - \futurelet\nextargument\dodogetgroupargument} - \def\dosinglegroupempty#1% - {\def\dodogetargument% + {\def\syst_helpers_get_grouped_argument_nested {\dontpermitspacesbetweengroups #1}% - \dogetgroupargument\firstargumenttrue\firstargumentfalse} + \syst_helpers_get_grouped_argument\firstargumenttrue\firstargumentfalse} \def\dodoublegroupempty#1% - {\def\dodogetargument##1% - {\def\dodogetargument% + {\def\syst_helpers_get_grouped_argument_nested##1% + {\def\syst_helpers_get_grouped_argument_nested {\dontpermitspacesbetweengroups #1{##1}}% - \dogetgroupargument\secondargumenttrue\secondargumentfalse}% - \dogetgroupargument\firstargumenttrue\firstargumentfalse} + \syst_helpers_get_grouped_argument\secondargumenttrue\secondargumentfalse}% + \syst_helpers_get_grouped_argument\firstargumenttrue\firstargumentfalse} \def\dotriplegroupempty#1% - {\def\dodogetargument##1% - {\def\dodogetargument####1% - {\def\dodogetargument% + {\def\syst_helpers_get_grouped_argument_nested##1% + {\def\syst_helpers_get_grouped_argument_nested####1% + {\def\syst_helpers_get_grouped_argument_nested {\dontpermitspacesbetweengroups #1{##1}{####1}}% - \dogetgroupargument\thirdargumenttrue\thirdargumentfalse}% - \dogetgroupargument\secondargumenttrue\secondargumentfalse}% - \dogetgroupargument\firstargumenttrue\firstargumentfalse} + \syst_helpers_get_grouped_argument\thirdargumenttrue\thirdargumentfalse}% + \syst_helpers_get_grouped_argument\secondargumenttrue\secondargumentfalse}% + \syst_helpers_get_grouped_argument\firstargumenttrue\firstargumentfalse} \def\doquadruplegroupempty#1% - {\def\dodogetargument##1% - {\def\dodogetargument####1% - {\def\dodogetargument########1% - {\def\dodogetargument% + {\def\syst_helpers_get_grouped_argument_nested##1% + {\def\syst_helpers_get_grouped_argument_nested####1% + {\def\syst_helpers_get_grouped_argument_nested########1% + {\def\syst_helpers_get_grouped_argument_nested {\dontpermitspacesbetweengroups #1{##1}{####1}{########1}}% - \dogetgroupargument\fourthargumenttrue\fourthargumentfalse}% - \dogetgroupargument\thirdargumenttrue\thirdargumentfalse}% - \dogetgroupargument\secondargumenttrue\secondargumentfalse}% - \dogetgroupargument\firstargumenttrue\firstargumentfalse} + \syst_helpers_get_grouped_argument\fourthargumenttrue\fourthargumentfalse}% + \syst_helpers_get_grouped_argument\thirdargumenttrue\thirdargumentfalse}% + \syst_helpers_get_grouped_argument\secondargumenttrue\secondargumentfalse}% + \syst_helpers_get_grouped_argument\firstargumenttrue\firstargumentfalse} \def\doquintuplegroupempty#1% - {\def\dodogetargument##1% - {\def\dodogetargument####1% - {\def\dodogetargument########1% - {\def\dodogetargument################1% - {\def\dodogetargument% + {\def\syst_helpers_get_grouped_argument_nested##1% + {\def\syst_helpers_get_grouped_argument_nested####1% + {\def\syst_helpers_get_grouped_argument_nested########1% + {\def\syst_helpers_get_grouped_argument_nested################1% + {\def\syst_helpers_get_grouped_argument_nested {\dontpermitspacesbetweengroups #1{##1}{####1}{########1}{################1}}% - \dogetgroupargument\fifthargumenttrue\fifthargumentfalse}% - \dogetgroupargument\fourthargumenttrue\fourthargumentfalse}% - \dogetgroupargument\thirdargumenttrue\thirdargumentfalse}% - \dogetgroupargument\secondargumenttrue\secondargumentfalse}% - \dogetgroupargument\firstargumenttrue\firstargumentfalse} + \syst_helpers_get_grouped_argument\fifthargumenttrue\fifthargumentfalse}% + \syst_helpers_get_grouped_argument\fourthargumenttrue\fourthargumentfalse}% + \syst_helpers_get_grouped_argument\thirdargumenttrue\thirdargumentfalse}% + \syst_helpers_get_grouped_argument\secondargumenttrue\secondargumentfalse}% + \syst_helpers_get_grouped_argument\firstargumenttrue\firstargumentfalse} %D These macros can explictly take care of spaces, which means %D that the next definition and calls are valid: @@ -2857,7 +2905,7 @@ %D nesting is to be expected, we can reuse \type{\wait} within %D \type{\wait} itself. -\def\wait +\unexpanded\def\wait {\begingroup \read16 to \wait \endgroup} @@ -2888,24 +2936,24 @@ \newtoks\everywritestring - \def\writedirect {\immediate\write\statuswrite} - \def\writeline {\writedirect{}} - \def\writestring#1{\begingroup\the\everywritestring\writedirect{#1}\endgroup} + \def\writedirect {\immediate\write\statuswrite} + \def\writeline {\writedirect{}} + \unexpanded\def\writestring#1{\begingroup\the\everywritestring\writedirect{#1}\endgroup} \fi -\def\normalwritestatus#1#2% - {\writestring{\expandafter\dosplitstatus\expandafter\statuswidth#1% +\unexpanded\def\normalwritestatus#1#2% + {\writestring{\expandafter\syst_helpers_split_status_yes\expandafter\statuswidth#1% \space\space\space\space\space\space\space \space\space\space\space\space\space\space \space\space\space\space\space\space\end \space:\space#2}} -\def\dosplitstatus#1#2% - {\ifcase#1 \expandafter\nosplitstatus\fi#2% - \expandafter\dosplitstatus\expandafter{\the\numexpr#1+\minusone\relax}} +\def\syst_helpers_split_status_yes#1#2% + {\ifcase#1 \expandafter\syst_helpers_split_status_nop\fi#2% + \expandafter\syst_helpers_split_status_yes\expandafter{\the\numexpr#1+\minusone\relax}} -\def\nosplitstatus#1\end +\def\syst_helpers_split_status_nop#1\end {} %D \macros @@ -2925,13 +2973,13 @@ \newif\ifdebuggerinfo -\def\debuggerinfo#1#2% +\unexpanded\def\debuggerinfo#1#2% {\ifdebuggerinfo \writestatus{debugger}{#1:: #2}% \fi} -\ifdefined\writestatus \else \let\writestatus\normalwritestatus \fi -\ifdefined\writebanner \else \def\writebanner{\writestring} \fi +\ifdefined\writestatus \else \let\writestatus\normalwritestatus \fi +\ifdefined\writebanner \else \unexpanded\def\writebanner{\writestring} \fi % % % % % % % % % % % % % % % % % % % % % % % % @@ -2941,13 +2989,13 @@ %D A raw and dirty alternative for \type {\getparameters}; no %D checking is done! -\def\rawsetparameter#1=#2,% +\unexpanded\def\rawsetparameter#1=#2,% {\if]#1\else \expandafter\def\csname\rawparameterprefix#1\endcsname{#2}% \expandafter\rawsetparameter \fi} -\def\rawgetparameters[#1][#2% some 5-10% faster +\unexpanded\def\rawgetparameters[#1][#2% some 5-10% faster {\ifx#2]% test is needed, else bomb on [#1][] \expandafter\gobbleoneargument \else @@ -2970,28 +3018,28 @@ %D \type {\redoglobal}. When using only alternatives, one can %D reset this mechanism with \type {\resetglobal}. -\def\resetglobal +\unexpanded\def\resetglobal {\let\redoglobal\relax \let\dodoglobal\relax} \resetglobal -\def\doglobal +\unexpanded\def\doglobal {\ifx\redoglobal\relax \let\redoglobal\global - \let\dodoglobal\@@dodoglobal + \let\dodoglobal\syst_helpers_dodo_global \fi} -\def\@@dodoglobal +\def\syst_helpers_dodo_global {\resetglobal\global} \def\saveglobal - {\let\@@dodoglobal\dodoglobal - \let\@@redoglobal\redoglobal} + {\let\syst_helpers_dodo_global\dodoglobal + \let\syst_helpers_redo_global\redoglobal} \def\restoreglobal - {\let\redoglobal\@@redoglobal - \let\dodoglobal\@@dodoglobal} + {\let\redoglobal\syst_helpers_redo_global + \let\dodoglobal\syst_helpers_dodo_global} %D A very useful application of this macro is \type {\newif}, %D \TEX's fake boolean type. Not being a primitive, @@ -3034,7 +3082,7 @@ \unexpanded\expandafter\def \fi#1} -\def\redefine#1% +\unexpanded\def\redefine#1% {\ifdefined#1% \message{[\noexpand#1is redefined]}% \fi @@ -3062,76 +3110,46 @@ % % [\test] -% todo: pick up keywords: -% -% \starttexdefinition unexpanded bagger .... - -% \bgroup \obeylines -% -% \gdef\starttexdefinition% -% {\bgroup% -% \obeylines% -% \dostarttexdefinition} -% -% \gdef\dostarttexdefinition #1 -% {\catcode\endoflineasciicode\ignorecatcode% -% \doifinstringelse\letterhash{\detokenize{#1}}\dodostarttexdefinition\nonostarttexdefinition#1 -% } -% -% \gdef\dodostarttexdefinition#1 #2 -% {\dododostarttexdefinition{#1}{#2}} -% -% \gdef\dododostarttexdefinition#1#2#3\stoptexdefinition% -% {\egroup% -% \expandafter\def\csname#1\endcsname#2{#3}} -% -% \gdef\nonostarttexdefinition#1 -% {\nononostarttexdefinition{#1}{}} -% -% \gdef\nononostarttexdefinition#1#2#3\stoptexdefinition% -% {\egroup% -% \expandafter\def\csname#1\endcsname{#3}} -% -% \egroup - \def\s!unexpanded{unexpanded} \bgroup \obeylines -\gdef\starttexdefinition% +\global\let\stoptexdefinition\relax + +\unexpanded\gdef\starttexdefinition% {\bgroup% \obeylines% - \dostarttexdefinition} + \syst_helpers_start_tex_definition} -\gdef\dostarttexdefinition #1 +\gdef\syst_helpers_start_tex_definition #1 {\catcode\endoflineasciicode\ignorecatcode% - \doifinstringelse\letterhash{\detokenize{#1}}\dodostarttexdefinition\nonostarttexdefinition#1 + \doifinstringelse\letterhash{\detokenize{#1}}\syst_helpers_start_tex_definition_yes\syst_helpers_start_tex_definition_nop#1 } -\gdef\dodostarttexdefinition#1 #2 +\gdef\syst_helpers_start_tex_definition_yes#1 #2 {\edef\texdefinitionname{#1}% \ifx\texdefinitionname\s!unexpanded% - \expandafter\dododostarttexdefinitionU% + \expandafter\syst_helpers_start_tex_definition_yes_unexpanded% \else% - \expandafter\dododostarttexdefinitionN% + \expandafter\syst_helpers_start_tex_definition_yes_normal% \fi% {#1}#2 } -\gdef\dododostarttexdefinitionU#1#2 #3 +\gdef\syst_helpers_start_tex_definition_yes_unexpanded#1#2 #3 #4\stoptexdefinition% {\egroup% #1=unexpanded \unexpanded\expandafter\def\csname#2\endcsname#3{#4}} -\gdef\dododostarttexdefinitionN#1#2 +\gdef\syst_helpers_start_tex_definition_yes_normal#1#2 #3\stoptexdefinition% {\egroup% \expandafter\def\csname#1\endcsname#2{#3}} -\gdef\nonostarttexdefinition#1 - {\nononostarttexdefinition{#1}{}} +\gdef\syst_helpers_start_tex_definition_nop#1 + {\syst_helpers_start_tex_definition_nop_indeed{#1}{}} -\gdef\nononostarttexdefinition#1#2#3\stoptexdefinition% +\gdef\syst_helpers_start_tex_definition_nop_indeed#1#2#3\stoptexdefinition% {\egroup% \expandafter\def\csname#1\endcsname{#3}} @@ -3141,8 +3159,8 @@ % This is a first variant, more might be added: -\def\starttexcode{\unprotect} -\def\stoptexcode {\protect} +\unexpanded\def\starttexcode{\unprotect} +\unexpanded\def\stoptexcode {\protect} %D \macros %D {newcounter, @@ -3202,7 +3220,7 @@ \def\zerocountervalue{0} -\def\newcounter#1% +\unexpanded\def\newcounter#1% {\dodoglobal\let#1\zerocountervalue} %D Nowadays we don't mind a few more tokens if we can gain a @@ -3217,14 +3235,14 @@ \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\fastincrement#1{\dodoglobal\edef#1{\the\numexpr#1+\plusone \relax}} -\def\fastdecrement#1{\dodoglobal\edef#1{\the\numexpr#1+\minusone\relax}} +\unexpanded\def\fastincrement#1{\dodoglobal\edef#1{\the\numexpr#1+\plusone \relax}} +\unexpanded\def\fastdecrement#1{\dodoglobal\edef#1{\the\numexpr#1+\minusone\relax}} -\def\increment{\doifnextcharelse(\syst_helpers_do_do_increment\syst_helpers_do_increment} -\def\decrement{\doifnextcharelse(\syst_helpers_do_do_decrement\syst_helpers_do_decrement} +\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} -\def\incrementvalue#1{\expandafter\increment\csname#1\endcsname} -\def\decrementvalue#1{\expandafter\decrement\csname#1\endcsname} +\unexpanded\def\incrementvalue#1{\expandafter\increment\csname#1\endcsname} +\unexpanded\def\decrementvalue#1{\expandafter\decrement\csname#1\endcsname} %D \macros %D {newsignal} @@ -3245,9 +3263,9 @@ \newdimen\maximumsignal % step is about 0.00025pt -\def\newsignal#1% +\unexpanded\def\newsignal#1% {\ifdefined#1\else - \advance\maximumsignal 2sp % to be save in rounding + \advance\maximumsignal 2\scaledpoint % to be save in rounding \edef#1{\the\maximumsignal}% \fi} @@ -3262,9 +3280,9 @@ %D \stoptyping \def\checkedstrippedcsname#1% this permits \strippedcsname{\xxx} and \strippedcsname{xxx} - {\expandafter\docheckedstrippedcsname\string#1} + {\expandafter\syst_helpers_checked_stripped_csname\string#1} -\def\docheckedstrippedcsname#1% +\def\syst_helpers_checked_stripped_csname#1% {\if\noexpand#1\letterbackslash\else#1\fi} %D \macros @@ -3272,15 +3290,14 @@ %D %D We will use this one in: -\def\savenormalmeaning#1% +\unexpanded\def\savenormalmeaning#1% {\ifcsname normal\strippedcsname#1\endcsname \else - \letvalue{normal\strippedcsname#1}#1% + \expandafter\let\csname normal\strippedcsname#1\endcsname#1% \fi} %D \macros %D {dorecurse,recurselevel,recursedepth, -%D dostepwiserecurse, -%D for} +%D dostepwiserecurse} %D %D \TEX\ does not offer us powerfull for||loop mechanisms. On %D the other hand its recursion engine is quite unique. We @@ -3326,77 +3343,79 @@ \def\recursedepth{\the\outerrecurse} \def\recurselevel{0} -\let\nextrecurse\relax +\let\syst_helpers_stepwise_next\relax -\def\@@irecurse{@@ir@@} % ecurse} % stepper -\def\@@arecurse{@@ar@@} % ecurse} % action +\installsystemnamespace{recurseindex} +\installsystemnamespace{recurseaction} \unexpanded\def\dostepwiserecurse#1#2#3#4% can be made faster by postponing #4 {\global\advance\outerrecurse \plusone - \global\expandafter\def\csname\@@arecurse\recursedepth\endcsname{#4}% - \global\expandafter\let\csname\@@irecurse\recursedepth\endcsname\recurselevel - \ifnum#3>0\relax + \global\expandafter\def\csname\??recurseaction\recursedepth\endcsname{#4}% + \global\expandafter\let\csname\??recurseindex\recursedepth\endcsname\recurselevel + \ifnum#3>\zerocount\relax \ifnum#2<#1\relax - \let\nextrecurse\exitstepwiserecurse + \let\syst_helpers_stepwise_next\syst_helpers_stepwise_exit \else - \let\nextrecurse\dodostepwiserecurse + \let\syst_helpers_stepwise_next\syst_helpers_stepwise_recurse \fi \else - \ifnum#3<0\relax + \ifnum#3<\zerocount\relax \ifnum#1<#2\relax - \let\nextrecurse\exitstepwiserecurse + \let\syst_helpers_stepwise_next\syst_helpers_stepwise_exit \else - \let\nextrecurse\dodostepwisereverse + \let\syst_helpers_stepwise_next\syst_helpers_stepwise_reverse \fi \else - \let\nextrecurse\exitstepwiserecurse + \let\syst_helpers_stepwise_next\syst_helpers_stepwise_exit \fi - \fi\normalexpanded{\nextrecurse{\number#1}{\number#2}{\number#3}}} + \fi\normalexpanded{\syst_helpers_stepwise_next{\number#1}{\number#2}{\number#3}}} -\def\dodostepwiserecurse#1#2#3% from to step +\unexpanded\def\syst_helpers_stepwise_recurse#1#2#3% from to step {\ifnum#1>#2\relax - \expandafter\nodostepwiserecurse + \expandafter\syst_helpers_stepwise_recurse_nop \else \def\recurselevel{#1}% - \doubleexpandafter\redostepwiserecurse\expandafter + \doubleexpandafter\syst_helpers_stepwise_recurse_yes\expandafter \fi\expandafter{\the\numexpr\recurselevel+#3\relax}{#2}{#3}} -\unexpanded\def\expandrecursecontent - {\csname\@@arecurse\recursedepth\endcsname} +\unexpanded\def\syst_helpers_recurse_content + {\csname\??recurseaction\recursedepth\endcsname} -\unexpanded\def\redostepwiserecurse - {\expandrecursecontent\dodostepwiserecurse} +\unexpanded\def\syst_helpers_stepwise_recurse_yes + {\syst_helpers_recurse_content + \syst_helpers_stepwise_recurse} -\unexpanded\def\dodostepwisereverse#1#2#3% from to step +\unexpanded\def\syst_helpers_stepwise_reverse#1#2#3% from to step {\ifnum#1<#2\relax - \expandafter\nodostepwiserecurse + \expandafter\syst_helpers_stepwise_recurse_nop \else \def\recurselevel{#1}% \innerrecurse#1\relax \advance\innerrecurse#3\relax - \doubleexpandafter\redostepwisereverse\expandafter + \doubleexpandafter\syst_helpers_stepwise_reverse_yes\expandafter \fi\expandafter{\the\innerrecurse}{#2}{#3}} -\unexpanded\def\redostepwisereverse - {\expandrecursecontent\dodostepwisereverse} +\unexpanded\def\syst_helpers_stepwise_reverse_yes + {\syst_helpers_recurse_content + \syst_helpers_stepwise_reverse} -\unexpanded\def\exitstepwiserecurse - {\nodostepwiserecurse\relax} +\unexpanded\def\syst_helpers_stepwise_exit + {\syst_helpers_stepwise_recurse_nop\relax} -\unexpanded\def\nodostepwiserecurse#1#2#3#4% - {\expandafter\let\expandafter\recurselevel\csname\@@irecurse\recursedepth\endcsname - \global\advance\outerrecurse \minusone} +\unexpanded\def\syst_helpers_stepwise_recurse_nop#1#2#3#4% + {\expandafter\let\expandafter\recurselevel\csname\??recurseindex\recursedepth\endcsname + \global\advance\outerrecurse\minusone} -\unexpanded\def\nonostepwiserecurse#1#2#3% - {\expandafter\let\expandafter\recurselevel\csname\@@irecurse\recursedepth\endcsname - \global\advance\outerrecurse \minusone} +% \unexpanded\def\nonostepwiserecurse#1#2#3% +% {\expandafter\let\expandafter\recurselevel\csname\??recurseindex\recursedepth\endcsname +% \global\advance\outerrecurse\minusone} \unexpanded\def\dorecurse#1% - {\dostepwiserecurse1{#1}1} + {\dostepwiserecurse\plusone{#1}\plusone} -\def\doexpandedrecurse#1#2% +\def\doexpandedrecurse#1#2% user macro (also was \doxprecurse) {\ifnum#1>\zerocount - #2\expandafter\doexpandedrecurse\expandafter{\the\numexpr#1-1\relax}{#2}% + #2\expandafter\doexpandedrecurse\expandafter{\the\numexpr#1-\plusone\relax}{#2}% \fi} %D As we can see here, the simple command \type{\dorecurse} is @@ -3422,47 +3441,48 @@ {\ifcase#1\relax \expandafter\gobbletwoarguments \or - \expandafter\ydorecurse + \expandafter\syst_helpers_recurse_y \else - \expandafter\xdorecurse + \expandafter\syst_helpers_recurse_x \fi{#1}} -\unexpanded\def\xdorecurse#1#2% +\unexpanded\def\syst_helpers_recurse_x#1#2% {\global\advance\outerrecurse \plusone - \expandafter\gdef\csname\@@arecurse\recursedepth\endcsname{#2}% - \global\expandafter\let\csname\@@irecurse\recursedepth\endcsname\recurselevel - \expandafter\dodorecurse\expandafter1\expandafter{\number#1}} + \expandafter\gdef\csname\??recurseaction\recursedepth\endcsname{#2}% + \global\expandafter\let\csname\??recurseindex\recursedepth\endcsname\recurselevel + \expandafter\syst_helpers_recurse_indeed\expandafter1\expandafter{\number#1}} -\unexpanded\def\ydorecurse#1#2% +\unexpanded\def\syst_helpers_recurse_y#1#2% {\global\advance\outerrecurse \plusone - \global\expandafter\let\csname\@@irecurse\recursedepth\endcsname\recurselevel + \global\expandafter\let\csname\??recurseindex\recursedepth\endcsname\recurselevel \let\recurselevel\!!plusone #2% - \expandafter\let\expandafter\recurselevel\csname\@@irecurse\recursedepth\endcsname + \expandafter\let\expandafter\recurselevel\csname\??recurseindex\recursedepth\endcsname \global\advance\outerrecurse \minusone} -\unexpanded\def\dodorecurse#1#2% from to +\unexpanded\def\syst_helpers_recurse_indeed#1#2% from to {\ifnum#1>#2\relax - \expandafter\nodorecurse + \expandafter\syst_helpers_recurse_indeed_nop \else \def\recurselevel{#1}% - \doubleexpandafter\redorecurse + \doubleexpandafter\syst_helpers_recurse_indeed_yes \fi\expandafter{\the\numexpr\recurselevel+\plusone\relax}{#2}} -\unexpanded\def\dodorecurse#1#2% from to +\unexpanded\def\syst_helpers_recurse_indeed#1#2% from to {\ifnum#1>#2\relax - \expandafter\nodorecurse + \expandafter\syst_helpers_recurse_indeed_nop \else \def\recurselevel{#1}% \innerrecurse#1\advance\innerrecurse\plusone - \doubleexpandafter\redorecurse + \doubleexpandafter\syst_helpers_recurse_indeed_yes \fi\expandafter{\the\innerrecurse}{#2}} -\unexpanded\def\redorecurse - {\expandrecursecontent\dodorecurse} +\unexpanded\def\syst_helpers_recurse_indeed_yes + {\syst_helpers_recurse_content + \syst_helpers_recurse_indeed} -\unexpanded\def\nodorecurse#1#2#3% - {\expandafter\let\expandafter\recurselevel\csname\@@irecurse\recursedepth\endcsname +\unexpanded\def\syst_helpers_recurse_indeed_nop#1#2#3% + {\expandafter\let\expandafter\recurselevel\csname\??recurseindex\recursedepth\endcsname \global\advance\outerrecurse \minusone } %D \macros @@ -3483,32 +3503,33 @@ %D When needed, one can call for \type{\looplevel} and %D \type{\loopdepth}. -\let\endofloop\donothing +\let\endofloop\donothing % maybe \syst_helpers_loop_end \unexpanded\def\doloop#1% {\global\advance\outerrecurse \plusone - \expandafter\gdef\csname\@@arecurse\recursedepth\endcsname{#1}% - \global\expandafter\let\csname\@@irecurse\recursedepth\endcsname\recurselevel - \let\endofloop\dodoloop - \dodoloop1} % no \plusone else \recurselevel wrong + \expandafter\gdef\csname\??recurseaction\recursedepth\endcsname{#1}% + \global\expandafter\let\csname\??recurseindex\recursedepth\endcsname\recurselevel + \let\endofloop\syst_helpers_loop + \syst_helpers_loop1} % no \plusone else \recurselevel wrong -\unexpanded\def\dodoloop#1% +\unexpanded\def\syst_helpers_loop#1% {\def\recurselevel{#1}% - \expandafter\redoloop\expandafter{\the\numexpr\recurselevel+\plusone\relax}} + \expandafter\syst_helpers_loop_yes\expandafter{\the\numexpr\recurselevel+\plusone\relax}} -\unexpanded\def\redoloop - {\expandrecursecontent\endofloop} +\unexpanded\def\syst_helpers_loop_yes + {\syst_helpers_recurse_content + \endofloop} -\unexpanded\def\nodoloop#1% - {\let\endofloop\dodoloop % new, permits nested \doloop's - \expandafter\let\expandafter\recurselevel\csname\@@irecurse\recursedepth\endcsname +\unexpanded\def\syst_helpers_loop_nop#1% + {\let\endofloop\syst_helpers_loop % new, permits nested \doloop's + \expandafter\let\expandafter\recurselevel\csname\??recurseindex\recursedepth\endcsname \global\advance\outerrecurse\minusone} \unexpanded\def\exitloop % \exitloop quits at end - {\let\endofloop\nodoloop} + {\let\endofloop\syst_helpers_loop_nop} \unexpanded\def\exitloopnow#1\endofloop % \exitloopnow quits directly - {\nodoloop} + {\syst_helpers_loop_nop} %D The loop is executed at least once, so beware of situations %D like: @@ -3548,94 +3569,113 @@ %D \dorecurse{3}{\expanded{\definesymbol[test-\recurselevel][xx-\recurselevel]}} %D \stoptyping -\def\expandrecursecontent - {\csname\@@arecurse\recursedepth\expandafter\expandafter\expandafter\endcsname +\def\syst_helpers_recurse_content + {\csname\??recurseaction\recursedepth\expandafter\expandafter\expandafter\endcsname \expandafter\expandafter\expandafter{\expandafter\recurselevel\expandafter}\expandafter{\recursedepth}} -\unexpanded\def\xdorecurse#1#2% +\unexpanded\def\syst_helpers_recurse_x#1#2% {\global\advance\outerrecurse \plusone - \global\expandafter\def\csname\@@arecurse\recursedepth\endcsname##1##2{#2}% - \global\expandafter\let\csname\@@irecurse\recursedepth\endcsname\recurselevel - \expandafter\dodorecurse\expandafter1\expandafter{\number#1}} + \global\expandafter\def\csname\??recurseaction\recursedepth\endcsname##1##2{#2}% + \global\expandafter\let\csname\??recurseindex\recursedepth\endcsname\recurselevel + \expandafter\syst_helpers_recurse_indeed\expandafter1\expandafter{\number#1}} -\unexpanded\def\ydorecurse#1#2% +\unexpanded\def\syst_helpers_recurse_y#1#2% {\global\advance\outerrecurse \plusone - \global\expandafter\let\csname\@@irecurse\recursedepth\endcsname\recurselevel + \global\expandafter\let\csname\??recurseindex\recursedepth\endcsname\recurselevel \let\recurselevel\!!plusone - \global\expandafter\def\csname\@@arecurse\recursedepth\endcsname##1##2{#2}% - \expandrecursecontent - \expandafter\let\expandafter\recurselevel\csname\@@irecurse\recursedepth\endcsname + \global\expandafter\def\csname\??recurseaction\recursedepth\endcsname##1##2{#2}% + \syst_helpers_recurse_content + \expandafter\let\expandafter\recurselevel\csname\??recurseindex\recursedepth\endcsname \global\advance\outerrecurse \minusone} \unexpanded\def\dostepwiserecurse#1#2#3#4% can be made faster by postponing #4 {\global\advance\outerrecurse \plusone - \global\expandafter\def\csname\@@arecurse\recursedepth\endcsname##1##2{#4}% - \global\expandafter\let\csname\@@irecurse\recursedepth\endcsname\recurselevel - \ifnum#3>0\relax + \global\expandafter\def\csname\??recurseaction\recursedepth\endcsname##1##2{#4}% + \global\expandafter\let\csname\??recurseindex\recursedepth\endcsname\recurselevel + \ifnum#3>\zerocount\relax \ifnum#2<#1\relax - \let\nextrecurse\exitstepwiserecurse + \let\syst_helpers_stepwise_next\syst_helpers_stepwise_exit \else - \let\nextrecurse\dodostepwiserecurse + \let\syst_helpers_stepwise_next\syst_helpers_stepwise_recurse \fi \else - \ifnum#3<0\relax + \ifnum#3<\zerocount\relax \ifnum#1<#2\relax - \let\nextrecurse\exitstepwiserecurse + \let\syst_helpers_stepwise_next\syst_helpers_stepwise_exit \else - \let\nextrecurse\dodostepwisereverse + \let\syst_helpers_stepwise_next\syst_helpers_stepwise_reverse \fi \else - \let\nextrecurse\exitstepwiserecurse + \let\syst_helpers_stepwise_next\syst_helpers_stepwise_exit \fi - \fi\normalexpanded{\nextrecurse{\number#1}{\number#2}{\number#3}}} + \fi\normalexpanded{\syst_helpers_stepwise_next{\number#1}{\number#2}{\number#3}}} \unexpanded\def\doloop#1% {\global\advance\outerrecurse \plusone - \global\expandafter\def\csname\@@arecurse\recursedepth\endcsname##1##2{#1}% - \global\expandafter\let\csname\@@irecurse\recursedepth\endcsname\recurselevel - \let\endofloop\dodoloop - \dodoloop1} % no \plusone else \recurselevel wrong + \global\expandafter\def\csname\??recurseaction\recursedepth\endcsname##1##2{#1}% + \global\expandafter\let\csname\??recurseindex\recursedepth\endcsname\recurselevel + \let\endofloop\syst_helpers_loop + \syst_helpers_loop1} % no \plusone else \recurselevel wrong % faster +% \unexpanded\def\dostepwiserecurse#1#2#3#4% can be made faster by postponing #4 +% {\global\advance\outerrecurse \plusone +% \global\expandafter\def\csname\??recurseaction\recursedepth\endcsname##1##2{#4}% +% \global\expandafter\let\csname\??recurseindex\recursedepth\endcsname\recurselevel +% \csname @swr% +% \ifnum#3>\zerocount +% \ifnum#2<#1\else d\fi +% \else\ifnum#3<\zerocount +% \ifnum#1<#2\else r\fi +% \fi\fi +% \expandafter\endcsname\normalexpanded{{\number#1}{\number#2}{\number#3}}} + +% \let\@swr \syst_helpers_stepwise_exit +% \let\@swrd\syst_helpers_stepwise_recurse +% \let\@swrr\syst_helpers_stepwise_reverse + +\installsystemnamespace{recursestepwise} + \unexpanded\def\dostepwiserecurse#1#2#3#4% can be made faster by postponing #4 {\global\advance\outerrecurse \plusone - \global\expandafter\def\csname\@@arecurse\recursedepth\endcsname##1##2{#4}% - \global\expandafter\let\csname\@@irecurse\recursedepth\endcsname\recurselevel - \csname @swr% + \global\expandafter\def\csname\??recurseaction\recursedepth\endcsname##1##2{#4}% + \global\expandafter\let\csname\??recurseindex\recursedepth\endcsname\recurselevel + \csname\??recursestepwise \ifnum#3>\zerocount \ifnum#2<#1\else d\fi \else\ifnum#3<\zerocount \ifnum#1<#2\else r\fi \fi\fi \expandafter\endcsname\normalexpanded{{\number#1}{\number#2}{\number#3}}} + % \expandafter\endcsname\expandafter{\number#1\expandafter}\expandafter{\number#2\expandafter}\expandafter{\number#3}} -\let\@swr \exitstepwiserecurse -\let\@swrd\dodostepwiserecurse -\let\@swrr\dodostepwisereverse +\letvalue{\??recursestepwise }\syst_helpers_stepwise_exit +\letvalue{\??recursestepwise d}\syst_helpers_stepwise_recurse +\letvalue{\??recursestepwise r}\syst_helpers_stepwise_reverse % quite okay too, but untested % % \def\dostepwiserecurse#1#2#3#4% can be made faster by postponing #4 % {\global\advance\outerrecurse \plusone -% \global\expandafter\def\csname\@@arecurse\recursedepth\endcsname##1##2{#4}% -% \global\expandafter\let\csname\@@irecurse\recursedepth\endcsname\recurselevel +% \global\expandafter\def\csname\??recurseaction\recursedepth\endcsname##1##2{#4}% +% \global\expandafter\let\csname\??recurseindex\recursedepth\endcsname\recurselevel % \normalexpanded % {\ifnum#3>\zerocount % \ifnum#2<#1 -% \exitstepwiserecurse +% \syst_helpers_stepwise_exit % \else -% \dodostepwiserecurse +% \syst_helpers_stepwise_recurse % \fi % \else % \ifnum#3<\zerocount % \ifnum#1<#2 -% \exitstepwiserecurse +% \syst_helpers_stepwise_exit % \else -% \dodostepwisereverse +% \syst_helpers_stepwise_reverse % \fi % \else -% \exitstepwiserecurse +% \syst_helpers_stepwise_exit % \fi % \fi{\number#1}{\number#2}{\number#3}}} @@ -3643,21 +3683,22 @@ \newcount\fastloopindex \newcount\fastloopfinal -\let\fastloopcs\relax + +\let\m_syst_helpers_fast_loop_cs\relax \unexpanded\def\dofastloopcs#1#2% - {\let\fastloopcs#2 + {\let\m_syst_helpers_fast_loop_cs#2% \fastloopindex\plusone \fastloopfinal#1\relax - \dodofastloopcs} + \syst_helpers_fast_loop_cs} -\unexpanded\def\dodofastloopcs +\unexpanded\def\syst_helpers_fast_loop_cs {\ifnum\fastloopindex>\fastloopfinal - \let\fastloopcs\relax + \let\m_syst_helpers_fast_loop_cs\relax \else - \fastloopcs + \m_syst_helpers_fast_loop_cs \advance\fastloopindex\plusone - \expandafter\dodofastloopcs + \expandafter\syst_helpers_fast_loop_cs \fi} % Helper: @@ -3693,10 +3734,10 @@ \unexpanded\def\doloopoverlist#1#2% {\global\advance\outerrecurse\plusone - \expandafter\gdef\csname\@@arecurse\recursedepth\endcsname##1{\edef\recursestring{##1}#2}% - \expandafter\glet\csname\@@irecurse\recursedepth\endcsname\recursestring - \normalexpanded{\processcommalist[#1]{\expandafter\noexpand\csname\@@arecurse\recursedepth\endcsname}}% - \expandafter\let\expandafter\recursestring\csname\@@irecurse\recursedepth\endcsname + \expandafter\gdef\csname\??recurseaction\recursedepth\endcsname##1{\edef\recursestring{##1}#2}% + \expandafter\glet\csname\??recurseindex\recursedepth\endcsname\recursestring + \normalexpanded{\processcommalist[#1]{\expandafter\noexpand\csname\??recurseaction\recursedepth\endcsname}}% + \expandafter\let\expandafter\recursestring\csname\??recurseindex\recursedepth\endcsname \global\advance\outerrecurse\minusone} %D \macros @@ -3724,20 +3765,20 @@ % \EveryPar{y } \everypar{before } [before] \par % } -% retrofit this into mkii - -\def\dowithevery#1% - {\expandafter\removetoks\expandafter\the\csname t\strippedcsname#1\endcsname\from#1% - \expandafter\appendtoks\expandafter\the\csname t\strippedcsname#1\endcsname\to #1% - \csname t\strippedcsname#1\endcsname} +\installsystemnamespace{extraevery} -\def\newevery#1#2% +\unexpanded\def\newevery#1#2% {\ifx#1\everypar\else\newtoks#1\fi% we test for redefinition elsewhere \ifx#2\relax\else\ifdefined#2\else - \expandafter\newtoks\csname t\strippedcsname#1\endcsname - \def#2{\dowithevery#1}% + \expandafter\newtoks\csname\??extraevery\strippedcsname#1\endcsname + \def#2{\syst_helpers_every#1}% \fi\fi} +\unexpanded\def\syst_helpers_every#1% + {\expandafter\removetoks\expandafter\the\csname\??extraevery\strippedcsname#1\endcsname\from#1% + \expandafter\appendtoks\expandafter\the\csname\??extraevery\strippedcsname#1\endcsname\to #1% + \csname\??extraevery\strippedcsname#1\endcsname} + %D This one permits definitions like: \newevery \everypar \EveryPar % we get a warning which is ok @@ -3745,7 +3786,23 @@ %D and how about: -\newevery \neverypar \NeveryPar +% \newtoks \neverypar +% \newtoks \neveryendpar +% +% \normalprotected\def\syst_helpers_forgotten_endpar +% {\the\neveryendpar\normalpar} +% +% \unexpanded\def\forgeteverypar +% {\everypar{\the\neverypar}% +% \let\endpar\syst_helpers_forgotten_endpar} +% +% \unexpanded\def\finishpar +% {\ifvmode\else\par\fi} + +\newtoks \neverypar + +\unexpanded\def\forgeteverypar + {\everypar{\the\neverypar}} %D Which we're going to use indeed! When the second argument %D equals \type {\relax}, the first token list is created @@ -3817,10 +3874,10 @@ %D Both commands accept the prefix \type{\doglobal} for global %D assignments. -\def\convertvalue#1\to +\unexpanded\def\convertvalue#1\to {\expandafter\convertcommand\csname#1\endcsname\to} -\def\defconvertedvalue#1#2% less sensitive for \to +\unexpanded\def\defconvertedvalue#1#2% less sensitive for \to {\expandafter\defconvertedcommand\expandafter#1\csname#2\endcsname} %D \macros @@ -3843,10 +3900,10 @@ %D \doifassignmentelse {...} {then ...} {else ...} %D \stoptyping -\def\docheckifassignmentelse#1=#2#3\@end@{\if#2@}% +\def\syst_helpers_check_if_assignment_else#1=#2#3\_e_o_p_{\if#2@}% -\def\doifassignmentelse#1% expandable - {\expandafter\docheckifassignmentelse\detokenize{#1}=@@\@end@ +\unexpanded\def\doifassignmentelse#1% expandable + {\expandafter\syst_helpers_check_if_assignment_else\detokenize{#1}=@@\_e_o_p_ \expandafter\secondoftwoarguments \else \expandafter\firstoftwoarguments @@ -3854,23 +3911,12 @@ \newif\ifassignment -% \def\docheckassignmentindeed#1=#2#3\@end@{\if#2@\assignmentfalse\else\assignmenttrue\fi} -% -% \def\docheckassignment#1% -% {\expandafter\docheckassignmentindeed\detokenize{#1}=@@\@end@} - -% D \macros -% D {convertasciiafter} -% D -% D Sometimes we need to convert an argument to a string (letters -% D only), for instance when we compare it with another string: -% D -% D \starttyping -% D \convertasciiafter\doifinstringelse{em}{\ascii}{...} -% D \stoptyping -% -% \def\convertasciiafter#1#2% -% {\expandafter#1\expandafter{\detokenize{#2}}} +\unexpanded\def\docheckassignment#1% + {\expandafter\syst_helpers_check_if_assignment_else\detokenize{#1}=@@\_e_o_p_ + \assignmentfalse + \else + \assignmenttrue + \fi} %D In \ETEX\ we can use \type {\detokenize} and gain some %D speed, but in general far less that 1\% for \type @@ -3879,17 +3925,17 @@ %D something I found out when primitives like \type %D {\jobname} were fed (or something undefined). -\def\convertargument#1\to#2{\dodoglobal\edef#2{\detokenize{#1}}} -\def\convertcommand #1\to#2{\dodoglobal\edef#2{\expandafter\detokenize\expandafter{#1}}} % hm, only second is also ok +\unexpanded\def\convertargument#1\to#2{\dodoglobal\edef#2{\detokenize{#1}}} +\unexpanded\def\convertcommand #1\to#2{\dodoglobal\edef#2{\expandafter\detokenize\expandafter{#1}}} % hm, only second is also ok -\def\defconvertedargument #1#2{\edef#1{\detokenize{#2}}} -\def\defconvertedcommand #1#2{\edef#1{\detokenize\expandafter{#2}}} -\def\edefconvertedargument#1#2{\edef#1{#2}% - \edef#1{\detokenize\expandafter{#1}}} -\def\gdefconvertedargument#1#2{\xdef#1{\detokenize{#2}}} -\def\gdefconvertedcommand #1#2{\xdef#1{\detokenize\expandafter{#2}}} -\def\xdefconvertedargument#1#2{\xdef#1{#2}% - \xdef#1{\detokenize\expandafter{#1}}} +\unexpanded\def\defconvertedargument #1#2{\edef#1{\detokenize{#2}}} +\unexpanded\def\defconvertedcommand #1#2{\edef#1{\detokenize\expandafter{#2}}} +\unexpanded\def\edefconvertedargument#1#2{\edef#1{#2}% + \edef#1{\detokenize\expandafter{#1}}} +\unexpanded\def\gdefconvertedargument#1#2{\xdef#1{\detokenize{#2}}} +\unexpanded\def\gdefconvertedcommand #1#2{\xdef#1{\detokenize\expandafter{#2}}} +\unexpanded\def\xdefconvertedargument#1#2{\xdef#1{#2}% + \xdef#1{\detokenize\expandafter{#1}}} %D When you try to convert a primitive command, you'll find %D out that the \ETEX\ method fails on for instance \type @@ -3910,14 +3956,11 @@ %D argument are completely redundant. %D \macros -%D {showvalue,showargument} +%D {showvalue} %D -%D Two handy macros for testing purposes only: - -\def\showvalue#1% - {\expandafter\show\csname#1\endcsname} +%D Ahandy macro, for testing purposes only: -\def\showvalue#1% +\unexpanded\def\showvalue#1% {\ifcsname#1\endcsname \expandafter\show\csname#1\endcsname \else @@ -3938,11 +3981,11 @@ %D %D Watch the one level expansion of the second argument. -\def\doifmeaningelse#1#2% - {\edef\!!stringa{\meaning#1}% - \def \!!stringb{#2}% - \edef\!!stringb{\meaning\!!stringb}% - \ifx\!!stringa\!!stringb +\unexpanded\def\doifmeaningelse#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}% + \ifx\m_syst_string_one\m_syst_string_two \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments @@ -3960,14 +4003,14 @@ %D \doifsamestringelse{\jobname}{oeps}{YES}{NO} %D \stoptyping -\def\@@doifsamestringelse#1#2#3#4% - {\edef\!!stringa{\detokenize\expandafter{\normalexpanded{#3}}}% - \edef\!!stringb{\detokenize\expandafter{\normalexpanded{#4}}}% - \ifx\!!stringa\!!stringb\expandafter#1\else\expandafter#2\fi} +\def\syst_helpers_if_samestring_else#1#2#3#4% + {\edef\m_syst_string_one{\detokenize\expandafter{\normalexpanded{#3}}}% + \edef\m_syst_string_two{\detokenize\expandafter{\normalexpanded{#4}}}% + \ifx\m_syst_string_one\m_syst_string_two\expandafter#1\else\expandafter#2\fi} -\def\doifsamestringelse{\@@doifsamestringelse\firstoftwoarguments\secondoftwoarguments} -\def\doifsamestring {\@@doifsamestringelse\firstofoneargument \gobbleoneargument } -\def\doifnotsamestring {\@@doifsamestringelse\gobbleoneargument \firstofoneargument } +\unexpanded\def\doifsamestringelse{\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 } %D \macros %D {ConvertToConstant,ConvertConstantAfter} @@ -3995,10 +4038,10 @@ %D In examples~2 and~3 both arguments equal, in~1 and~4 %D they differ. -\def\ConvertToConstant#1#2#3% - {\edef\!!stringa{\expandafter\detokenize\expandafter{#2}}% - \edef\!!stringb{\expandafter\detokenize\expandafter{#3}}% - #1{\!!stringa}{\!!stringb}} +\unexpanded\def\ConvertToConstant#1#2#3% + {\edef\m_syst_string_one{\expandafter\detokenize\expandafter{#2}}% + \edef\m_syst_string_two{\expandafter\detokenize\expandafter{#3}}% + #1{\m_syst_string_one}{\m_syst_string_two}} %D When the argument \type{#1} consists of commands, we had %D better use @@ -4027,14 +4070,14 @@ %D %D where \type{...} can be anything legally \TEX. -\def\CheckConstantAfter#1#2% +\unexpanded\def\CheckConstantAfter#1#2% {\expandafter\convertargument\v!prefix!\to\ascii \convertargument#1\to#2\relax \doifinstringelse\ascii{#2} {\expandafter\convertargument#1\to#2} {}} -\def\ConvertConstantAfter#1#2#3% +\unexpanded\def\ConvertConstantAfter#1#2#3% {\CheckConstantAfter{#2}\asciia \CheckConstantAfter{#3}\asciib #1{\asciia}{\asciib}} @@ -4050,7 +4093,7 @@ %D %D We don't explicitly test if the macro is defined. -\def\assignifempty#1#2% can be sped up +\unexpanded\def\assignifempty#1#2% can be sped up {\doifsomething{#1}{\def#1{#2}}} % {\doifnot{#1}{}{\def#1{#2}}} %D \macros @@ -4094,11 +4137,13 @@ %D %D results in: \type{\message{Hello world!}}. -\def\dograbuntil#1#2% - {\def\next##1#1{#2{##1}}\next} +\let\syst_helpers_grab_indeed\relax -\def\grabuntil#1% - {\expandafter\dograbuntil\expandafter{\csname#1\endcsname}} +\unexpanded\def\syst_helpers_grab#1#2% + {\def\syst_helpers_grab_indeed##1#1{#2{##1}}\syst_helpers_grab_indeed} + +\unexpanded\def\grabuntil#1% + {\expandafter\syst_helpers_grab\expandafter{\csname#1\endcsname}} %D The next command build on this mechanism: %D @@ -4122,13 +4167,15 @@ %D is related to these commands. This one simply throws away %D everything preceding \type{\command}. -\def\processbetween#1#2% +\let\syst_helpers_gobble_indeed\relax + +\unexpanded\def\processbetween#1#2% {\setvalue{\s!start#1}{\grabuntil{\s!stop#1}{#2}}} -\def\gobbleuntil#1% - {\def\next##1#1{}\next} +\unexpanded\def\gobbleuntil#1% + {\def\syst_helpers_gobble_indeed##1#1{}\syst_helpers_gobble_indeed} -\def\gobbleuntilrelax#1\relax +\unexpanded\def\gobbleuntilrelax#1\relax {} %D The next one simply expands the pickup up tokens. @@ -4137,8 +4184,10 @@ %D \processuntil{sequence} %D \stoptyping -\def\processuntil#1% - {\def\next##1#1{##1}\next} +\let\syst_helpers_until_indeed\relax + +\unexpanded\def\processuntil#1% + {\def\syst_helpers_until_indeed##1#1{##1}\syst_helpers_until_indeed} %D \macros %D {groupedcommand} @@ -4183,7 +4232,7 @@ %D %D \starttyping %D \def\rightword% -%D {\groupedcommand{\hfill\hbox}{\parfillskip\!!zeropoint}} +%D {\groupedcommand{\hfill\hbox}{\parfillskip\zeropoint}} %D %D .......... \rightword{the right way} %D \stoptyping @@ -4202,45 +4251,85 @@ %D to be {\bold bold} or not, that's the question %D \stoptyping %D -%D This alternative checks for a \type{\bgroup} token first. -%D The internal alternative does not accept the box handling -%D mentioned before, but further nesting works all right. The -%D extra \type{\bgroup}||\type{\egroup} is needed to keep -%D \type{\AfterGroup} both into sight and local. +%D This alternative checks for a \type {\bgroup} token first. The internal +%D alternative does not accept the box handling mentioned before, but further +%D nesting works all right. The extra \type {\bgroup}||\type {\egroup} is needed to +%D keep \type {\m_syst_helpers_handle_group_after} both into sight and local. -\def\HandleGroup#1#2% +\let\m_syst_helpers_handle_group_after \relax +\let\m_syst_helpers_handle_group_before\relax + +% keep: +% +% \unexpanded\def\syst_helpers_handle_group_normal#1#2% +% {\bgroup +% \def\m_syst_helpers_handle_group_before{\bgroup#1\bgroup\aftergroup\m_syst_helpers_handle_group_after}% can't we remove the second \bgroup +% \def\m_syst_helpers_handle_group_after {#2\egroup\egroup}% and one \egroup here? +% \afterassignment\m_syst_helpers_handle_group_before +% \let\next=} + +\unexpanded\def\syst_helpers_handle_group_normal#1#2% {\bgroup - \def\BeforeGroup{\bgroup#1\bgroup\aftergroup\AfterGroup}% can't we remove the second \bgroup - \def\AfterGroup {#2\egroup\egroup}% % and one \egroup here? - \afterassignment\BeforeGroup + \def\m_syst_helpers_handle_group_before{#1}% + \def\m_syst_helpers_handle_group_after {#2}% + \afterassignment\m_syst_helpers_handle_group_normal_before \let\next=} -\def\HandleSimpleGroup#1#2% no inner group (so no kerning interference) +\def\m_syst_helpers_handle_group_normal_before + {\bgroup + \m_syst_helpers_handle_group_before + \bgroup + \aftergroup\m_syst_helpers_handle_group_normal_after} + +\def\m_syst_helpers_handle_group_normal_after + {\m_syst_helpers_handle_group_after + \egroup + \egroup} + +% keep: +% +% \unexpanded\def\syst_helpers_handle_group_simple#1#2% no inner group (so no kerning interference) +% {\bgroup +% %def\m_syst_helpers_handle_group_before{\bgroup#1\aftergroup\m_syst_helpers_handle_group_after}% interferes +% \def\m_syst_helpers_handle_group_before{\bgroup\aftergroup\m_syst_helpers_handle_group_after#1}% +% \def\m_syst_helpers_handle_group_after {#2\egroup}% +% \afterassignment\m_syst_helpers_handle_group_before +% \let\next=} + +\unexpanded\def\syst_helpers_handle_group_simple#1#2% no inner group (so no kerning interference) {\bgroup - %def\BeforeGroup{\bgroup#1\aftergroup\AfterGroup}% interferes - \def\BeforeGroup{\bgroup\aftergroup\AfterGroup#1}% - \def\AfterGroup {#2\egroup}% - \afterassignment\BeforeGroup + \def\m_syst_helpers_handle_group_before{#1}% + \def\m_syst_helpers_handle_group_after {#2}% + \afterassignment\m_syst_helpers_handle_group_simple_before \let\next=} -% \def\HandleNoGroup#1#2% -% {\def\AfterGroup{#2\egroup}% -% \bgroup\aftergroup\AfterGroup#1} +\def\m_syst_helpers_handle_group_simple_before + {\bgroup + \aftergroup\m_syst_helpers_handle_group_simple_after + \m_syst_helpers_handle_group_before} + +\def\m_syst_helpers_handle_group_simple_after + {\m_syst_helpers_handle_group_after + \egroup}% -\def\HandleNoGroup % retrofit into mkii +\unexpanded\def\syst_helpers_handle_group_nop {\ifnum\currentgrouptype=\semisimplegroupcode - \expandafter\HandleNoGroupA + \expandafter\syst_helpers_handle_group_nop_a \else - \expandafter\HandleNoGroupB + \expandafter\syst_helpers_handle_group_nop_b \fi} -\def\HandleNoGroupA#1#2% - {\def\AfterGroup{#2\endgroup}% - \begingroup\aftergroup\AfterGroup#1} +\def\syst_helpers_handle_group_nop_a#1#2% + {\def\m_syst_helpers_handle_group_after{#2\endgroup}% + \begingroup + \aftergroup\m_syst_helpers_handle_group_after + #1} -\def\HandleNoGroupB#1#2% - {\def\AfterGroup{#2\egroup}% - \bgroup\aftergroup\AfterGroup#1} +\def\syst_helpers_handle_group_nop_b#1#2% + {\def\m_syst_helpers_handle_group_after{#2\egroup}% + \bgroup + \aftergroup\m_syst_helpers_handle_group_after + #1} %D I considered it a nuisance that %D @@ -4255,10 +4344,10 @@ %D implementation became: \unexpanded\def\groupedcommand#1#2% - {\doifnextbgroupelse{\HandleGroup{#1}{#2}}{\HandleNoGroup{#1}{#2}}} + {\doifnextbgroupelse{\syst_helpers_handle_group_normal{#1}{#2}}{\syst_helpers_handle_group_nop{#1}{#2}}} \unexpanded\def\simplegroupedcommand#1#2% - {\doifnextbgroupelse{\HandleSimpleGroup{#1}{#2}}{\HandleNoGroup{#1}{#2}}} + {\doifnextbgroupelse{\syst_helpers_handle_group_simple{#1}{#2}}{\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 @@ -4288,10 +4377,10 @@ %D \type{CAPITALS}. This suggestion is feasible, because %D \CONTEXT only defines lowcased macros. -\def\showdefinederror#1#2% +\unexpanded\def\showdefinederror#1#2% {\writestatus\m!system{#1 #2 replaces a macro, use CAPITALS!}} -\def\checkdefined#1#2#3% +\unexpanded\def\checkdefined#1#2#3% {\doifdefined{#3}{\showdefinederror{#2}{#3}}} %D \macros @@ -4365,6 +4454,11 @@ {\def\dodogotopar{#1}% \redogotopar\par} +\def\dogotoparcs#1% + {\let\dodogotopar#1% + \redogotopar\par} + + \unexpanded\def\GetPar {\expanded {\dowithpar @@ -4413,10 +4507,13 @@ %D ... \par %D \stoptyping +\let\syst_helpers_next_par\relax +\let\syst_helpers_next_arg\relax + \unexpanded\def\dowithpargument#1% - {\def\nextpar##1 \par{#1{##1}}% - \def\nextarg##1{#1{##1}}% - \doifnextbgroupelse\nextarg{\doifnextcharelse\par{#1{}}\nextpar}} + {\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}} %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} @@ -4440,10 +4537,13 @@ %D ... %D \stoptyping +\let\syst_helpers_next_war\relax +\let\syst_helpers_next_arg\relax + \unexpanded\def\dowithwargument#1% - {\def\nextwar##1 {#1{##1}}% - \def\nextarg##1{#1{##1}}% - \doifnextbgroupelse\nextarg\nextwar} + {\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} %D \macros %D {dorepeat,dorepeatwithcommand} @@ -4476,12 +4576,12 @@ %D specification is missing, the command executes once. \unexpanded\def\dorepeatwithcommand[#1]% - {\dodorepeatwithcommand#1*\empty*\relax} + {\syst_helpers_repeat_with_command#1*\empty*\relax} -\def\dodorepeatwithcommand#1*#2#3*#4\relax#5% - {\ifx#2\empty\redorepeatwithcommand[#1]#5\else\dododorepeatwithcommand{#1}{#2}{#3}#5\fi} +\def\syst_helpers_repeat_with_command#1*#2#3*#4\relax#5% + {\ifx#2\empty\syst_helpers_repeat_with_command_again[#1]#5\else\syst_helpers_repeat_with_command_indeed{#1}{#2}{#3}#5\fi} -\def\dododorepeatwithcommand#1#2#3#4% +\def\syst_helpers_repeat_with_command_indeed#1#2#3#4% {\ifx#2\empty % redundant but gives cleaner extensions #4{#1}% \else\ifnum#1<\zerocount @@ -4493,7 +4593,7 @@ \dorecurse{#1}{#4{#2#3}}% \fi\fi\fi} -\def\redorepeatwithcommand[#1]#2% +\def\syst_helpers_repeat_with_command_again[#1]#2% {#2{#1}} %D The extension hook permits something like: @@ -4503,11 +4603,11 @@ %D %D \catcode`\*=\superscriptcatcode %D -%D \gdef\redorepeatwithcommand[#1]% +%D \gdef\syst_helpers_repeat_with_command_again[#1]% %D {\redodorepeatwithcommand#1*\empty*\relax} %D %D \gdef\redodorepeatwithcommand#1*#2#3*#4\relax#5% -%D {\dododorepeatwithcommand{#1}{#2}{#3}#5} +%D {\syst_helpers_repeat_with_command_indeed{#1}{#2}{#3}#5} %D %D \egroup %D \stoptyping @@ -4515,14 +4615,6 @@ %D although one may wonder if changing the catcode of \type {*} is wise. %D \macros -%D {normalbgroup,normalgroup} -%D -%D No comment. - -\let\normalbgroup\bgroup -\let\normalegroup\egroup - -%D \macros %D {doifstringinstringelse} %D %D The next macro is meant for situations where both strings @@ -4539,7 +4631,7 @@ %D %D A bit faster is: -\def\pp!doifstringinstringelse#1% +\def\syst_helpers_if_instring_else_indeed#1% {\if#1@% \expandafter\secondoftwoarguments \else @@ -4547,9 +4639,9 @@ \fi} \def\doifstringinstringelse#1#2% - {\expandafter\def\expandafter\p!doifstringinstringelse\expandafter##\expandafter1#1##2##3\war - {\pp!doifstringinstringelse##2}% - \expandafter\expandafter\expandafter\p!doifstringinstringelse\expandafter#2#1@@\war} + {\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_} %D \macros %D {appendtoks,prependtoks,appendtoksonce,prependtoksonce, @@ -4569,36 +4661,39 @@ %D These macros are clones of the ones implemented in page~378 of %D Knuth's \TeX book. -\newtoks\@@scratchtoks +\newtoks\t_syst_helpers_scratch +\let \m_syst_helpers_scratch\empty + +% no longer \def but \let to target toks -\unexpanded\def\appendtoks {\doappendtoks \relax} -\unexpanded\def\prependtoks {\doprependtoks \relax} -\unexpanded\def\appendtoksonce {\doappendtoksonce \relax} -\unexpanded\def\prependtoksonce{\doprependtoksonce\relax} +\unexpanded\def\appendtoks {\syst_helpers_append_toks \relax} +\unexpanded\def\prependtoks {\syst_helpers_prepend_toks \relax} +\unexpanded\def\appendtoksonce {\syst_helpers_append_toks_once \relax} +\unexpanded\def\prependtoksonce{\syst_helpers_prepend_toks_once\relax} -\def\dodoappendtoks - {\dodoglobal\@@toks\doubleexpandafter{\expandafter\the\expandafter\@@toks\the\@@scratchtoks}} +\def\syst_helpers_append_toks_indeed + {\dodoglobal\m_syst_helpers_scratch\doubleexpandafter{\expandafter\the\expandafter\m_syst_helpers_scratch\the\t_syst_helpers_scratch}} -\def\dodoprependtoks - {\dodoglobal\@@toks\doubleexpandafter{\expandafter\the\expandafter\@@scratchtoks\the\@@toks}} +\def\syst_helpers_prepend_toks_indeed + {\dodoglobal\m_syst_helpers_scratch\doubleexpandafter{\expandafter\the\expandafter\t_syst_helpers_scratch\the\m_syst_helpers_scratch}} -\def\doappendtoks#1\to#2% - {\def\@@toks{#2}% - \@@scratchtoks\expandafter{\gobbleoneargument#1}\dodoappendtoks} +\def\syst_helpers_append_toks#1\to#2% + {\let\m_syst_helpers_scratch#2% + \t_syst_helpers_scratch\expandafter{\gobbleoneargument#1}\syst_helpers_append_toks_indeed} -\def\doprependtoks#1\to#2% - {\def\@@toks{#2}% - \@@scratchtoks\expandafter{\gobbleoneargument#1}\dodoprependtoks} +\def\syst_helpers_prepend_toks#1\to#2% + {\let\m_syst_helpers_scratch#2% + \t_syst_helpers_scratch\expandafter{\gobbleoneargument#1}\syst_helpers_prepend_toks_indeed} -\def\doappendtoksonce#1\to#2% - {\def\@@toks{#2}% - \@@scratchtoks\expandafter{\gobbleoneargument#1}% - \doifintokselse\@@scratchtoks\@@toks\donothing\dodoappendtoks} +\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} -\def\doprependtoksonce#1\to#2% - {\def\@@toks{#2}% - \@@scratchtoks\expandafter{\gobbleoneargument#1}% - \doifintokselse\@@scratchtoks\@@toks\donothing\dodoprependtoks} +\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} %D The test macro: @@ -4616,70 +4711,27 @@ % {\scratchtoks{a\relax b} \removetoks \relax\from\scratchtoks [\showthe\scratchtoks]} \unexpanded\def\removetoks#1\from#2% - {\def\doremovetoks##1#1##2\empty\empty\empty##3\\% - {\def\!!stringa{##3}% - \ifx\!!stringa\empty#2{##1}\else#2{##1##2}\fi}% - \expandafter\doremovetoks\the#2\empty\empty\empty#1\empty\empty\empty\\} + {\def\syst_helpers_remove_toks##1#1##2\empty\empty\empty##3\_e_o_t_ + {\def\m_syst_string_one{##3}% + \ifx\m_syst_string_one\empty#2{##1}\else#2{##1##2}\fi}% + \expandafter\syst_helpers_remove_toks\the#2\empty\empty\empty#1\empty\empty\empty\_e_o_t_} %D Also: -\unexpanded\def\appendetoks #1\to{\normalexpanded{\noexpand\appendtoks #1}\to} -\unexpanded\def\prependetoks#1\to{\normalexpanded{\noexpand\prependtoks#1}\to} +\unexpanded\def\appendetoks #1\to{\normalexpanded{\appendtoks #1}\to} +\unexpanded\def\prependetoks#1\to{\normalexpanded{\prependtoks#1}\to} %D Hm. -\def\flushtoks#1% nb: can reassing to #1 again, hence the indirectness - {\@@scratchtoks#1\relax +\unexpanded\def\flushtoks#1% nb: can reassing to #1 again, hence the indirectness + {\t_syst_helpers_scratch#1\relax \dodoglobal#1\emptytoks - \the\@@scratchtoks\relax} + \the\t_syst_helpers_scratch\relax} % better: \def\flushtoks#1{\normalexpanded{\noexpand\dodoglobal#1\emptytoks\the#\relax}} \let\dotoks\the -% The following code is obsolete (and names are reused for the more -% advanced counter mechanism and those macros are not compatible! -% -% %D \macros -% %D {makecounter,pluscounter,minuscounter, -% %D resetcounter,setcounter,countervalue} -% %D -% %D Declaring, setting and resetting \COUNTERS\ can be done -% %D with the next set of commands. -% %D -% %D \starttyping -% %D \makecounter {name} -% %D \pluscounter {name} -% %D \minuscounter {name} -% %D \resetcounter {name} -% %D \setcounter {name} {value} -% %D \countervalue {name} -% %D \stoptyping -% -% \def\makecounter#1% -% {\global\expandafter\let\csname#1\endcsname\zerocountervalue} % see earlier -% -% \def\countervalue#1% -% {\ifcsname#1\endcsname\csname#1\endcsname\fi} -% -% \def\pluscounter#1% -% {\expandafter\xdef\csname#1\endcsname{\the\numexpr\csname#1\endcsname+\plusone\relax}} -% -% \def\minuscounter#1% -% {\expandafter\xdef\csname#1\endcsname{\the\numexpr\csname#1\endcsname-\plusone\relax}} -% -% \def\resetcounter#1% -% {\global\expandafter\let\csname#1\endcsname\zerocountervalue} -% -% \def\setcounter#1#2% -% {\expandafter\xdef\csname#1\endcsname{\the\numexpr#2\relax}} -% -% \def\savecounter#1% -% {\expandafter\xdef\csname ! #1 !\endcsname{\the\numexpr\csname#1\endcsname\relax}} -% -% \def\restorecounter#1% -% {\expandafter\xdef\csname#1\endcsname{\the\numexpr\csname ! #1 !\endcsname\relax}} - %D \macros %D {beforesplitstring,aftersplitstring} %D @@ -4697,33 +4749,35 @@ %D Both implementations show some insight in the manipulation %D of arguments. -\def\beforesplitstring#1\at#2\to#3% - {\def\dosplitstring##1#2##2#2##3\\% +\let\syst_helpers_split_string\relax + +\unexpanded\def\beforesplitstring#1\at#2\to#3% + {\def\syst_helpers_split_string##1#2##2#2##3\\% {\def#3{##1}}% - \expandafter\dosplitstring#1#2#2\\} + \expandafter\syst_helpers_split_string#1#2#2\\} -\def\aftersplitstring#1\at#2\to#3% - {\def\dosplitstring##1#2##2@@@##3\\% +\unexpanded\def\aftersplitstring#1\at#2\to#3% + {\def\syst_helpers_split_string##1#2##2@@@##3\\% {\def#3{##2}}% - \expandafter\dosplitstring#1@@@#2@@@\\} + \expandafter\syst_helpers_split_string#1@@@#2@@@\\} %D \macros %D {splitstring,greedysplitstring} %D %D A bonus macro. -\def\splitstring#1\at#2\to#3\and#4% - {\def\dosplitstring##1#2##2\empty\empty\empty##3\\% +\unexpanded\def\splitstring#1\at#2\to#3\and#4% + {\def\syst_helpers_split_string##1#2##2\empty\empty\empty##3\\% {\def#3{##1}% - \def\dosplitstring{##3}% - \ifx\dosplitstring\empty + \def\syst_helpers_split_string{##3}% + \ifx\syst_helpers_split_string\empty \let#4\empty \else \def#4{##2}% \fi}% - \expandafter\dosplitstring#1\empty\empty\empty#2\empty\empty\empty\\} + \expandafter\syst_helpers_split_string#1\empty\empty\empty#2\empty\empty\empty\\} -\def\greedysplitstring#1\at#2\to#3\and#4% +\unexpanded\def\greedysplitstring#1\at#2\to#3\and#4% {\edef\asciib{#1}% \let\asciic\asciib \let#3\empty @@ -4745,20 +4799,20 @@ %D aftertestandsplitstring, %D testandsplitstring} -\def\beforetestandsplitstring#1\at#2\to#3% - {\def\dosplitstring##1#2##2#2##3##4\\% +\unexpanded\def\beforetestandsplitstring#1\at#2\to#3% + {\def\syst_helpers_split_string##1#2##2#2##3##4\\% {\ifx##3\empty\let#3\empty\else\def#3{##1}\fi}% - \expandafter\dosplitstring#1#2#2\empty\\} + \expandafter\syst_helpers_split_string#1#2#2\empty\\} -\def\aftertestandsplitstring#1\at#2\to#3% - {\def\dosplitstring ##1#2##2@@@##3##4\\% +\unexpanded\def\aftertestandsplitstring#1\at#2\to#3% + {\def\syst_helpers_split_string ##1#2##2@@@##3##4\\% {\ifx##3\empty\let#3\empty\else\def#3{##2}\fi}% - \expandafter\dosplitstring #1@@@#2@@@\empty\\} + \expandafter\syst_helpers_split_string #1@@@#2@@@\empty\\} \def\testandsplitstring#1\at#2\to#3\and#4% - {\def\dosplitstring##1#2##2#2##3##4\\% + {\def\syst_helpers_split_string##1#2##2#2##3##4\\% {\ifx##3\empty\let#3\empty\let#4\empty\else\def#3{##1}\def#4{##2}\fi}% - \expandafter\dosplitstring#1#2#2\empty\\} + \expandafter\syst_helpers_split_string#1#2#2\empty\\} %D \macros %D {removesubstring} @@ -4771,9 +4825,9 @@ %D %D Which in terms of \TEX\ looks like: -\def\removesubstring#1\from#2\to#3% - {\splitstring#2\to\!!stringa\and\!!stringb - \dodoglobal#3{\!!stringa\!!stringb}} +\unexpanded\def\removesubstring#1\from#2\to#3% + {\splitstring#2\to\m_syst_string_one\and\m_syst_string_two + \dodoglobal#3{\m_syst_string_one\m_syst_string_two}} %D \macros %D {appendtocommalist,prependtocommalist, @@ -4848,9 +4902,9 @@ {\dodoglobal\edef#2{#1\ifx#2\empty\else,#2\fi}}} \unexpanded\def\robustdoifinsetelse#1#2% - {\edef\!!stringa{\detokenize\expandafter{\normalexpanded{#1}}}% - \edef\!!stringb{\detokenize\expandafter{\normalexpanded{#2}}}% - \rawdoifinsetelse\!!stringa\!!stringb} + {\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} \unexpanded\def\robustaddtocommalist#1#2% {item} \cs {\robustdoifinsetelse{#1}#2\resetglobal @@ -4860,11 +4914,11 @@ {\robustdoifinsetelse{#1}#2\resetglobal {\dodoglobal\edef#2{#1\ifx#2\empty\else,#2\fi}}} -\def\xsplitstring#1#2% \cs {str} - {\def\dosplitstring##1,#2,##2,#2,##3\\% - {\edef\!!stringa{\bcleanedupcommalist##1\empty\empty\relax}% - \edef\!!stringb{\acleanedupcommalist##2,,\relax}}% - \expandafter\dosplitstring\expandafter,#1,,#2,,#2,\\} +\unexpanded\def\xsplitstring#1#2% \cs {str} + {\def\syst_helpers_split_string##1,#2,##2,#2,##3\\% + {\edef\m_syst_string_one{\bcleanedupcommalist##1\empty\empty\relax}% + \edef\m_syst_string_two{\acleanedupcommalist##2,,\relax}}% + \expandafter\syst_helpers_split_string\expandafter,#1,,#2,,#2,\\} \def\bcleanedupcommalist#1#2#3\relax{\if#1,\else#1\fi\if#2,\else#2\fi#3} \def\bcleanedupcommalist#1#2\relax{\if#1,\else#1\fi#2} @@ -4872,12 +4926,12 @@ \unexpanded\def\removefromcommalist#1#2% to be sped up {\rawdoifinsetelse{#1}#2% - {\normalexpanded{\noexpand\xsplitstring\noexpand#2{#1}}% + {\normalexpanded{\xsplitstring\noexpand#2{#1}}% \dodoglobal\edef#2% - {\ifx\!!stringa\empty - \!!stringb + {\ifx\m_syst_string_one\empty + \m_syst_string_two \else - \!!stringa\ifx\!!stringb\empty\else,\!!stringb\fi + \m_syst_string_one\ifx\m_syst_string_two\empty\else,\m_syst_string_two\fi \fi}} \resetglobal} @@ -4897,52 +4951,35 @@ %D \substituteincommalist{old}{new}{list} %D \stoptyping -\def\substituteincommalist#1#2#3% old, new, list (slooow) - {\edef\!!stringb{#1}% - \edef\!!stringd{#2}% - \let\!!stringa#3% - \let#3\empty - \def\dosubstituteincommalist##1% - {\edef\!!stringc{##1}% - \ifx\!!stringb\!!stringc - \ifx\!!stringd\empty\else - \edef#3{#3\ifx#3\empty\else,\fi\!!stringd}% - \fi - \def\docommand####1{\edef#3{#3,####1}}% - \else - \edef#3{#3\ifx#3\empty\else,\fi##1}% - \fi}% - \expandafter\rawprocesscommacommand\expandafter[\!!stringa]\dosubstituteincommalist} - -%D A not so useful macro: - -\def\dodofrontstrip[#1#2]#3% - {\ifx#1\space - \def#3{#2}% +\def\syst_helpers_substitute_in_comma_list_step#1% + {\edef\m_syst_string_three{#1}% + \ifx\m_syst_string_one\m_syst_string_three + \ifx\m_syst_string_two\empty \else + \edef\m_syst_string_four{\ifx\m_syst_string_four\empty\else\m_syst_string_four,\fi\m_syst_string_two}% + \fi \else - \def#3{#1#2}% + \edef\m_syst_string_four{\ifx\m_syst_string_four\empty\else\m_syst_string_four,\fi#1}% \fi} -\def\dofrontstrip#1% - {\edef\!!stringa{#1}% - \ifx\!!stringa\empty \else - \expandafter\dodofrontstrip\expandafter[#1]#1% - \fi} +\unexpanded\def\substituteincommalist#1#2#3% old, new, list (slooow) + {\edef\m_syst_string_one{#1}% + \edef\m_syst_string_two{#2}% + \let\m_syst_string_four\empty + \normalexpanded{\rawprocesscommacommand[#3]}\syst_helpers_substitute_in_comma_list_step + \let#3\m_syst_string_four} %D \macros %D {replaceincommalist} %D -%D The next macro can be used to replace an indexed element -%D in a commalist: +%D The next macro can be used to replace an indexed element in a commalist: %D %D \starttyping %D \replaceincommalist\MyList{2} %D \stoptyping %D -%D Element~2 will be replaced by the current meaning of the macro -%D \type {\newcommalistelement}. The old meaning is saved in -%D \type {\commalistelement}. The replacement honors grouped items, -%D like in: +%D Element~2 will be replaced by the current meaning of the macro \type +%D {\newcommalistelement}. The old meaning is saved in \type {\commalistelement}. +%D The replacement honors grouped items, like in: %D %D \starttyping %D \def\MyList{a,b,c,d,e,f} \replaceincommalist\MyList{3} @@ -4950,43 +4987,50 @@ %D \def\MyList{a,{b,c},d,e,f} \replaceincommalist\MyList{3} %D \def\MyList{a,b,c,{d,e,f}} \replaceincommalist\MyList{3} %D \stoptyping +%D +%D This macro was used in the bibtex code (and is probably no longer needed). + +\newcount\c_syst_helpers_comma_list_index +\let \m_syst_helpers_comma_list_target\empty \let\newcommalistelement\empty -\def\replaceincommalist#1#2% #1 = commalistelement #2 = position starts at 1 - {\def\doreplaceincommalist##1% - {\ifnum\commalistcounter=#2\relax - \ifx\newcommalistelement\empty\else - \ifx\newcommalist\empty - \let\newcommalist\newcommalistelement - \else - \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter - \newcommalist\expandafter\expandafter\expandafter - {\expandafter\newcommalist\expandafter,\newcommalistelement}% - \fi - \fi - \def\commalistelement{##1}% - \else - \ifx\newcommalist\empty - \ifx\nexttoken\bgroup % is known -) - \def\newcommalist{{##1}}% - \else - \def\newcommalist{##1}% - \fi - \else - \ifx\nexttoken\bgroup % is known -) - \expandafter\def\expandafter\newcommalist\expandafter{\newcommalist,{##1}}% - \else - \expandafter\def\expandafter\newcommalist\expandafter{\newcommalist,##1}% - \fi - \fi - \fi - \advance\commalistcounter\plusone}% +\def\syst_helpers_replace_in_comma_list_step#1% + {\ifnum\commalistcounter=\c_syst_helpers_comma_list_index\relax + \ifx\newcommalistelement\empty\else + \ifx\m_syst_helpers_comma_list_target\empty + \let\m_syst_helpers_comma_list_target\newcommalistelement + \else + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter + \m_syst_helpers_comma_list_target\expandafter\expandafter\expandafter + {\expandafter\m_syst_helpers_comma_list_target\expandafter,\newcommalistelement}% + \fi + \fi + \def\commalistelement{#1}% + \else + \ifx\m_syst_helpers_comma_list_target\empty + \ifx\nexttoken\bgroup % is known -) + \def\m_syst_helpers_comma_list_target{{#1}}% + \else + \def\m_syst_helpers_comma_list_target{#1}% + \fi + \else + \ifx\nexttoken\bgroup % is known -) + \expandafter\def\expandafter\m_syst_helpers_comma_list_target\expandafter{\m_syst_helpers_comma_list_target,{#1}}% + \else + \expandafter\def\expandafter\m_syst_helpers_comma_list_target\expandafter{\m_syst_helpers_comma_list_target,#1}% + \fi + \fi + \fi + \advance\commalistcounter\plusone} + +\unexpanded\def\replaceincommalist#1#2% #1 = commalistelement #2 = position starts at 1 + {\c_syst_helpers_comma_list_index#2\relax + \let\m_syst_helpers_comma_list_target\empty \let\commalistelement\empty - \let\newcommalist\empty \commalistcounter\plusone - \expandafter\processcommalist\expandafter[#1]\doreplaceincommalist - \dodoglobal\let#1\newcommalist} + \expandafter\processcommalist\expandafter[#1]\syst_helpers_replace_in_comma_list_step + \dodoglobal\let#1\m_syst_helpers_comma_list_target} %D \macros %D {globalprocesscommalist} @@ -4997,15 +5041,17 @@ %D handling comma lists in alignments. In these situations the %D next macro can be of use. -\def\globalprocesscommaitem#1,% +\let\m_syst_helpers_comma_list_command_global\empty + +\def\syst_helpers_comma_list_command_global_step#1,% {\if]#1\else - \globalcommacommand{#1}% - \expandafter\globalprocesscommaitem + \m_syst_helpers_comma_list_command_global{#1}% + \expandafter\syst_helpers_comma_list_command_global_step \fi} -\def\globalprocesscommalist[#1]#2% - {\global\let\globalcommacommand#2% - \expandafter\globalprocesscommaitem#1,],} +\unexpanded\def\globalprocesscommalist[#1]#2% + {\global\let\m_syst_helpers_comma_list_command_global#2% + \expandafter\syst_helpers_comma_list_command_global_step#1,],} %D \macros %D {withoutpt,PtToCm, @@ -5082,36 +5128,36 @@ %D %D Beware: global! -\def\@sl@{@sl@} -\def\@sg@{@sg@} +\installsystemnamespace{localpushedmacro} +\installsystemnamespace{globalpushedmacro} -\let\@@pushedmacro\empty +\let\m_syst_helpers_push_macro\empty -\def\globalpushmacro#1% - {\xdef\@@pushedmacro{\string#1}% - \ifcsname\@sg@\@@pushedmacro\endcsname \else - \expandafter\newcount\csname\@sg@\@@pushedmacro\endcsname +\unexpanded\def\globalpushmacro#1% + {\xdef\m_syst_helpers_push_macro{\string#1}% + \ifcsname\??globalpushedmacro\m_syst_helpers_push_macro\endcsname \else + \expandafter\newcount\csname\??globalpushedmacro\m_syst_helpers_push_macro\endcsname \fi - \global\advance\csname\@sg@\@@pushedmacro\endcsname \plusone - \global\expandafter\let\csname\the\csname\@sg@\@@pushedmacro\endcsname\@@pushedmacro\endcsname#1} - -\def\globalpopmacro#1% - {\xdef\@@pushedmacro{\string#1}% - \global\expandafter\let\expandafter#1\csname\the\csname\@sg@\@@pushedmacro\endcsname\@@pushedmacro\endcsname - \global\advance\csname\@sg@\@@pushedmacro\endcsname \minusone} - -\def\localpushmacro#1% this one can be used to push a value over an \egroup - {\xdef\@@pushedmacro{\string#1}% - \ifcsname\@sl@\@@pushedmacro\endcsname \else - \expandafter\newcount\csname\@sl@\@@pushedmacro\endcsname + \global\advance\csname\??globalpushedmacro\m_syst_helpers_push_macro\endcsname \plusone + \global\expandafter\let\csname\the\csname\??globalpushedmacro\m_syst_helpers_push_macro\endcsname\m_syst_helpers_push_macro\endcsname#1} + +\unexpanded\def\globalpopmacro#1% + {\xdef\m_syst_helpers_push_macro{\string#1}% + \global\expandafter\let\expandafter#1\csname\the\csname\??globalpushedmacro\m_syst_helpers_push_macro\endcsname\m_syst_helpers_push_macro\endcsname + \global\advance\csname\??globalpushedmacro\m_syst_helpers_push_macro\endcsname \minusone} + +\unexpanded\def\localpushmacro#1% this one can be used to push a value over an \egroup + {\xdef\m_syst_helpers_push_macro{\string#1}% + \ifcsname\??localpushedmacro\m_syst_helpers_push_macro\endcsname \else + \expandafter\newcount\csname\??localpushedmacro\m_syst_helpers_push_macro\endcsname \fi - \global\advance\csname\@sl@\@@pushedmacro\endcsname \plusone - \global\expandafter\let\csname\the\csname\@sl@\@@pushedmacro\endcsname\@@pushedmacro\endcsname#1} + \global\advance\csname\??localpushedmacro\m_syst_helpers_push_macro\endcsname \plusone + \global\expandafter\let\csname\the\csname\??localpushedmacro\m_syst_helpers_push_macro\endcsname\m_syst_helpers_push_macro\endcsname#1} -\def\localpopmacro#1% - {\xdef\@@pushedmacro{\string#1}% - \expandafter\let\expandafter#1\csname\the\csname\@sl@\@@pushedmacro\endcsname\@@pushedmacro\endcsname - \global\advance\csname\@sl@\@@pushedmacro\endcsname \minusone } +\unexpanded\def\localpopmacro#1% + {\xdef\m_syst_helpers_push_macro{\string#1}% + \expandafter\let\expandafter#1\csname\the\csname\??localpushedmacro\m_syst_helpers_push_macro\endcsname\m_syst_helpers_push_macro\endcsname + \global\advance\csname\??localpushedmacro\m_syst_helpers_push_macro\endcsname \minusone } \let\pushmacro\localpushmacro \let\popmacro \localpopmacro @@ -5133,49 +5179,28 @@ %D These examples show us that an optional can be used. The %D value provided is added to \type{\localhsize}. -% todo: a fast non argument variant - \newdimen\localhsize -% \def\complexsetlocalhsize[#1]% don't change ! -% {\localhsize\hsize -% \ifnum\hangafter<\zerocount -% \advance\localhsize\ifdim\hangindent>\zeropoint-\fi\hangindent -% \fi -% \advance\localhsize -\leftskip -% \advance\localhsize -\rightskip -% \advance\localhsize #1\relax} -% -% \def\simplesetlocalhsize -% {\complexsetlocalhsize[\zeropoint]} -% -% \definecomplexorsimple\setlocalhsize - \unexpanded\def\setlocalhsize % don't change ! {\doifnextoptionalelse \syst_helpers_set_local_hsize_yes \syst_helpers_set_local_hsize_nop} -% \def\syst_helpers_set_local_hsize_nop -% {\localhsize\hsize -% \ifnum\hangafter<\zerocount -% \advance\localhsize\ifdim\hangindent>\zeropoint-\fi\hangindent -% \fi -% \advance\localhsize -\leftskip -% \advance\localhsize -\rightskip} - \def\syst_helpers_set_local_hsize_nop - {\localhsize\dimexpr - \hsize -\leftskip -\rightskip - \ifnum\hangafter<\zerocount - \ifdim\hangindent>\zeropoint-\else+\fi\hangindent - \fi - \relax} + {\localhsize\availablehsize} \def\syst_helpers_set_local_hsize_yes[#1]% {\syst_helpers_set_local_hsize_nop \advance\localhsize#1\relax} +\def\availablehsize + {\dimexpr + \hsize-\leftskip-\rightskip + \ifnum\hangafter<\zerocount + \ifdim\hangindent>\zeropoint-\else+\fi\hangindent + \fi + \relax} + %D \macros %D {doifvalue,doifnotvalue,doifelsevalue, %D doifnothing,doifsomething,doifelsenothing, @@ -5187,81 +5212,84 @@ %D tokens per call. Anyone familiar with the not||values %D ones, can derive their meaning from the definitions. -\def\doifvalue#1#2% - {\edef\!!stringa{\csname#1\endcsname}\edef\!!stringb{#2}% - \ifx\!!stringa\!!stringb +\unexpanded\def\doifvalue#1#2% + {\edef\m_syst_string_one{\csname#1\endcsname}% + \edef\m_syst_string_two{#2}% + \ifx\m_syst_string_one\m_syst_string_two \expandafter\firstofoneargument \else \expandafter\gobbleoneargument \fi} -\def\doifnotvalue#1#2% - {\edef\!!stringa{\csname#1\endcsname}\edef\!!stringb{#2}% - \ifx\!!stringa\!!stringb +\unexpanded\def\doifnotvalue#1#2% + {\edef\m_syst_string_one{\csname#1\endcsname}% + \edef\m_syst_string_two{#2}% + \ifx\m_syst_string_one\m_syst_string_two \expandafter\gobbleoneargument \else \expandafter\firstofoneargument \fi} -\def\doifelsevalue#1#2% - {\edef\!!stringa{\csname#1\endcsname}\edef\!!stringb{#2}% - \ifx\!!stringa\!!stringb +\unexpanded\def\doifelsevalue#1#2% + {\edef\m_syst_string_one{\csname#1\endcsname}% + \edef\m_syst_string_two{#2}% + \ifx\m_syst_string_one\m_syst_string_two \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments \fi} -\def\doifnothing#1% - {\edef\!!stringa{#1}% - \ifx\!!stringa\empty +\unexpanded\def\doifnothing#1% + {\edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\firstofoneargument \else \expandafter\gobbleoneargument \fi} -\def\doifsomething#1% - {\edef\!!stringa{#1}% - \ifx\!!stringa\empty +\unexpanded\def\doifsomething#1% + {\edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\gobbleoneargument \else \expandafter\firstofoneargument \fi} -\def\doifelsenothing#1% - {\edef\!!stringa{#1}% - \ifx\!!stringa\empty +\unexpanded\def\doifelsenothing#1% + {\edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments \fi} -\def\doifsomethingelse#1% - {\edef\!!stringa{#1}% - \ifx\!!stringa\empty +\unexpanded\def\doifsomethingelse#1% + {\edef\m_syst_string_one{#1}% + \ifx\m_syst_string_one\empty \expandafter\secondoftwoarguments \else \expandafter\firstoftwoarguments \fi} -\def\doifvaluenothing#1% - {\edef\!!stringa{\csname#1\endcsname}% - \ifx\!!stringa\empty +\unexpanded\def\doifvaluenothing#1% + {\edef\m_syst_string_one{\csname#1\endcsname}% + \ifx\m_syst_string_one\empty \expandafter\firstofoneargument \else \expandafter\gobbleoneargument \fi} -\def\doifvaluesomething#1% - {\edef\!!stringa{\csname#1\endcsname}% - \ifx\!!stringa\empty +\unexpanded\def\doifvaluesomething#1% + {\edef\m_syst_string_one{\csname#1\endcsname}% + \ifx\m_syst_string_one\empty \expandafter\gobbleoneargument \else \expandafter\firstofoneargument \fi} -\def\doifelsevaluenothing#1% - {\edef\!!stringa{\csname#1\endcsname}% - \ifx\!!stringa\empty +\unexpanded\def\doifelsevaluenothing#1% + {\edef\m_syst_string_one{\csname#1\endcsname}% + \ifx\m_syst_string_one\empty \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments @@ -5308,9 +5336,9 @@ \processcommalist[#3]\syst_helpers_do_common_check_all \ifdone\expandafter#1\else\expandafter#2\fi} -\def\doifallcommonelse{\syst_helpers_do_if_all_common_else\firstoftwoarguments\secondoftwoarguments} -\def\doifallcommon {\syst_helpers_do_if_all_common_else\firstofonearguments\gobbleoneargument } -\def\doifnotallcommon {\syst_helpers_do_if_all_common_else\gobbleoneargument \firstofonearguments } +\unexpanded\def\doifallcommonelse{\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 } %D \macros %D {DOIF,DOIFELSE,DOIFNOT} @@ -5328,39 +5356,42 @@ %D %D We have to use a two||step implementation, because the %D expansion has to take place outside \type{\uppercase}. +%D +%D These might up as \LUA based helpers (i.e. considere these +%D obsolete: \unexpanded\def\syst_helpers_do_IF#1#2% - {\uppercase{{$#1$}{$#2$}}% + {\uppercase{\syst_helpers_do_if_in_string_else{$#1$}{$#2$}}% \expandafter\firstofoneargument \else \expandafter\gobbleoneargument \fi} \unexpanded\def\syst_helpers_do_IF_NOT#1#2% - {\uppercase{{$#1$}{$#2$}}% + {\uppercase{\syst_helpers_do_if_in_string_else{$#1$}{$#2$}}% \expandafter\gobbleoneargument \else \expandafter\firstofoneargument \fi} \unexpanded\def\syst_helpers_do_IF_ELSE#1#2% - {\uppercase{{$#1$}{$#2$}}% + {\uppercase{\syst_helpers_do_if_in_string_else{$#1$}{$#2$}}% \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments \fi} \unexpanded\def\syst_helpers_do_IF_INSTRING_ELSE#1#2% - {\uppercase{{$#1$}{$#2$}}% + {\uppercase{\syst_helpers_do_if_in_string_else{$#1$}{$#2$}}% \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments \fi} -\unexpanded\def\DOIF #1#2{\normalexpanded{\syst_helpers_do_IF {#1}{#2}}} -\unexpanded\def\DOIFNOT #1#2{\normalexpanded{\syst_helpers_do_IF_NOT {#1}{#2}}} -\unexpanded\def\DOIFELSE #1#2{\normalexpanded{\syst_helpers_do_IF_ELSE {#1}{#2}}} -\unexpanded\def\DOIFINSTRINGELSE #1#2{\normalexpanded{\syst_helpers_do_IF_INSTRING_ELSE{#1}{#2}}} +\unexpanded\def\DOIF #1#2{\normalexpanded{\syst_helpers_do_IF {#1}{#2}}}% will become obsolete +\unexpanded\def\DOIFNOT #1#2{\normalexpanded{\syst_helpers_do_IF_NOT {#1}{#2}}}% will become obsolete +\unexpanded\def\DOIFELSE #1#2{\normalexpanded{\syst_helpers_do_IF_ELSE {#1}{#2}}}% will become obsolete +\unexpanded\def\DOIFINSTRINGELSE #1#2{\normalexpanded{\syst_helpers_do_IF_INSTRING_ELSE{#1}{#2}}}% will become obsolete %D \macros %D {dosingleargumentwithset, @@ -5396,25 +5427,25 @@ %D \starttyping %D \definesomething[alfa,beta,...][variable=...,...] %D \stoptyping -%D -%D Now a whole bunch of variables like \type{\@@xxalfavariable} -%D and \type{\@@xxbetavariable} is defined. -\def\dodoublewithset[#1][#2]% +\let\m_syst_helpers_with_set_command\empty +\let\syst_helpers_with_set_step \relax + +\def\syst_helpers_with_set_double[#1][#2]% {\doifsomething{#1} - {\def\@@dodowithsetcommand##1{\@@dowithsetcommand[##1][#2]}% - \processcommalist[#1]\@@dodowithsetcommand}} + {\def\syst_helpers_with_set_step##1{\m_syst_helpers_with_set_command[##1][#2]}% + \processcommalist[#1]\syst_helpers_with_set_step}} -\def\dotriplewithset[#1][#2][#3]% +\def\syst_helpers_with_set_triple[#1][#2][#3]% {\doifsomething{#1} - {\def\@@dodowithsetcommand##1{\@@dowithsetcommand[##1][#2][#3]}% - \processcommalist[#1]\@@dodowithsetcommand}} + {\def\syst_helpers_with_set_step##1{\m_syst_helpers_with_set_command[##1][#2][#3]}% + \processcommalist[#1]\syst_helpers_with_set_step}} -\def\dodoubleemptywithset #1{\let\@@dowithsetcommand#1\dodoubleempty \dodoublewithset} % \command -\def\dodoubleargumentwithset#1{\let\@@dowithsetcommand#1\dodoubleargument\dodoublewithset} % \command +\def\dodoubleemptywithset #1{\let\m_syst_helpers_with_set_command#1\dodoubleempty \syst_helpers_with_set_double} % \command +\def\dodoubleargumentwithset#1{\let\m_syst_helpers_with_set_command#1\dodoubleargument\syst_helpers_with_set_double} % \command -\def\dotripleemptywithset #1{\let\@@dowithsetcommand#1\dotripleempty \dotriplewithset} % \command -\def\dotripleargumentwithset#1{\let\@@dowithsetcommand#1\dotripleargument\dotriplewithset} % \command +\def\dotripleemptywithset #1{\let\m_syst_helpers_with_set_command#1\dotripleempty \syst_helpers_with_set_triple} % \command +\def\dotripleargumentwithset#1{\let\m_syst_helpers_with_set_command#1\dotripleargument\syst_helpers_with_set_triple} % \command %D \macros %D {stripcharacters,stripspaces} @@ -5441,16 +5472,18 @@ %D As we can see below, spaces following a control sequence are %D to enclosed in \type{{}}. -\def\stripcharacter#1\from#2\to#3% - {\def\dostripcharacter##1#1##2\end - {\edef\!!strippedstring{\!!strippedstring##1}% - \doifnotempty{##2}{\dostripcharacter##2\end}}% - \let\!!strippedstring\empty - \edef\!!stringa{#2}% - \expandafter\dostripcharacter\!!stringa#1\end - \dodoglobal\let#3\!!strippedstring} +\let\m_syst_helpers_strip_character\empty -\def\stripspaces\from#1\to#2% will become \unspacestring#1\from#2 +\unexpanded\def\stripcharacter#1\from#2\to#3% + {\def\syst_helpers_strip_character##1#1##2\end + {\edef\m_syst_helpers_strip_character{\m_syst_helpers_strip_character##1}% + \doifnotempty{##2}{\syst_helpers_strip_character##2\end}}% + \let\m_syst_helpers_strip_character\empty + \edef\m_syst_string_one{#2}% + \expandafter\syst_helpers_strip_character\m_syst_string_one#1\end + \dodoglobal\let#3\m_syst_helpers_strip_character} + +\unexpanded\def\stripspaces\from#1\to#2% will become \unspacestring#1\from#2 {\stripcharacter{ }\from#1\to#2} %D \macros @@ -5459,7 +5492,7 @@ %D The next macro does the same but is more compatible with other macros, %D like \type {\convert...}. -\def\unspacestring#1\to#2% +\unexpanded\def\unspacestring#1\to#2% {\stripcharacter{ }\from#1\to#2} %D \macros @@ -5482,8 +5515,6 @@ %D We can of course gobble more arguments using the %D appropriate gobbling command. -\newif\ifexecuted % general purpose - \def\executeifdefined#1% #2 / never change this one again {\ifcsname#1\endcsname \csname#1\expandafter\expandafter\expandafter\endcsname\expandafter\gobbleoneargument @@ -5510,65 +5541,15 @@ %D Is this one still needed? -\def\p!doifsomespaceelse#1 #2#3\war{\if\noexpand#2@} +\def\syst_helpers_if_some_space_else#1 #2#3\_e_o_s_{\if\noexpand#2@} -\def\doifsomespaceelse#1% % #2#3% - {\p!doifsomespaceelse#1 @ @\war % #3\else#2\fi} +\def\doifsomespaceelse#1% % #2#3% + {\syst_helpers_if_some_space_else#1 @ @\_e_o_s_ % #3\else#2\fi} \expandafter\secondoftwoarguments \else \expandafter\firstoftwoarguments \fi} -% %D \macros -% %D {adaptdimension,balancedimensions} -% %D -% %D Again we introduce some macros that are closely related to -% %D an interface aspect of \CONTEXT. The first command can be -% %D used to adapt a \DIMENSION. -% %D -% %D \starttyping -% %D \adaptdimension {dimension} {value} -% %D \stoptyping -% %D -% %D When the value is preceed by a \type{+} or minus, the -% %D dimension is advanced accordingly, otherwise it gets the -% %D value. -% -% \def\doadaptdimension#1#2\\#3\\% -% {\if#1+% -% \dodoglobal\advance -% \else\if#1-% -% \dodoglobal\advance -% \else -% \dodoglobal -% \fi\fi -% #3 #1#2\relax} -% -% \def\adaptdimension#1#2% -% {\expandafter\doadaptdimension#2\\#1\\} -% -% %D A second command takes two \DIMENSIONS. Both are adapted, -% %D depending on the sign of the given value. -% %D maat. This time we take the value as it is, and don't look -% %D explicitly at the preceding sign. -% %D -% %D \starttyping -% %D \balancedimensions {dimension 1} {dimension 2} {value} -% %D \stoptyping -% %D -% %D When a positive value is given, the first dimension is -% %D incremented, the second ond is decremented. A negative value -% %D has the opposite result. -% -% \def\balancedimensions#1#2#3% -% {\scratchdimen#3\relax -% \redoglobal\advance#1 \scratchdimen -% \dodoglobal\advance#2 -\scratchdimen} -% -% %D Both commands can be preceded by \type{\doglobal}. Here we -% %D use \type{\redo} first, because \type{\dodo} resets the -% %D global character. - %D \macros %D {processseparatedlist} %D @@ -5600,56 +5581,61 @@ %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% - {\def\!!stringa{##2}% suggested by VZ +\let\syst_helpers_process_separated_list_step\relax + +\def\syst_helpers_process_separated_list#1]#2[#3]#4% + {\def\syst_helpers_process_separated_list_step##1##2#3% + {\def\m_syst_string_one{##2}% suggested by VZ \if]##1% - \let\dodoprocessseparatedlist\relax - \else\ifx\blankspace\!!stringa + \let\syst_helpers_process_separated_list_step\relax + \else\ifx\blankspace\m_syst_string_one #4{##1}% \else\if]##2% - \let\dodoprocessseparatedlist\relax + \let\syst_helpers_process_separated_list_step\relax \else #4{##1##2}% \fi\fi\fi - \dodoprocessseparatedlist}% - \expandafter\dodoprocessseparatedlist\gobbleoneargument#1#3]#3} + \syst_helpers_process_separated_list_step}% + \expandafter\syst_helpers_process_separated_list_step\gobbleoneargument#1#3]#3} -\def\processseparatedlist[% - {\doprocessseparatedlist\relax} +\unexpanded\def\processseparatedlist[% + {\syst_helpers_process_separated_list\relax} %D \macros %D {processlist} %D -%D An even more general list processing macro is the -%D following one: +%D An even more general list processing macro is the following one: %D %D \starttyping %D \processlist{beginsym}{endsym}{separator}\docommand list %D \stoptyping %D -%D This one supports arbitrary open and close symbols as well -%D as user defined separators. +%D This one supports arbitrary open and close symbols as well as user +%D defined separators. %D %D \starttyping %D \processlist(){=>}\docommand(a=>b=>c=>d) %D \stoptyping -\def\processlist#1#2#3#4% no blank skipping ! - {\def\doprocesslist##1#2% - {\def\dodoprocesslist####1####2#3% +\let\syst_helpers_process_any_list \relax +\let\syst_helpers_process_any_list_indeed\relax +\let\syst_helpers_process_any_list_step \relax + +\unexpanded\def\processlist#1#2#3#4% no blank skipping ! + {\def\syst_helpers_process_any_list_indeed##1#2% + {\def\syst_helpers_process_any_list_step####1####2#3% {\ifx#2####1% - \let\dodoprocesslist\relax + \let\syst_helpers_process_any_list_step\relax \else\ifx#2####2% - \let\dodoprocesslist\relax + \let\syst_helpers_process_any_list_step\relax \else #4{####1####2}% \fi\fi - \dodoprocesslist}% - \expandafter\dodoprocesslist\gobbleoneargument##1#3#2#3}% - \def\dodoprocesslist#1% - {\doprocesslist\relax}% - \dodoprocesslist} + \syst_helpers_process_any_list_step}% + \expandafter\syst_helpers_process_any_list_step\gobbleoneargument##1#3#2#3}% + \def\syst_helpers_process_any_list#1% + {\syst_helpers_process_any_list_indeed\relax}% + \syst_helpers_process_any_list} %D \macros %D {processassignlist} @@ -5665,12 +5651,12 @@ %D This command can be integrated in \type{\getparameters}, but %D we decided best not to do so. -\def\processassignlist#1[#2]#3% - {\def\p!dodogetparameter[##1=##2=##3]% +\unexpanded\def\processassignlist#1[#2]#3% + {\def\syst_helpers_process_assign_list_assign[##1=##2=##3]% {\doifnot{##3}\relax{#3{##1}}}% - \def\p!dogetparameter##1% - {\p!dodogetparameter[##1==\relax]}% - \processcommalist[#2]\p!dogetparameter} + \def\syst_helpers_process_assign_list_step##1% + {\syst_helpers_process_assign_list_assign[##1==\relax]}% + \processcommalist[#2]\syst_helpers_process_assign_list_step} %D \macros %D {untextargument @@ -5687,20 +5673,22 @@ %D They remove braces and backslashes and give us something to %D sort. -\def\untexsomething +\let\m_syst_helpers_untexed\empty + +\unexpanded\def\untexsomething {\begingroup \catcode\leftbraceasciicode \ignorecatcode \catcode\rightbraceasciicode\ignorecatcode \escapechar\minusone - \dountexsomething} + \syst_helpers_untex_something} -\def\dountexsomething#1#2\to#3% - {\doglobal#1#2\to\untexedargument +\def\syst_helpers_untex_something#1#2\to#3% + {\doglobal#1#2\to\m_syst_helpers_untexed \endgroup - \let#3\untexedargument} + \let#3\m_syst_helpers_untexed} -\def\untexargument{\untexsomething\convertargument} -\def\untexcommand {\untexsomething\convertcommand} +\unexpanded\def\untexargument{\untexsomething\convertargument} +\unexpanded\def\untexcommand {\untexsomething\convertcommand} %D \macros %D {ScaledPointsToBigPoints,ScaledPointsToWholeBigPoints} @@ -5725,14 +5713,14 @@ % \PointsToWholeBigPoints{10.53941pt}\test \test % \PointsToWholeBigPoints{10.53942pt}\test \test -\def\PointsToBigPoints#1#2% +\unexpanded\def\PointsToBigPoints#1#2% {\edef#2{\withoutpt\the\dimexpr.996264\dimexpr#1\relax\relax}} -\def\PointsToWholeBigPoints#1#2% +\unexpanded\def\PointsToWholeBigPoints#1#2% {\edef#2{\the\numexpr\dimexpr.996264\dimexpr#1\relax\relax/\maxcard\relax}} -\def\ScaledPointsToBigPoints #1{\PointsToBigPoints {\number#1\scaledpoint}} -\def\ScaledPointsToWholeBigPoints#1{\PointsToWholeBigPoints{\number#1\scaledpoint}} +\unexpanded\def\ScaledPointsToBigPoints #1{\PointsToBigPoints {\number#1\scaledpoint}} +\unexpanded\def\ScaledPointsToWholeBigPoints#1{\PointsToWholeBigPoints{\number#1\scaledpoint}} %D \macros %D {PointsToReal} @@ -5744,9 +5732,8 @@ %D \PointsToReal {dimension} \target %D \stoptyping -\def\PointsToReal#1#2% - {\scratchdimen#1% - \edef#2{\withoutpt\the\scratchdimen}} +\unexpanded\def\PointsToReal#1#2% + {\edef#2{\withoutpt\the\dimexpr#1}} %D \macros %D {dontleavehmode} @@ -5777,16 +5764,17 @@ %D %D And finaly we got the following alternative, one that avoids %D interfering grouping at the cost of a box. - -\newbox\@@dlhbox - -\unexpanded\def\dontleavehmode - {\ifhmode\else \ifmmode\else - \setbox\@@dlhbox\hbox{\mathsurround\zeropoint\everymath\emptytoks$ $}\unhbox\@@dlhbox - \fi \fi} - -%D But, if you run a recent version of \TEX, we can use the new -%D primitive: +%D +%D \starttyping +%D \newbox\b_syst_helpers_dlh +%D +%D \unexpanded\def\dontleavehmode +%D {\ifhmode\else \ifmmode\else +%D \setbox\b_syst_helpers_dlh\hbox{\mathsurround\zeropoint\everymath\emptytoks$ $}\unhbox\b_syst_helpers_dlh +%D \fi \fi} +%D \stoptyping +%D +%D But, as we run a recent version of \TEX, we can use the new primitive: \ifdefined\normalquitvmode \let\dontleavehmode\normalquitvmode \fi @@ -5800,14 +5788,17 @@ %D \lowercasestring somestring\to\somestring %D \stoptyping %D -%D the first argument may be a \type{\macro}. +%D The first argument may be a \type{\macro}. -\def\uppercasestring#1\to#2% +\unexpanded\def\uppercasestring#1\to#2% {\uppercase\expandafter{\expandafter\dodoglobal\expandafter\edef\expandafter#2\expandafter{\normalexpanded{#1}}}} -\def\lowercasestring#1\to#2% +\unexpanded\def\lowercasestring#1\to#2% {\lowercase\expandafter{\expandafter\dodoglobal\expandafter\edef\expandafter#2\expandafter{\normalexpanded{#1}}}} +%D These macros are sort of obsolete as we never use uppercase this +%D way. + %D \macros %D {handletokens} %D @@ -5843,25 +5834,26 @@ %D takes a real counter. The macro can be preceded by \type %D {\doglobal}. -\def\counttoken#1\in#2\to#3% +\def\syst_helpers_count_token#1% obeys {} + {\def\m_syst_string_three{#1}% + \ifx\m_syst_string_two\m_syst_string_three \else + \ifx\m_syst_string_one\m_syst_string_three + \advance\scratchcounter\plusone + \fi + \expandafter\syst_helpers_count_token + \fi} + +\unexpanded\def\counttoken#1\in#2\to#3% {\scratchcounter\zerocount - \def\!!stringa{#1}% - \def\!!stringb{\end}% - \def\docounttoken##1% obeys {} - {\def\!!stringc{##1}% - \ifx\!!stringb\!!stringc \else - \ifx\!!stringa\!!stringc - \advance\scratchcounter\plusone - \fi - \expandafter\docounttoken - \fi}% - \docounttoken#2\end + \def\m_syst_string_one{#1}% + \def\m_syst_string_two{\end}% + \syst_helpers_count_token#2\end \dodoglobal#3\scratchcounter} -\def\counttokens#1\to#2% +\unexpanded\def\counttokens#1\to#2% {\scratchcounter\zerocount - \def\docounttoken##1{\advance\scratchcounter\plusone}% - \handletokens#1\with\docounttoken + \def\syst_helpers_count_token##1{\advance\scratchcounter\plusone}% + \handletokens#1\with\syst_helpers_count_token \dodoglobal#2\scratchcounter} %D \macros @@ -5871,17 +5863,17 @@ %D Consider for instance the macro for which I originally %D wrote this token handler. -\def\splitofftokens#1\from#2\to#3% slow but hardly used +\unexpanded\def\splitofftokens#1\from#2\to#3% slow but hardly used {\ifnum#1>\zerocount \scratchcounter#1\relax - \def\dosplitofftokens##1% + \def\syst_helpers_split_off_tokens##1% {\ifnum\scratchcounter>\zerocount \advance\scratchcounter \minusone \edef#3{#3##1}% \fi}% % \let#3\empty % #3 can be #2, so: \expandafter\let\expandafter#3\expandafter\empty - \expandafter\handletokens#2\with\dosplitofftokens + \expandafter\handletokens#2\with\syst_helpers_split_off_tokens \else \edef#3{#2}% \fi} @@ -5918,27 +5910,27 @@ %D way we can handle the sentinal, a blank space and grouped %D tokens. -\def\dohandletokens % \nexthandledtoken is part of interface - {\futurelet\nexthandledtoken\dodohandletokens} +\unexpanded\def\syst_helpers_handle_tokens % \nexthandledtoken is part of interface + {\futurelet\nexthandledtoken\syst_helpers_handle_tokens_indeed} \def\handletokens#1\with#2% - {\gdef\dododohandletokens{#2}% permits more complex #2's - \dohandletokens#1\end} + {\gdef\syst_helpers_handle_tokens_command{#2}% permits more complex #2's + \syst_helpers_handle_tokens#1\end} -\def\dodohandletokens +\def\syst_helpers_handle_tokens_indeed {\ifx\nexthandledtoken\blankspace - \expandafter\dodohandletokensone + \expandafter\syst_helpers_handle_tokens_indeed_one \else\ifx\nexthandledtoken\end \expandafter\expandafter\expandafter\gobbletwoarguments % also gobble the \end \else - \expandafter\expandafter\expandafter\dodohandletokenstwo + \expandafter\expandafter\expandafter\syst_helpers_handle_tokens_indeed_two \fi\fi *} -\def\dodohandletokensone * % - {\dododohandletokens{ }\dohandletokens} +\def\syst_helpers_handle_tokens_indeed_one * % + {\syst_helpers_handle_tokens_command{ }\syst_helpers_handle_tokens} -\def\dodohandletokenstwo *#1% - {\dododohandletokens{#1}\dohandletokens} +\def\syst_helpers_handle_tokens_indeed_two *#1% + {\syst_helpers_handle_tokens_command{#1}\syst_helpers_handle_tokens} %D This macro is tested on: %D @@ -6021,130 +6013,35 @@ %D This macro is first used in the tabulation macros. \unexpanded\def\processcontent#1% - {\begingroup\expandafter\doprocesscontent\csname#1\endcsname} + {\begingroup\expandafter\syst_helpers_process_content\csname#1\endcsname} -\unexpanded\def\doprocesscontent#1#2#3% - {\unexpanded\def\doprocesscontent##1#1% +\unexpanded\def\syst_helpers_process_content#1#2#3% + {\unexpanded\def\syst_helpers_process_content##1#1% {\endgroup\def#2{##1}#3}% - \doprocesscontent} + \syst_helpers_process_content} %D \macros %D {dogobblesingleempty, dogobbledoubleempty} %D %D These two macros savely grab and dispose two arguments. -\def\dogobblesingleempty{\dosingleempty\dodogobblesingleempty} -\def\dogobbledoubleempty{\dodoubleempty\dodogobbledoubleempty} +\def\dogobblesingleempty{\dosingleempty\syst_helpers_gobble_single_empty} +\def\dogobbledoubleempty{\dodoubleempty\syst_helpers_gobble_double_empty} -\def\dodogobblesingleempty [#1]{} -\def\dodogobbledoubleempty[#1][#2]{} +\def\syst_helpers_gobble_single_empty [#1]{} +\def\syst_helpers_gobble_double_empty[#1][#2]{} \let\gobblesingleempty\dogobblesingleempty % also used \let\gobbledoubleempty\dogobbledoubleempty % also used %D \macros -%D {sortcommalist,sortcommacommand, -%D donumericcompare,comparedresult} -%D -%D Sometimes we need to sort a commalist, so here is Taco's -%D solution. This will in many cases be a list that is stored -%D in a \type{\csname}, so both commalist and commacommands are -%D supported. The sorting algorithm is very simple, so the list -%D should not be too long or sorting will be very slow. -%D -%D \starttyping -%D \sortcommalist[10,2,4,5,6,1,2,3,4,10,20]\donumericcompare -%D -%D \def\test{10,2,4,5,6,1,2,3,4,10,20} -%D -%D \sortcommacommand[\test]\donumericcompare -%D \stoptyping -%D -%D In both cases, the result is available in the macro \type -%D {\sortedcommalist}. -%D -%D Parameter \type{#2} is a macro that should accept two -%D parameters, and it has to decide which one is larger, by -%D setting the counter \type{\comparedresult} to~0 (for equal), -%D 1~(if it's first argument is larger), or~2 (if it's second -%D argument is larger). -%D -%D As said, these macro are largely written by Taco, and are -%D (maybe therefore) also the first application of \type -%D {\replaceincommalist}. - -\newcount\comparedresult - -\def\sortcommacommand[#1]% - {\expandafter\sortcommalist\expandafter[#1]} - -\def\sortcommalist[#1]#2% - {\getcommalistsize[#1]% - \ifnum\commalistsize>1 - \let\sortedcommalist\empty - \let\comparecommand#2% - \processcommalist[#1]\dosortcommacommand - \else - \def\sortedcommalist{#1}% - \fi} - -\def\dosortcommacommand#1% - {\ifx\sortedcommalist\empty - \def\sortedcommalist{#1}% - \else - \def\!!tempa{#1}% - \ifx\!!tempa\empty\else - \scratchcounter\plusone - \expandafter\getcommalistsize\expandafter[\sortedcommalist]% - \expandafter\processcommalist\expandafter[\sortedcommalist]\docompareitems - \fi - \fi} - -%D All those \type{\expandafter}'s are there because I do not -%D want to use \type{\edef}. - -\def\docompareitems#1% - {\doifnotempty{#1} - {\expandafter\comparecommand\expandafter{\!!tempa}{#1}\relax - %\ifcase\compareresult % equal - \ifnum\comparedresult<2 - \ifnum\scratchcounter=\commalistsize - \expandafter\expandafter\expandafter\def - \expandafter\expandafter\expandafter\sortedcommalist - \expandafter\expandafter\expandafter{\expandafter\sortedcommalist\expandafter,\!!tempa}% - \fi - %\or % new element larger - % \ifnum\scratchcounter=\commalistsize - % \expandafter\expandafter\expandafter\def - % \expandafter\expandafter\expandafter\sortedcommalist - % \expandafter\expandafter\expandafter{\expandafter\sortedcommalist\expandafter,\!!tempa}% - % \fi - \else % old element larger - \expandafter\def\expandafter\newcommalistelement\expandafter{\!!tempa,#1}% - \replaceincommalist\sortedcommalist\scratchcounter - \expandafter\quitcommalist - \fi}% - \advance\scratchcounter \plusone} % bug, was \minusone - -%D The macro \type{\donumericcompare} considers everything -%D that is not a number to be larger than any number. - -% 0: both are equal, 1: #1 is larger, 2: #2 is larger - -\def\thenumericcompare#1#2% no \relax es inside hee - {\doifnumberelse{#1} - {\doifnumberelse{#2}{\ifnum#1>#2 \plusone\else\ifnum#1<#2 \plustwo\else\zerocount\fi\fi}\plustwo} - \plusone} - -\def\donumericcompare - {\comparedresult\thenumericcompare} - -%D \macros %D {@True, @False, @Not, @And} %D %D Some predicate logic functions, used in for instance the %D math module. +% These have rather ugly names ... will change: + \def\@True {00} \def\@False {01} \def\@Not #1{0\ifcase#11 \or\expandafter 1\else \expandafter 0\fi} @@ -6167,10 +6064,10 @@ %D assignment inside a box. The \type{\empty}'s permits %D gobbling while preventing spurious \type{\relax}'s. -\def\setdimensionwithunit#1#2#3% number unit dimension / nice trick +\unexpanded\def\setdimensionwithunit#1#2#3% number unit dimension / nice trick {\afterassignment\gobblefourarguments#1=#2#3pt\relax\empty\empty\empty\empty} -\def\freezedimensionwithunit#1#2% +\unexpanded\def\freezedimensionwithunit#1#2% {\setdimensionwithunit\scratchdimen#1{#2}\edef#1{\the\scratchdimen}} %D \macros @@ -6179,25 +6076,25 @@ %D Not that fast I guess, but here's a way to test for token %D registers being empty. -\def\doifsometokselse#1% - {\edef\!!stringa{\the#1}% one level expansion so quite ok - \ifx\!!stringa\empty +\unexpanded\def\doifsometokselse#1% + {\edef\m_syst_string_one{\the#1}% one level expansion so quite ok + \ifx\m_syst_string_one\empty \expandafter\secondoftwoarguments \else \expandafter\firstoftwoarguments \fi} -\def\doifsometoks#1% - {\edef\!!stringa{\the#1}% one level expansion so quite ok - \ifx\!!stringa\empty +\unexpanded\def\doifsometoks#1% + {\edef\m_syst_string_one{\the#1}% one level expansion so quite ok + \ifx\m_syst_string_one\empty \expandafter\gobbleoneargument \else \expandafter\firstofoneargument \fi} -\def\doifemptytoks#1% - {\edef\!!stringa{\the#1}% one level expansion so quite ok - \ifx\!!stringa\empty +\unexpanded\def\doifemptytoks#1% + {\edef\m_syst_string_one{\the#1}% one level expansion so quite ok + \ifx\m_syst_string_one\empty \expandafter\firstofoneargument \else \expandafter\gobbleoneargument @@ -6212,9 +6109,9 @@ \def\syst_helpers_strict_inspect_next_character% no user macro ! {\ifx\nexttoken\charactertoken - \expandafter\!!stringa + \expandafter\m_syst_action_yes \else - \expandafter\!!stringb + \expandafter\m_syst_action_nop \fi} % better: push/pop @@ -6267,10 +6164,14 @@ %D %D Concatenate commalists: -\def\serializecommalist[#1]% +\let\syst_helpers_serialize_comma_list_step\relax + +\def\syst_helpers_serialize_comma_list_step#1% + {\edef\serializedcommalist{\serializedcommalist#1}} + +\unexpanded\def\serializecommalist[#1]% {\let\serializedcommalist\empty - \def\docommand##1{\edef\serializedcommalist{\serializedcommalist##1}}% - \processcommacommand[#1]\docommand} + \processcommacommand[#1]\syst_helpers_serialize_comma_list_step} %D \macros %D {purenumber} @@ -6346,7 +6247,7 @@ \def\filterfromvalue#1#2#3% value max n {\expandafter\doubleexpandafter\csname % we use the fact that an \expandafter\ifx\csname#1\endcsname\relax % undefined cs has become \relax - \strippedcsname\gobbleoneargument % which we then gobble here + \strippedcsname\gobbleoneargument % which we then gobble here \else \dofilterfromstr{#2}{#3}% \fi @@ -6364,13 +6265,27 @@ %D ... \measure{mywidth} ... %D \stoptyping -\def\??dm{@@dm} % brrr +\installsystemnamespace{measure} \unexpanded\def\definemeasure - {\dodoubleargument\dodefinemeasure} + {\dodoubleargument\syst_helpers_define_measure} + +\def\syst_helpers_define_measure[#1][#2]% + {\expandafter\def\csname\??measure#1\endcsname{#2}} -\def\dodefinemeasure[#1][#2]% - {\expandafter\def\csname\??dm#1\endcsname{#2}} +\unexpanded\def\freezemeasure + {\dodoubleargument\syst_helpers_freeze_measure} + +\def\syst_helpers_freede_measure[#1][#2]% + {\expandafter\edef\csname\??measure#1\endcsname{\the\dimexpr#2}} + +\unexpanded\def\setmeasure #1#2{\expandafter\def \csname\??measure#1\endcsname{#2}} % quick way +\unexpanded\def\setgmeasure#1#2{\expandafter\gdef\csname\??measure#1\endcsname{#2}} % quick way +\unexpanded\def\setemeasure#1#2{\expandafter\edef\csname\??measure#1\endcsname{\the\dimexpr#2}} % quick way +\unexpanded\def\setxmeasure#1#2{\expandafter\xdef\csname\??measure#1\endcsname{\the\dimexpr#2}} % quick way + +\def\measure#1% maybe \dimexpr ... \relax + {\ifcsname\??measure#1\endcsname\csname\??measure#1\endcsname\else\zeropoint\fi} % #2 could be omitted, but we want to support spaces % @@ -6378,13 +6293,21 @@ % \setmeasure {xx} {1cm} % \setmeasure {xxx}{1cm} -\unexpanded\def\setmeasure #1#2{\expandafter\def \csname\??dm#1\endcsname{#2}} % quick way -\unexpanded\def\setemeasure#1#2{\expandafter\edef\csname\??dm#1\endcsname{#2}} % quick way -\unexpanded\def\setgmeasure#1#2{\expandafter\gdef\csname\??dm#1\endcsname{#2}} % quick way -\unexpanded\def\setxmeasure#1#2{\expandafter\xdef\csname\??dm#1\endcsname{#2}} % quick way +%D \macros +%D {dividedsize} +%D +%D This one can be used inside a measure (used in m4all): +%D +%D \starttyping +%D \definemeasure[columnwidth][\dividedsize\textwidth{1em}{3}] +%D \stoptyping -\def\measure#1% maybe \dimexpr ... \relax - {\ifcsname\??dm#1\endcsname\csname\??dm#1\endcsname\else\zeropoint\fi} +\def\dividedsize#1#2#3% size gap n + {\dimexpr + \ifnum\dimexpr#1\relax>\plusone + (\dimexpr#1\relax-\numexpr#3-\plusone\relax\dimexpr#2\relax)/#3\else#1% + \fi + \relax} %D \macros %D {doifdimensionelse} @@ -6392,9 +6315,9 @@ %D This is a dirty one: we simply append a unit and discard it when needed. \def\doifdimensionelse#1% - {\afterassignment\dodoifdimensionelse\scratchdimen#1pt\relax} + {\afterassignment\syst_helpers_if_dimension_else\scratchdimen#1pt\relax} -\def\dodoifdimensionelse#1% +\def\syst_helpers_if_dimension_else#1% {\ifx#1\relax \expandafter\secondoftwoarguments \else % #1=p ... t\relax @@ -6418,53 +6341,57 @@ %D \NC 1 \NC \doifdimenstringelse {1}{yes}{no} \NC \NR %D \stoptabulate +\installsystemnamespace{dimenchecka} +\installsystemnamespace{dimencheckb} +\installsystemnamespace{dimencheckc} + \def\doifdimenstringelse#1{\normalexpanded{\noexpand\dodimenteststageone#1}\empty\empty]} -\def\dodimenteststageone #1#2{\csname d!1!\ifcsname d!1!#2\endcsname#2\else x\fi\endcsname#2} -\def\dodimenteststagetwo #1#2{\csname d!2!\ifcsname d!2!#2\endcsname#2\else x\fi\endcsname#2} -\def\dodimenteststagethree #1]{\csname d!3!\ifcsname d!3!#1\endcsname#1\else x\fi\endcsname} - -\expandafter\let\csname d!1!x\endcsname\dodimenteststagethree -\expandafter\let\csname d!2!x\endcsname\dodimenteststagethree -\expandafter\let\csname d!3!x\endcsname\secondoftwoarguments - -\expandafter\let\csname d!1!.\endcsname\dodimenteststagetwo -\expandafter\let\csname d!1!,\endcsname\dodimenteststagetwo -\expandafter\let\csname d!1!1\endcsname\dodimenteststageone -\expandafter\let\csname d!1!2\endcsname\dodimenteststageone -\expandafter\let\csname d!1!3\endcsname\dodimenteststageone -\expandafter\let\csname d!1!4\endcsname\dodimenteststageone -\expandafter\let\csname d!1!5\endcsname\dodimenteststageone -\expandafter\let\csname d!1!6\endcsname\dodimenteststageone -\expandafter\let\csname d!1!7\endcsname\dodimenteststageone -\expandafter\let\csname d!1!8\endcsname\dodimenteststageone -\expandafter\let\csname d!1!9\endcsname\dodimenteststageone -\expandafter\let\csname d!1!0\endcsname\dodimenteststageone - -\expandafter\let\csname d!2!1\endcsname\dodimenteststagetwo -\expandafter\let\csname d!2!2\endcsname\dodimenteststagetwo -\expandafter\let\csname d!2!3\endcsname\dodimenteststagetwo -\expandafter\let\csname d!2!4\endcsname\dodimenteststagetwo -\expandafter\let\csname d!2!5\endcsname\dodimenteststagetwo -\expandafter\let\csname d!2!6\endcsname\dodimenteststagetwo -\expandafter\let\csname d!2!7\endcsname\dodimenteststagetwo -\expandafter\let\csname d!2!8\endcsname\dodimenteststagetwo -\expandafter\let\csname d!2!9\endcsname\dodimenteststagetwo -\expandafter\let\csname d!2!0\endcsname\dodimenteststagetwo - -\expandafter\let\csname d!3!pt\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!pc\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!in\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!bp\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!cm\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!mm\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!dd\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!cc\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!sp\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!ex\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!em\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!nd\endcsname\firstoftwoarguments -\expandafter\let\csname d!3!nc\endcsname\firstoftwoarguments +\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} +\def\dodimenteststagethree #1]{\csname \??dimencheckc\ifcsname \??dimencheckc#1\endcsname#1\else x\fi\endcsname} + +\expandafter\let\csname \??dimenchecka x\endcsname\dodimenteststagethree +\expandafter\let\csname \??dimencheckb x\endcsname\dodimenteststagethree +\expandafter\let\csname \??dimencheckc x\endcsname\secondoftwoarguments + +\expandafter\let\csname \??dimenchecka.\endcsname\dodimenteststagetwo +\expandafter\let\csname \??dimenchecka,\endcsname\dodimenteststagetwo +\expandafter\let\csname \??dimenchecka1\endcsname\dodimenteststageone +\expandafter\let\csname \??dimenchecka2\endcsname\dodimenteststageone +\expandafter\let\csname \??dimenchecka3\endcsname\dodimenteststageone +\expandafter\let\csname \??dimenchecka4\endcsname\dodimenteststageone +\expandafter\let\csname \??dimenchecka5\endcsname\dodimenteststageone +\expandafter\let\csname \??dimenchecka6\endcsname\dodimenteststageone +\expandafter\let\csname \??dimenchecka7\endcsname\dodimenteststageone +\expandafter\let\csname \??dimenchecka8\endcsname\dodimenteststageone +\expandafter\let\csname \??dimenchecka9\endcsname\dodimenteststageone +\expandafter\let\csname \??dimenchecka0\endcsname\dodimenteststageone + +\expandafter\let\csname \??dimencheckb1\endcsname\dodimenteststagetwo +\expandafter\let\csname \??dimencheckb2\endcsname\dodimenteststagetwo +\expandafter\let\csname \??dimencheckb3\endcsname\dodimenteststagetwo +\expandafter\let\csname \??dimencheckb4\endcsname\dodimenteststagetwo +\expandafter\let\csname \??dimencheckb5\endcsname\dodimenteststagetwo +\expandafter\let\csname \??dimencheckb6\endcsname\dodimenteststagetwo +\expandafter\let\csname \??dimencheckb7\endcsname\dodimenteststagetwo +\expandafter\let\csname \??dimencheckb8\endcsname\dodimenteststagetwo +\expandafter\let\csname \??dimencheckb9\endcsname\dodimenteststagetwo +\expandafter\let\csname \??dimencheckb0\endcsname\dodimenteststagetwo + +\expandafter\let\csname \??dimencheckc pt\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc pc\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc in\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc bp\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc cm\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc mm\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc dd\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc cc\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc sp\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc ex\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc em\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc nd\endcsname\firstoftwoarguments +\expandafter\let\csname \??dimencheckc nc\endcsname\firstoftwoarguments %D \macros %D {comparedimension,comparedimensioneps} @@ -6502,51 +6429,51 @@ % \copycsname xxx\endcsname\csname ..\endcsname -\def\copycsname{\expandafter\expandafter\expandafter\let\expandafter\expandafter\csname} +\unexpanded\def\copycsname{\expandafter\expandafter\expandafter\let\expandafter\expandafter\csname} % \letcscsname \crap \csname ..\endcsname % \letcsnamecs \csname ..\endcsname\crap % \letcsnamecsname\csname ..\endcsname\csname ..\endcsname -\def\letcscsname {\expandafter\let\expandafter} -\def\letcsnamecs {\expandafter\let} -\def\letcsnamecsname{\expandafter\expandafter\expandafter\let\expandafter\expandafter} +\unexpanded\def\letcscsname {\expandafter\let\expandafter} +\unexpanded\def\letcsnamecs {\expandafter\let} +\unexpanded\def\letcsnamecsname{\expandafter\expandafter\expandafter\let\expandafter\expandafter} % another one, add an item to a commalist -\def\addvalue#1#2% cs item +\unexpanded\def\addvalue#1#2% cs item {\ifcsname#1\endcsname\else\expandafter\let\csname#1\endcsname\empty\fi \normalexpanded{\noexpand\addtocommalist{#2}\expandafter\noexpand\csname#1\endcsname}} \def\unspaced#1% - {\dounspaced#1\end} + {\syst_helpers_unspaced#1\end} -\def\dounspaced#1% +\def\syst_helpers_unspaced#1% {\ifx#1\end \expandafter\gobbleoneargument \else \ifx#1\blankspace\else#1\fi \fi - \dounspaced} + \syst_helpers_unspaced} -\def\unspaceargument#1\to#2% +\unexpanded\def\unspaceargument#1\to#2% {\scratchcounter\catcode\spaceasciicode \catcode\spaceasciicode\ignorecatcode \scantextokens{\edef#2{#1}}% \catcode\spaceasciicode\scratchcounter} -\def\unspaceafter#1#2% +\unexpanded\def\unspaceafter#1#2% {\unspaceargument#2\to\ascii \expandafter#1\expandafter{\ascii}} % sometimes handy: -\def\doifhasspaceelse#1% - {\edef\!!stringa{#1}% - \normalexpanded{\noexpand\dodoifhasspaceelse#1\space}\empty\relax} +\unexpanded\def\doifhasspaceelse#1% + {\edef\m_syst_string_one{#1}% + \normalexpanded{\syst_helpers_if_has_space_else#1\space}\empty\relax} -\def\dodoifhasspaceelse#1 #2#3\relax % \space\empty\relax - {\ifx\!!stringa\space +\unexpanded\def\syst_helpers_if_has_space_else#1 #2#3\relax % \space\empty\relax + {\ifx\m_syst_string_one\space \expandafter\firstoftwoarguments \else\ifx#2\empty \doubleexpandafter\secondoftwoarguments @@ -6556,67 +6483,35 @@ % this will replace loadfile once and alike !!! todo -\def\@flg@{@flg@} - -\def\setflag #1{\expandafter\dodoglobal\expandafter\let\csname\@flg@#1\endcsname\zerocount} -\def\resetflag#1{\expandafter\dodoglobal\expandafter\let\csname\@flg@#1\endcsname\plusone} +\installsystemnamespace{flag} -\let\ifflagged\ifcase +\unexpanded\def\setflag #1{\expandafter\dodoglobal\expandafter\let\csname\??flag#1\endcsname\zerocount} +\unexpanded\def\resetflag#1{\expandafter\dodoglobal\expandafter\let\csname\??flag#1\endcsname\plusone} -\def\flag#1{\csname\@flg@#1\endcsname} +\def\flag#1{\csname\??flag#1\endcsname} \def\doifelseflagged#1% - {\expandafter\ifx\csname\@flg@#1\endcsname\relax + {\expandafter\ifx\csname\??flag#1\endcsname\relax \expandafter\secondoftwoarguments - \else\ifcase\csname\@flg@#1\endcsname + \else\ifcase\csname\??flag#1\endcsname \doubleexpandafter\firstoftwoarguments \else \doubleexpandafter\secondoftwoarguments \fi\fi} \def\doifnotflagged#1% - {\expandafter\ifx\csname\@flg@#1\endcsname\relax + {\expandafter\ifx\csname\??flag#1\endcsname\relax \expandafter\firstofoneargument - \else\ifcase\csname\@flg@#1\endcsname + \else\ifcase\csname\??flag#1\endcsname \doubleexpandafter\gobbleoneargument \else \doubleexpandafter\firstofoneargument \fi\fi} -\def\inheritparameter[#1]#2[#3]#4[#5]% tag tokey fromkey +\unexpanded\def\inheritparameter[#1]#2[#3]#4[#5]% tag tokey fromkey {\expandafter\def\csname#1#3\expandafter\endcsname\expandafter{\csname#1#5\endcsname}} -% \buildarray[test][aa,bb,cc,dd,ee,ff] -% \setarrayelement{test}{1}{qq} -% \arrayelement{test}{1} -% \arraylength{test} -% -% \def\buildarray[#1][#2]% -% {\scratchcounter=0 -% \def\docommand##1% -% {\advance\scratchcounter by 1 -% \setvalue{@@aa#1\the\scratchcounter}{##1}}% -% \processcommalist[#2]\docommand -% \setevalue{@@aa#1}{\the\scratchcounter}}% -% -% \def\setarrayelement#1#2{\setvalue{@@aa#1#2}} -% \def\arrayelement #1#2{\getvalue{@@aa#1#2}} -% \def\arraylength #1{\getvalue{@@aa#1}} - -% \newsignal\junksignal -% -% \def\setjunksignal% -% {\ifhmode -% \hskip\junksignal -% \let\removejunkspaces\doremovejunkspaces -% \else -% \let\removejunkspaces\relax -% \fi} -% -% \def\doremovejunkspaces% -% {\doloop{\ifdim\lastskip=\junksignal\unskip\else\exitloop\fi}} - -\def\dodoifnonzeropositiveelse#1#2\end % #3#4% +\def\syst_helpers_if_non_zero_positive_else#1#2\end % #3#4% {\ifx#1\relax \ifcase\scratchcounter \endgroup @@ -6631,45 +6526,42 @@ \fi} \def\doifnonzeropositiveelse#1% - {\begingroup\afterassignment\dodoifnonzeropositiveelse\scratchcounter=0#1\relax\empty\end} + {\begingroup\afterassignment\syst_helpers_if_non_zero_positive_else\scratchcounter=0#1\relax\empty\end} % here ? -\def\dosetrawvalue #1#2#3{\expandafter \def\csname#1#2\endcsname{#3}} -\def\dosetrawevalue#1#2#3{\expandafter\edef\csname#1#2\endcsname{#3}} -\def\dosetrawgvalue#1#2#3{\expandafter\gdef\csname#1#2\endcsname{#3}} -\def\dosetrawxvalue#1#2#3{\expandafter\xdef\csname#1#2\endcsname{#3}} +\unexpanded\def\dosetrawvalue #1#2#3{\expandafter \def\csname#1#2\endcsname{#3}} +\unexpanded\def\dosetrawevalue#1#2#3{\expandafter\edef\csname#1#2\endcsname{#3}} +\unexpanded\def\dosetrawgvalue#1#2#3{\expandafter\gdef\csname#1#2\endcsname{#3}} +\unexpanded\def\dosetrawxvalue#1#2#3{\expandafter\xdef\csname#1#2\endcsname{#3}} -\def\getrawparameters {\dogetparameters\dosetrawvalue } -\def\getraweparameters {\dogetparameters\dosetrawevalue} -\def\getrawgparameters {\dogetparameters\dosetrawgvalue} -\def\getrawxparameters {\dogetparameters\dosetrawxvalue} +\unexpanded\def\getrawparameters {\dogetparameters\dosetrawvalue } +\unexpanded\def\getraweparameters {\dogetparameters\dosetrawevalue} +\unexpanded\def\getrawgparameters {\dogetparameters\dosetrawgvalue} +\unexpanded\def\getrawxparameters {\dogetparameters\dosetrawxvalue} -\def\globalgetrawparameters{\dogetparameters\dosetrawgvalue} % obsolete - -\def\splitskip#1% - {\scratchskip#1\relax - \dimen0\scratchskip - \dimen2\gluestretch\scratchskip - \dimen4\glueshrink\scratchskip} +\unexpanded\def\globalgetrawparameters{\dogetparameters\dosetrawgvalue} % obsolete -\newcount\modcounter +%D Sort of obsolete: -\def\dosetmodulo#1#2#3% - {\modcounter#1\divide\modcounter#2\multiply\modcounter#2% - #3#1\advance#3-\modcounter} +\newcount\c_syst_helpers_mod -\def\dosetdivision#1#2#3% +\unexpanded\def\dosetmodulo#1#2#3% + {\c_syst_helpers_mod#1\divide\c_syst_helpers_mod#2\multiply\c_syst_helpers_mod#2% + #3#1\advance#3-\c_syst_helpers_mod} + +\unexpanded\def\dosetdivision#1#2#3% {#3#1\divide#3 #2\relax} -\def\DoMod#1by#2to#3{\dosetmodulo {#1}{#2}{#3}} -\def\DoDiv#1by#2to#3{\dosetdivision{#1}{#2}{#3}} +\unexpanded\def\DoMod#1by#2to#3{\dosetmodulo {#1}{#2}{#3}} +\unexpanded\def\DoDiv#1by#2to#3{\dosetdivision{#1}{#2}{#3}} -\def\dounprotected#1\par +\def\syst_helpers_unprotected#1\par {#1\protect} -\def\unprotected - {\unprotect\dounprotected} +\unexpanded\def\unprotected + {\unprotect + \syst_helpers_unprotected} % awaiting the definitive implementation @@ -6683,20 +6575,21 @@ \def\elapsedtime {\ctxcommand{elapsedtime()}} \let\elapsedseconds \elapsedtime -\newcount\featuretest +\newcount\c_syst_helpers_test_feature_n \unexpanded\def\testfeature#1#2% - {\def\dotestfeature - {\advance\featuretest \plusone - \ifnum\featuretest>#1\else#2\expandafter\dotestfeature\fi}% + {\def\syst_helpers_test_feature_step + {\advance\c_syst_helpers_test_feature_n\plusone + \ifnum\c_syst_helpers_test_feature_n>#1\else#2\expandafter\syst_helpers_test_feature_step\fi}% \retestfeature} -\def\retestfeature % timer support is new per 10/5/2005 +\unexpanded\def\retestfeature % timer support is new per 10/5/2005 {\bgroup \ifcase\interactionmode\let\wait\relax\fi \writestatus\m!system{starting feature test}\wait \resettimer - \featuretest\zerocount \dotestfeature + \c_syst_helpers_test_feature_n\zerocount + \syst_helpers_test_feature_step \writestatus\m!system{feature test done (\elapsedseconds s)}% \wait \egroup} @@ -6719,7 +6612,7 @@ %D \freezedimenmacro\leftmargindistance %D \stoptyping -\def\freezedimenmacro#1% +\unexpanded\def\freezedimenmacro#1% {\edef#1{\the\dimexpr#1}} %D The next macro negates a macro (dimension or number, or actually, whatever. @@ -6735,191 +6628,19 @@ \def\gobbleassigndimen#1\\{} \def\assigndimen#1#2% - {\afterassignment\gobbleassigndimen#1=#2\!!zeropoint\\} - -\def\setusage#1% - {\expandafter\let\csname#1\endcsname\iftrue} - -\def\resetusage#1% - {\expandafter\let\csname#1\endcsname\iffalse} - -\def\ifusage#1% - {\ifcsname#1\endcsname\else - \resetusage{#1}% - \fi - \csname#1\endcsname} - -%D Very handy, more efficient than \type{{}}, and more readable -%D than \type {\empty}. - -\let\donothing\empty + {\afterassignment\gobbleassigndimen#1=#2\zeropoint\\} -% The following macros are used in XML handling. +\unexpanded\def\appended#1#2#3{\expandafter#1\expandafter#2\expandafter{#2#3}} +\unexpanded\def\appendvalue #1{\expandafter\appended\expandafter \def\csname#1\endcsname} +\unexpanded\def\appendgvalue#1{\expandafter\appended\expandafter\gdef\csname#1\endcsname} -\setvalue{@u@s@"}#1#2"{#2} \setvalue{@g@s@"}#1#2"{\scratchtoks{#2}} -\setvalue{@u@s@'}#1#2'{#2} \setvalue{@g@s@'}#1#2'{\scratchtoks{#2}} -\setvalue{@u@s@ }#1#2 {#2} \setvalue{@g@s@ }#1#2 {\scratchtoks{#2}} - -\def\unstringed#1{\csname\ifcsname @u@s@#1\endcsname @u@s@#1\else\s!empty\fi\endcsname#1} -\def\grabstring#1{\csname\ifcsname @g@s@#1\endcsname @g@s@#1\else\s!empty\fi\endcsname#1} - -\def\dowithgrabbedstring#1% - {\def\@@dowithgrabbedstring{#1}% - \afterassignment\@@dowithgrabbedstring\grabstring} - -\def\expifequalelse#1#2% - {\@@ifequal#1\relax\relax\@@and#2\relax\relax\@@then} - -\def\@@ifequal#1#2\@@and#3% - {\ifx#1\relax - \ifx#3\relax - \doubleexpandafter\@@if@@equal@@true - \else - \doubleexpandafter\@@if@@equal@@false - \fi - \else - \ifx#3\relax - \tripleexpandafter\@@if@@equal@@false - \else\ifx#1#3% - % go on - \else - \tripleexpandafter\@@if@@equal@@false - \fi\fi - \fi - \@@ifequal#2\@@and} - -\def\@@if@@equal@@true #1\@@then#2#3{#2} -\def\@@if@@equal@@false#1\@@then#2#3{#3} - -\def\appended#1#2#3{\expandafter#1\expandafter#2\expandafter{#2#3}} -\def\appendvalue #1{\expandafter\appended\expandafter \def\csname#1\endcsname} -\def\appendgvalue#1{\expandafter\appended\expandafter\gdef\csname#1\endcsname} - -\def\prepended#1#2#3% - {\scratchtoks{#3}% +\unexpanded\def\prepended#1#2#3% + {\t_syst_helpers_scratch{#3}% \expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter#2\expandafter\expandafter\expandafter - {\expandafter\the\expandafter\scratchtoks#2}} + {\expandafter\the\expandafter\t_syst_helpers_scratch#2}} -\def\prependvalue #1{\expandafter\prepended\expandafter \def\csname#1\endcsname} -\def\prependgvalue#1{\expandafter\prepended\expandafter\gdef\csname#1\endcsname} - -%D \macros -%D {compresscommacommandnrs,compresscommalistnrs,compressedcommalistnrs, -%D compresscommacommand,compresscommalist,compressedcommalist, -%D reversecommacommand,reversecommalist,reversedcommalist} -%D -%D The following two list processing macros are needed by Taco's -%D bibliography module. The numbers compressor converts the -%D list in a list of ranges. The normal compressor remove duplicate -%D and empty entries. -%D -%D This is now obsolete (and more a \LUA\ thing anyway). - -\def\compresscommalistnrs[#1]% - {\let\compressedlist\empty - \!!counta\maxdimen - \!!countb\maxdimen - \processcommalist[#1]\docompresslistnrs - \ifnum\!!counta=\maxdimen\else\dodocompresslistnrs\fi} - -\def\compresscommacommandnrs[#1]% - {\normalexpanded{\noexpand\compresscommalistnrs[#1]}} - -\def\docompresslistnrs#1% - {\edef\commalistelement{#1}% - \ifx\commalistelement\empty\else - \ifnum\!!counta=\maxdimen - \!!counta\commalistelement\relax - \!!countb\!!counta - \else - \advance\!!countb\plusone - \ifnum\commalistelement>\!!countb - \advance\!!countb\minusone - \dodocompresslistnrs - \!!counta\commalistelement\relax - \!!countb\!!counta - \fi - \fi - \fi} - -\def\dodocompresslistnrs - {\edef\compressedlist - {\ifx\compressedlist\empty\else\compressedlist,\fi - {\the\!!counta}{\ifnum\!!countb>\!!counta\the\!!countb\fi}}} - -%D \def\test#1{{\tttf#1->\compresscommalistnrs[#1]\defconvertedcommand\ascii\compressedlist\ascii}} -%D \startlines -%D \test{} -%D \test{1} -%D \test{1,3} -%D \test{1,3,4} -%D \test{1,3,3,4,5} -%D \test{1,3,3,4,5,8} -%D \test{1,3,3,4,5,5,8,10} -%D \test{1,3,4,5,8,10,11} -%D \test{1,,3,,4,,5,,8,,10,,11,} -%D \stoplines - -\def\compresscommalist[#1]% - {\let\compressedlist\empty - \let\!!stringa\empty - \processcommalist[#1]\docompresslist} - -\def\compresscommacommand[#1]% - {\normalexpanded{\noexpand\compresscommalist[#1]}} - -\def\docompresslist#1% - {\edef\commalistelement{#1}% - \ifx\commalistelement\empty \else - \ifx\!!stringa\commalistelement \else - \ifx\compressedlist\empty - \def\compressedlist{#1}% - \else - \appended\def\compressedlist{,#1}% - \fi - \let\!!stringa\commalistelement - \fi - \fi} - -%D \def\test#1{{\tttf#1->\compresscommalist[#1]\defconvertedcommand\ascii\compressedlist\ascii}} -%D \startlines -%D \test{} -%D \test{1} -%D \test{1,3} -%D \test{1,3,4} -%D \test{1,3,3,4,5} -%D \test{1,3,3,4,5,8} -%D \test{1,3,3,4,5,5,8,10} -%D \test{1,3,4,5,8,10,11} -%D \test{1,,3,,4,,5,,8,,10,,11,} -%D \stoplines - -\def\reversecommalist[#1]% - {\let\reversedlist\empty - \processcommalist[#1]\doreverselist} - -\def\doreverselist#1% - {\ifx\reversedlist\empty - \def\reversedlist{#1}% - \else - \prepended\def\reversedlist{#1,}% - \fi} - -\def\reversecommacommand[#1]% - {\normalexpanded{\noexpand\reversecommalist[#1]}} - -%D \def\test#1{{\tttf#1->\reversecommalist[#1]\defconvertedcommand\ascii\reversedlist\ascii}} -%D \startlines -%D \test{} -%D \test{1} -%D \test{1,3} -%D \test{1,3,4} -%D \test{1,3,3,4,5} -%D \test{1,3,3,4,5,8} -%D \test{1,3,3,4,5,5,8,10} -%D \test{1,3,4,5,8,10,11} -%D \test{1,,3,,4,,5,,8,,10,,11,} -%D \stoplines +\unexpanded\def\prependvalue #1{\expandafter\prepended\expandafter \def\csname#1\endcsname} +\unexpanded\def\prependgvalue#1{\expandafter\prepended\expandafter\gdef\csname#1\endcsname} %D \macros %D {dowithrange} @@ -6927,44 +6648,11 @@ %D This one is for Mojca Miklavec, who made me aware of the fact that %D \type {page-imp.tex} was not the best place to hide it. -\def\dowithrange#1#2% #2 takes number +\unexpanded\def\dowithrange#1#2% #2 takes number {\splitstring#1\at:\to\fromrange\and\torange \ifx\torange\empty\let\torange\fromrange\fi \dostepwiserecurse\fromrange\torange1{#2{\recurselevel}}} - -%D \macros {uncompresslist} -%D -%D When given a list like \type{1,4-7,9} as argument, this macro -%D will store the expanded commalist in \type{\uncompressedlist}. -%D -%D \startbuffer -%D \def\MojcaHasToDoTheTasks[#1]#2% -%D {{\uncompresslist[#1]% -%D \def\processitem##1{I have to do ##1 #2\par}% -%D \processcommacommand[\uncompressedlist]\processitem}} -%D -%D \MojcaHasToDoTheTasks [1-4,7,9-11] {until tomorrow} -%D \stopbuffer -%D -%D Here is an example of how to use \type {\uncompresslist}: -%D \typebuffer -%D -%D The output of this is: -%D -%D \getbuffer -\def\uncompresslist[#1]% by TH - {\let\uncompressedlist\empty - \def\docompressedlistitem##1-##2-% - {\expandafter\dorecurse\expandafter - {\the\numexpr1+##2-##1\relax}% - {\expandafter\appendtocommalist\expandafter{\the\numexpr##1-1+####1\relax}\uncompressedlist}}% - \def\douncompresslist##1% - {\doifinstringelse{-}{##1} - {\docompressedlistitem##1-} - {\appendtocommalist{##1}\uncompressedlist}}% - \processcommalist[#1]\douncompresslist} - %D \macros %D {ignoreimplicitspaces} %D @@ -6977,7 +6665,7 @@ %D %D \typebuffer \getbuffer -\def\ignoreimplicitspaces +\unexpanded\def\ignoreimplicitspaces {\doifnextcharelse\relax\relax\relax} %D \macros @@ -6985,74 +6673,39 @@ %D %D Not that sophisticated but sometimes users (like in metafun). -\def\doprocesswords#1 #2\od - {\doifsomething{#1}{\processword{#1} \doprocesswords#2 \od}} -% {\doifsomething{\detokenize{#1}}{\processword{#1} \doprocesswords#2 \od}} % to be tested +\def\syst_helpers_process_word#1 #2\_e_o_w_ + {\doifsomething{#1}{\processword{#1} \syst_helpers_process_word#2 \_e_o_w_}} \def\processwords#1% - {\doprocesswords#1 \od}% no \unskip + {\syst_helpers_process_word#1 \_e_o_w_}% no \unskip \let\processword\relax -% new -% -% \startnointerference -% all kind of code -% \stopnointerference +%D \macros +%D {startnointerference} +%D +%D \starttyping +%D \startnointerference +%D all kind of code +%D \stopnointerference +%D \stoptyping -\newbox\nointerferencebox +\newbox\b_syst_helpers_no_interference \unexpanded\def\startnointerference % not even grouped ! - {\setbox\nointerferencebox\vbox + {\setbox\b_syst_helpers_no_interference\vbox \bgroup} \unexpanded\def\stopnointerference {\egroup - \setbox\nointerferencebox\emptybox} - -% \def\appendtovaluelist#1#2% -% {\ifcsname#1\endcsname -% \expandafter\ifx\csname#1\endcsname\empty -% \expandafter\def\csname#1\endcsname{#2}% -% \else -% \expandafter\def\csname#1\expandafter\expandafter\expandafter\endcsname -% \expandafter\expandafter\expandafter{\csname#1\endcsname,#2}% -% \fi -% \else -% \expandafter\def\csname#1\endcsname{#2}% -% \fi} -% -% or -% -% \def\appendtovaluelist#1% -% {\ifcsname#1\endcsname -% \expandafter\ifx\csname#1\endcsname\empty -% \expandafter\noappendtovaluelist\csname#1\expandafter\expandafter\expandafter\endcsname -% \else -% \expandafter\doappendtovaluelist\csname#1\expandafter\expandafter\expandafter\endcsname -% \fi -% \else -% \expandafter\noappendtovaluelist\csname#1\expandafter\endcsname -% \fi} - -% \def\doappendtovaluelist#1#2{\expandafter\def\expandafter#1\expandafter{#1,#2}} -% \def\noappendtovaluelist#1#2{\def#1{#2}} - -% \appendtovaluelist{mylist}{aap} -% \appendtovaluelist{mylist}{noot} -% \appendtovaluelist{mylist}{mies} - -% \showvalue{mylist} + \setbox\b_syst_helpers_no_interference\emptybox} %D A variant for \type {\executeifdefined}: -% \def\expandcheckedcsname#1#2#3% -% {\csname#1\ifcsname#1#2\endcsname#2\else#3\fi\endcsname} - \def\expandcheckedcsname#1#2% #2 is often a \xxxparameter so let's expand it once - {\normalexpanded{\noexpand\doexpandcheckedcsname{#1}{#2}}} + {\normalexpanded{\noexpand\syst_helpers_expand_checked_csname{#1}{#2}}} -\def\doexpandcheckedcsname#1#2#3% +\def\syst_helpers_expand_checked_csname#1#2#3% {\csname#1\ifcsname#1#2\endcsname#2\else#3\fi\endcsname} %D Signal. Some fonts have a char0 rendering so we need to make sure that it @@ -7060,7 +6713,41 @@ \unexpanded\def\signalcharacter{\char\zerocount} % \zwj -%D Here are some nasty helpers: +%D A few secial variants of commands defined here. Some more will be moved here (e.g. +%D from table modules. + +\def\dodirectdoubleempty#1#2% used in math (lookahead issues) + {\ifx#2[% + \expandafter\syst_helpers_direct_double_empty_one_yes + \else + \expandafter\syst_helpers_direct_double_empty_one_nop + \fi#1#2} + +\def\syst_helpers_direct_double_empty_one_yes#1[#2]#3% + {\ifx#3[\else\expandafter\syst_helpers_direct_double_empty_two_nop\fi#1[#2]#3} + +\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 \startbuffer +%D [\docheckedpair{}] +%D [\docheckedpair{a}] +%D [\docheckedpair{a,b}] +%D [\docheckedpair{a,b,c}] +%D \stopbuffer +%D +%D \typebuffer \startlines \getbuffer \stoplines + +\def\docheckedpair#1% + {\syst_helpers_checked_pair#1,,\_o_e_p_} + +\def\syst_helpers_checked_pair#1,#2,#3\_o_e_p_ + {#1,#2} + +%D Here are some nasty helpers. They can be used to fill often expanded token +%D lists efficiently (see tabulate for an example). \def\constantnumber#1% {\ifcase#1\zerocount @@ -7111,8 +6798,53 @@ {#1}% \fi} -%D These can be used when constructing often reused token lists, -%D as we do with tabulates. +% %D Maybe some day (moved from cont-new): +% %D +% %D \starttyping +% %D \the\dimexpr(\dimchoice {7pt}{{<10pt}{8pt}{<12pt}{9pt}{<15pt}{10pt}{=11pt}{12pt}}) +% %D \the\dimexpr(\dimchoice{11pt}{{<10pt}{8pt}{<12pt}{9pt}{<15pt}{10pt}{=11pt}{12pt}}) +% %D \the\dimexpr(\dimchoice{14pt}{{<10pt}{8pt}{<12pt}{9pt}{<15pt}{10pt}{=11pt}{12pt}}) +% %D \stoptyping +% +% \def\syst_helpers_choice_finish#1\empty{} +% +% \def\syst_helpers_choice_dim#1#2#3% +% {\ifdim#1#2% +% #3\expandafter\syst_helpers_choice_finish +% \else +% \expandafter\syst_helpers_choice_dim +% \fi{#1}} +% +% \def\syst_helpers_choice_num#1#2#3% +% {\ifnum#1#2% +% #3\expandafter\syst_helpers_choice_finish +% \else +% \expandafter\syst_helpers_choice_num +% \fi{#1}} +% +% \def\dimchoice#1#2{\syst_helpers_choice_dim{#1}#2{=#1}{#1}\empty} +% \def\numchoice#1#2{\syst_helpers_choice_num{#1}#2{=#1}{#1}\empty} + +%D \macros +%D {getsubstring} +%D \startbuffer +%D +%D \getsubstring{4}{}{Who Wants This} +%D \getsubstring{4}{9}{Who Wants This} +%D \getsubstring{9}{-2}{Who Wants This} +%D \getsubstring{1}{5}{Who Wants This} +%D \stopbuffer +%D +%D \typebuffer +%D +%D \startlines +%D \getbuffer +%D \stoplines + +% 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")}} \protect \endinput @@ -7174,3 +6906,37 @@ % nothing % } % \stopchoice + +% \def\appendtovaluelist#1#2% +% {\ifcsname#1\endcsname +% \expandafter\ifx\csname#1\endcsname\empty +% \expandafter\def\csname#1\endcsname{#2}% +% \else +% \expandafter\def\csname#1\expandafter\expandafter\expandafter\endcsname +% \expandafter\expandafter\expandafter{\csname#1\endcsname,#2}% +% \fi +% \else +% \expandafter\def\csname#1\endcsname{#2}% +% \fi} +% +% or +% +% \def\appendtovaluelist#1% +% {\ifcsname#1\endcsname +% \expandafter\ifx\csname#1\endcsname\empty +% \expandafter\noappendtovaluelist\csname#1\expandafter\expandafter\expandafter\endcsname +% \else +% \expandafter\doappendtovaluelist\csname#1\expandafter\expandafter\expandafter\endcsname +% \fi +% \else +% \expandafter\noappendtovaluelist\csname#1\expandafter\endcsname +% \fi} +% +% \def\doappendtovaluelist#1#2{\expandafter\def\expandafter#1\expandafter{#1,#2}} +% \def\noappendtovaluelist#1#2{\def#1{#2}} +% +% \appendtovaluelist{mylist}{aap} +% \appendtovaluelist{mylist}{noot} +% \appendtovaluelist{mylist}{mies} +% +% \showvalue{mylist} |