diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-num.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/strc-num.mkiv | 796 |
1 files changed, 491 insertions, 305 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-num.mkiv b/Master/texmf-dist/tex/context/base/strc-num.mkiv index b386b5d9518..9c08693be56 100644 --- a/Master/texmf-dist/tex/context/base/strc-num.mkiv +++ b/Master/texmf-dist/tex/context/base/strc-num.mkiv @@ -5,7 +5,7 @@ %D subtitle=Basic Numbering, %D author=Hans Hagen, %D date=\currentdate, -%D copyright=PRAGMA-ADE / Hans Hagen] +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] %C %C This module is part of the \CONTEXT\ macro||package and is %C therefore copyrighted by \PRAGMA. See mreadme.pdf for @@ -17,326 +17,485 @@ \unprotect -% we need to rework this, i.e. clone like itm, des etc with \s!parent +% work in progress +% to be checked: can we use the command handler code here? -% numbering +\installcorenamespace{counter} -% \definestructurecounter[name] -% \setupstructurecounter[name][wijze=,blok=,tekst=,plaats=,conversie=,start=] -% \setstructurecounter[name]{value} -% \resetstructurecounter[name] -% \incrementstructurecounter[name] -% \decrementstructurecounter[name] -% \savestructurecounter[name] -% \restorestructurecounter[name] -% \convertedstructurecounter[name] % depricated: \getstructurecounter[name] -% \rawstructurecounter[name] +\unexpanded\def\setupstructurecounting{\dodoubleempty\getparameters[\??counter]} -% private (defined in core-sec.tex) -% -% \nextstructurecounter[name][tag][reference] -% \currentstructurecounter[name] - -% todo: better inheritane system - -\unexpanded\def\setupstructurecountering{\dodoubleempty\getparameters[\??nn]} - -\setupstructurecountering +\setupstructurecounting [\c!way=\v!by\v!chapter, % \c!blockway=, % \c!prefixstarter=, % \c!prefixstopper=, \c!prefixconnector=., - \c!prefixsegments=\thenamedstructurecounterlevel\currentstructurecounter, + \c!prefixsegments=\autostructureprefixsegments\sharedcounterparameter, \c!start=0, \c!prefix=\v!yes, \c!state=\v!start] -\setupstructurecountering - [\c!prefixsegments=\autostructureprefixsegments\sharedstructurecounterparameter] +\def\strc_counters_the#1% we need a nicer name + {\ifcsname\??counter#1\c!number\endcsname + \expandafter\strc_counters_the\csname\??counter#1\c!number\endcsname + \else + #1% + \fi} \def\autostructureprefixsegments#1% todo: \c!prefixsegments=\v!auto - {2:\thenamedstructureheadlevel{\ctxlua{structures.sections.way("#1\c!way","\v!by")}}} + {2:\thenamedheadlevel{\ctxlua{structures.sections.way("#1\c!way")}}} -\def\structurecounterparameter#1#2% +\def\counterparameter#1#2% this will become \named.... {\csname - \ifcsname\??nn#1#2\endcsname - \??nn#1#2% - \else\ifcsname\??nn\@@thestructurecounter{#1}#2\endcsname - \??nn\@@thestructurecounter{#1}#2% - \else\ifcsname\??nn#2\endcsname - \??nn#2% + \ifcsname\??counter#1#2\endcsname + \??counter#1#2% + \else\ifcsname\??counter\strc_counters_the{#1}#2\endcsname + \??counter\strc_counters_the{#1}#2% + \else\ifcsname\??counter#2\endcsname + \??counter#2% \else \s!empty \fi\fi\fi \endcsname} -\def\@@thestructurecounter#1% - {\ifcsname\??nn#1\c!number\endcsname - \expandafter\@@thestructurecounter\csname\??nn#1\c!number\endcsname - \else - #1% - \fi} - -\def\sharedstructurecounterparameter#1% +\def\sharedcounterparameter#1% {\csname - \ifcsname\??nn#1\endcsname - \??nn#1% + \ifcsname\??counter#1\endcsname + \??counter#1% \else \s!empty \fi \endcsname} -\let\numberingparameter\sharedstructurecounterparameter +\unexpanded\def\definecounter + {\dodoubleempty\strc_counters_define} -% \def\structurecounterparameter #1#2{\csname\dostructurecounterparameter{\??nn#1}#2\endcsname} -% \def\dostructurecounterparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\dostructurecounterparentparameter\csname#1\s!number\endcsname#2\fi} -% \def\dostructurecounterparentparameter#1#2{\ifx#1\relax\s!empty\else\dostructurecounterparameter#1#2\fi} - -\unexpanded\def\definestructurecounter - {\dodoubleempty\dodefinestructurecounter} - -\def\dodefinestructurecounter[#1][#2]% +\def\strc_counters_define[#1][#2]% {\doifassignmentelse{#2} - {\dododefinestructurecounter[#1][#2]} + {\strc_counters_define_yes[#1][#2]} {\doifelsenothing{#2} - {\dododefinestructurecounter[#1][]} - {\donodefinestructurecounter[#1][#2]}}} + {\strc_counters_define_yes[#1][]} + {\strc_counters_define_nop[#1][#2]}}} + +\def\strc_counters_define_yes[#1][#2]% + {\getparameters[\??counter#1][\s!counter=,#2]% counter is for internal purposes + \ctxcommand{definecounter { + name = "#1", + start = tonumber("\counterparameter{#1}\c!start") or 0, + counter = "\counterparameter{#1}\s!counter", + method = "\counterparameter{#1}\c!method", + }}% + \strc_counters_check_setup{#1}} + +\def\strc_counters_define_nop[#1][#2]% inherit + {\getparameters[\??counter#1][\c!number=#2]% + \strc_counters_check_setup{#1}} + +\unexpanded\def\setupcounter + {\dodoubleargument\strc_counters_setup} + +\def\strc_counters_setup[#1][#2]% + {\getparameters[\??counter#1][\c!start=,#2]% + \strc_counters_check_setup{#1}} + +% % % % + +\def\strc_counters_way#1% slow, we need to store it at the tex end + {\ctxlua{structures.sections.way("\counterparameter{#1}\c!way")}} + +% \def\thenamedcounterlevel#1% +% {\thenamedheadlevel{\strc_counters_way{#1}}} + +\def\thenamedcounterlevel#1% + {\xthenamedheadlevel{\strc_counters_way{#1}}} + +\def\xthenamedheadlevel#1% + {\xsectionlevel{#1}{\sectionheadsection{\sectionheadcoupling{#1}}}} + +\def\xsectionlevel#1#2% direct indirect + {\csname\??headlevel + \ifcsname\??headlevel#1\endcsname + #1% + \else\ifcsname\??headlevel#2\endcsname + #2% + \else + \v!none + \fi\fi + \endcsname} + +\def\strc_counters_check_setup#1% does it have to happen here? + {% this can be done at the lua end / a bit messy here ... todo ... + \ifcsname\??counter#1\c!number\endcsname + \doifelsevalue {\??counter#1\c!number}{#1} {\letbeundefined{\??counter#1\c!number}}% + {\doifvaluenothing{\??counter#1\c!number} {\letbeundefined{\??counter#1\c!number}}}% + \fi + \ifcsname\??counter#1\c!number\endcsname + % it's a clone + \else + \edef\currentcounterlevel{\thenamedcounterlevel{#1}}% + \ctxcommand{checkcountersetup("#1",\currentcounterlevel,"\counterparameter{#1}\c!start","\counterparameter{#1}\c!state")}% + \fi} -\def\dododefinestructurecounter[#1][#2]% - {\getparameters[\??nn#1][\s!counter=,#2]% counter is for internal purposes - \ctxlua{structures.counters.define("#1", % this will be a table - tonumber("\structurecounterparameter{#1}\c!start") or 0, - "\structurecounterparameter{#1}\s!counter", - "\structurecounterparameter{#1}\c!method")}% - \docheckstructurecountersetup{#1}} +\unexpanded\def\doifcounterelse #1{\ctxcommand{doifelsecounter("\strc_counters_the{#1}")}} +\unexpanded\def\doifcounter #1{\ctxcommand{doifcounter ("\strc_counters_the{#1}")}} +\unexpanded\def\doifnotcounter #1{\ctxcommand{doifnotcounter ("\strc_counters_the{#1}")}} + +\unexpanded\def\setcounter {\dotripleempty \strc_counters_set_interfaced} +\unexpanded\def\setcounterown {\dotripleempty \strc_counters_setown_interfaced} +\unexpanded\def\restartcounter {\dotripleempty \strc_counters_restart_interfaced} +\unexpanded\def\resetcounter {\dodoubleempty \strc_counters_reset_interfaced} +\unexpanded\def\incrementcounter {\dodoubleempty \strc_counters_increment_interfaced} +\unexpanded\def\decrementcounter {\dodoubleempty \strc_counters_decrement_interfaced} + +\unexpanded\def\rawcounter {\dodoubleargument\strc_counters_raw_interfaced} +\unexpanded\def\lastcounter {\dodoubleargument\strc_counters_last_interfaced} +\unexpanded\def\firstcounter {\dodoubleargument\strc_counters_first_interfaced} +\unexpanded\def\nextcounter {\dodoubleargument\strc_counters_next_interfaced} +\unexpanded\def\prevcounter {\dodoubleargument\strc_counters_prev_interfaced} +\unexpanded\def\countersubs {\dodoubleargument\strc_counters_subs_interfaced} + +\unexpanded\def\savecounter {\dodoubleempty \strc_counters_save_interfaced} +\unexpanded\def\restorecounter {\dodoubleempty \strc_counters_restore_interfaced} + +\def\strc_counters_set_interfaced + {\ifthirdargument + \singleexpandafter\strc_counters_set_two + \else\ifsecondargument + \doubleexpandafter\strc_counters_set_one + \else + \doubleexpandafter\gobblethreeoptionals + \fi\fi} + +\def\strc_counters_setown_interfaced + {\ifthirdargument + \singleexpandafter\strc_counters_setown_two + \else\ifsecondargument + \doubleexpandafter\strc_counters_setown_one + \else + \doubleexpandafter\gobblethreeoptionals + \fi\fi} + +\def\strc_counters_restart_interfaced + {\ifthirdargument + \singleexpandafter\strc_counters_restart_two + \else\ifsecondargument + \doubleexpandafter\strc_counters_restart_one + \else + \doubleexpandafter\gobblethreeoptionals + \fi\fi} -\def\donodefinestructurecounter[#1][#2]% inherit - {\getparameters[\??nn#1][\c!number=#2]% - \docheckstructurecountersetup{#1}} +\def\strc_counters_reset_interfaced + {\ifsecondargument + \singleexpandafter\strc_counters_reset_two + \else\iffirstargument + \doubleexpandafter\strc_counters_reset_one + \else + \doubleexpandafter\gobbletwooptionals + \fi\fi} -\unexpanded\def\setupstructurecounter - {\dodoubleargument\dosetupstructurecounter} +\def\strc_counters_increment_interfaced + {\ifsecondargument + \singleexpandafter\strc_counters_increment_two + \else\iffirstargument + \doubleexpandafter\strc_counters_increment_one + \else + \doubleexpandafter\gobbletwooptionals + \fi\fi} -\def\dosetupstructurecounter[#1][#2]% - {\getparameters[\??nn#1][\c!start=,#2]% - \docheckstructurecountersetup{#1}} +\def\strc_counters_decrement_interfaced + {\ifsecondargument + \singleexpandafter\strc_counters_decrement_two + \else\iffirstargument + \doubleexpandafter\strc_counters_decrement_one + \else + \doubleexpandafter\gobbletwooptionals + \fi\fi} -\def\structurecounterway#1% slow, we need to store it at the tex end - {\ctxlua{structures.sections.way("\structurecounterparameter{#1}\c!way","\v!by")}} +\def\strc_counters_raw_interfaced + {\ifsecondargument + \singleexpandafter\strc_counters_raw_two + \else\iffirstargument + \doubleexpandafter\strc_counters_raw_one + \else + \doubleexpandafter\gobbletwooptionals + \fi\fi} -\def\thenamedstructurecounterlevel#1% - {\thenamedstructureheadlevel{\structurecounterway{#1}}} +\def\strc_counters_last_interfaced + {\ifsecondargument + \singleexpandafter\strc_counters_last_two + \else\iffirstargument + \doubleexpandafter\strc_counters_last_one + \else + \doubleexpandafter\gobbletwooptionals + \fi\fi} -\def\docheckstructurecountersetup#1% - {% this can be done at the lua end / a bit messy here ... todo ... - \ifcsname\??nn#1\c!number\endcsname - \doifelsevalue {\??nn#1\c!number}{#1} {\letbeundefined{\??nn#1\c!number}}% - {\doifvaluenothing{\??nn#1\c!number} {\letbeundefined{\??nn#1\c!number}}}% - \fi - \ifcsname\??nn#1\c!number\endcsname - % it's a clone +\def\strc_counters_first_interfaced + {\ifsecondargument + \singleexpandafter\strc_counters_first_two + \else\iffirstargument + \doubleexpandafter\strc_counters_first_one \else - \edef\currentstructurecounterlevel{\thenamedstructurecounterlevel{#1}}% - \ctxlua{ - structures.counters.restart("#1",1,"\structurecounterparameter{#1}\c!start") - structures.counters.setstate("#1","\structurecounterparameter{#1}\c!state") - structures.counters.setlevel("#1",\currentstructurecounterlevel) - structures.sections.setchecker("#1",\currentstructurecounterlevel,structures.counters.reset) - }% + \doubleexpandafter\gobbletwooptionals + \fi\fi} + +\def\strc_counters_prev_interfaced + {\ifsecondargument + \singleexpandafter\strc_counters_prev_two + \else\iffirstargument + \doubleexpandafter\strc_counters_prev_one + \else + \doubleexpandafter\gobbletwooptionals + \fi\fi} + +\def\strc_counters_next_interfaced + {\ifsecondargument + \singleexpandafter\strc_counters_next_two + \else\iffirstargument + \doubleexpandafter\strc_counters_next_one + \else + \doubleexpandafter\gobbletwooptionals + \fi\fi} + +\def\strc_counters_subs_interfaced + {\ifsecondargument + \singleexpandafter\strc_counters_subs_two + \else\iffirstargument + \doubleexpandafter\strc_counters_subs_one + \else + \doubleexpandafter\gobbletwooptionals + \fi\fi} + +\def\strc_counters_save_interfaced + {\iffirstargument + \expandafter\strc_counters_save_one + \else + \expandafter\gobbleoneoptional \fi} -\def\doifstructurecounterelse#1{\ctxlua{structures.counters.doifelse("\@@thestructurecounter{#1}")}} -\def\doifstructurecounter #1{\ctxlua{structures.counters.doif ("\@@thestructurecounter{#1}")}} -\def\doifnotstructurecounter #1{\ctxlua{structures.counters.doifnot ("\@@thestructurecounter{#1}")}} - -\def\setstructurecounter [#1]#2{\ctxlua{structures.counters.set ("\@@thestructurecounter{#1}",1,\number#2)}} -\def\setstructurecounterown [#1]#2{\ctxlua{structures.counters.setown ("\@@thestructurecounter{#1}",1,"#2")}} -\def\resetstructurecounter [#1]{\ctxlua{structures.counters.reset ("\@@thestructurecounter{#1}",1)}} -\def\restartstructurecounter [#1]#2{\ctxlua{structures.counters.restart("\@@thestructurecounter{#1}",1,#2)}} -\def\savestructurecounter [#1]{\ctxlua{structures.counters.save ("\@@thestructurecounter{#1}")}} -\def\restorestructurecounter [#1]{\ctxlua{structures.counters.restore("\@@thestructurecounter{#1}")}} -\def\incrementstructurecounter [#1]{\ctxlua{structures.counters.add ("\@@thestructurecounter{#1}",1,1)}} -\def\decrementstructurecounter [#1]{\ctxlua{structures.counters.add ("\@@thestructurecounter{#1}",1,-1)}} -\def\rawstructurecounter [#1]{\ctxlua{structures.counters.value ("\@@thestructurecounter{#1}",1)}} -\def\laststructurecounter [#1]{\ctxlua{structures.counters.last ("\@@thestructurecounter{#1}",1)}} -\def\firststructurecounter [#1]{\ctxlua{structures.counters.first ("\@@thestructurecounter{#1}",1)}} -\def\nextstructurecounter [#1]{\ctxlua{structures.counters.next ("\@@thestructurecounter{#1}",1)}} -\def\prevstructurecounter [#1]{\ctxlua{structures.counters.prev ("\@@thestructurecounter{#1}",1)}} -\def\structurecountersubs [#1]{\ctxlua{structures.counters.subs ("\@@thestructurecounter{#1}",1)}} - -\def\tracestructurecounter [#1]{\ctxlua{structures.counters.trace ("\@@thestructurecounter{#1}")}} - -\def\incrementedstructurecounter[#1]{\ctxlua{tex.write(structures.counters.add("\@@thestructurecounter{#1}",1,1))}} -\def\decrementedstructurecounter[#1]{\ctxlua{tex.write(structures.counters.add("\@@thestructurecounter{#1}",1,-1))}} - -\def\setsubstructurecounter {\dodoubleargument\dosetsubstructurecounter} -\def\setsubstructurecounterown {\dodoubleargument\dosetsubstructurecounterown} -\def\resetsubstructurecounter {\dodoubleargument\doresetsubstructurecounter} -\def\restartsubstructurecounter {\dodoubleargument\dorestartsubstructurecounter} -\def\incrementsubstructurecounter {\dodoubleargument\doincrementsubstructurecounter} -\def\decrementsubstructurecounter {\dodoubleargument\dodecrementsubstructurecounter} -\def\rawsubstructurecounter {\dodoubleargument\dorawsubstructurecounter} - -\def\dosetsubstructurecounter [#1][#2]#3{\ctxlua{structures.counters.set ("\@@thestructurecounter{#1}",#2,\number#3)}} -\def\dosetsubstructurecounterown [#1][#2]#3{\ctxlua{structures.counters.setown ("\@@thestructurecounter{#1}",#2,"#3")}} -\def\doresetsubstructurecounter [#1][#2]{\ctxlua{structures.counters.reset ("\@@thestructurecounter{#1}",#2)}} -\def\dorestartsubstructurecounter [#1][#2]#3{\ctxlua{structures.counters.restart("\@@thestructurecounter{#1}",#2,#3)}} -\def\doincrementsubstructurecounter [#1][#2]{\ctxlua{structures.counters.add ("\@@thestructurecounter{#1}",#2,1)}} -\def\dodecrementsubstructurecounter [#1][#2]{\ctxlua{structures.counters.add ("\@@thestructurecounter{#1}",#2,-1)}} -\def\dorawsubstructurecounter [#1][#2]{\ctxlua{structures.counters.value ("\@@thestructurecounter{#1}",#2)}} -\def\dolastsubstructurecounter [#1][#2]{\ctxlua{structures.counters.last ("\@@thestructurecounter{#1}",#2)}} -\def\dofirstsubstructurecounter [#1][#2]{\ctxlua{structures.counters.first ("\@@thestructurecounter{#1}",#2)}} -\def\dosubstructurecountersubs [#1][#2]{\ctxlua{structures.counters.subs ("\@@thestructurecounter{#1}",#2)}} - -% The bypage check needs a multipass reference and therefore -% we only check for it when we increment and know that some -% content will be placed. We could also check for spreads. - -% to be checked ! - -\def\docheckstructurecounterbypage#1% since we call lua to get the way we can as well do all in lua - {\doif{\structurecounterway{#1}}\v!page{\checkpagechange{#1}\ifpagechanged\resetstructurecounter[#1]\fi}} - -\def\incrementstructurecounter[#1]% - {\docheckstructurecounterbypage{#1}% - \ctxlua{structures.counters.add("\@@thestructurecounter{#1}",1,1)}} - -\def\doincrementsubstructurecounter[#1][#2]% - {\docheckstructurecounterbypage{#1}% - \ctxlua{structures.counters.add("\@@thestructurecounter{#1}",#2,1)}} - -\def\convertedstructurecounter - {\dodoubleempty\doconvertedstructurecounter} - -\def\doconvertedstructurecounter[#1][#2]% +\def\strc_counters_restore_interfaced + {\iffirstargument + \expandafter\strc_counters_restore_one + \else + \expandafter\gobbleoneoptional + \fi} + +\def\strc_counters_set_two [#1][#2][#3]{\strc_counters_set_sub {#1}{#2}{#3}} +\def\strc_counters_setown_two [#1][#2][#3]{\strc_counters_setown_sub {#1}{#2}{#3}} +\def\strc_counters_restart_two [#1][#2][#3]{\strc_counters_restart_sub {#1}{#2}{#3}} +\def\strc_counters_reset_two [#1][#2]{\strc_counters_reset_sub {#1}{#2}} +\def\strc_counters_increment_two [#1][#2]{\strc_counters_increment_sub{#1}{#2}} +\def\strc_counters_decrement_two [#1][#2]{\strc_counters_decrement_sub{#1}{#2}} + +\def\strc_counters_raw_two [#1][#2]{\strc_counters_raw_sub {#1}{#2}} +\def\strc_counters_last_two [#1][#2]{\strc_counters_last_sub {#1}{#2}} +\def\strc_counters_first_two [#1][#2]{\strc_counters_first_sub {#1}{#2}} +\def\strc_counters_next_two [#1][#2]{\strc_counters_next_sub {#1}{#2}} +\def\strc_counters_prev_two [#1][#2]{\strc_counters_prev_sub {#1}{#2}} +\def\strc_counters_subs_two [#1][#2]{\strc_counters_subs_sub {#1}{#2}} + +\def\strc_counters_set_one [#1][#2][#3]{\strc_counters_set_sub {#1}\plusone{#2}} +\def\strc_counters_setown_one [#1][#2][#3]{\strc_counters_setown_sub {#1}\plusone{#2}} +\def\strc_counters_restart_one [#1][#2][#3]{\strc_counters_restart_sub {#1}\plusone{#2}} +\def\strc_counters_reset_one [#1][#2]{\strc_counters_reset_sub {#1}\plusone} +\def\strc_counters_increment_one [#1][#2]{\strc_counters_increment_sub{#1}\plusone} +\def\strc_counters_decrement_one [#1][#2]{\strc_counters_decrement_sub{#1}\plusone} + +\def\strc_counters_raw_one [#1][#2]{\strc_counters_raw_sub {#1}\plusone} +\def\strc_counters_last_one [#1][#2]{\strc_counters_last_sub {#1}\plusone} +\def\strc_counters_first_one [#1][#2]{\strc_counters_first_sub {#1}\plusone} +\def\strc_counters_next_one [#1][#2]{\strc_counters_next_sub {#1}\plusone} +\def\strc_counters_prev_one [#1][#2]{\strc_counters_prev_sub {#1}\plusone} +\def\strc_counters_subs_one [#1][#2]{\strc_counters_subs_sub {#1}\plusone} + +\def\strc_counters_save_one [#1]{\strc_counters_save {#1}} +\def\strc_counters_restore_one [#1]{\strc_counters_restore {#1}} + +\unexpanded\def\strc_counters_set #1#2{\strc_counters_set_sub {#1}\plusone{#2}} +\unexpanded\def\strc_counters_setown #1#2{\strc_counters_setown_sub {#1}\plusone{#2}} +\unexpanded\def\strc_counters_restart #1#2{\strc_counters_restart_sub {#1}\plusone{#2}} +\unexpanded\def\strc_counters_reset #1{\strc_counters_reset_sub {#1}\plusone} +\unexpanded\def\strc_counters_increment #1{\strc_counters_increment_sub{#1}\plusone} +\unexpanded\def\strc_counters_decrement #1{\strc_counters_decrement_sub{#1}\plusone} + + \def\strc_counters_raw #1{\strc_counters_raw_sub {#1}\plusone} + \def\strc_counters_last #1{\strc_counters_last_sub {#1}\plusone} + \def\strc_counters_first #1{\strc_counters_first_sub {#1}\plusone} + \def\strc_counters_next #1{\strc_counters_next_sub {#1}\plusone} + \def\strc_counters_prev #1{\strc_counters_prev_sub {#1}\plusone} + \def\strc_counters_subs #1{\strc_counters_subs_sub {#1}\plusone} + +\unexpanded\def\strc_counters_set_sub #1#2#3{\ctxcommand{setcounter ("\strc_counters_the{#1}",\number#2,\number#3)}} +\unexpanded\def\strc_counters_setown_sub #1#2#3{\ctxcommand{setowncounter ("\strc_counters_the{#1}",\number#2,"#3")}} +\unexpanded\def\strc_counters_restart_sub #1#2#3{\ctxcommand{restartcounter("\strc_counters_the{#1}",\number#2,\number#3)}} +\unexpanded\def\strc_counters_reset_sub #1#2{\ctxcommand{resetcounter ("\strc_counters_the{#1}",\number#2)}} +\unexpanded\def\strc_counters_increment_sub #1#2{\ctxcommand{addcounter ("\strc_counters_the{#1}",\number#2,1)}} +\unexpanded\def\strc_counters_decrement_sub #1#2{\ctxcommand{addcounter ("\strc_counters_the{#1}",\number#2,-1)}} + + \def\strc_counters_raw_sub #1#2{\ctxcommand{countervalue ("\strc_counters_the{#1}",\number#2)}} % maybe raw + \def\strc_counters_last_sub #1#2{\ctxcommand{lastcountervalue ("\strc_counters_the{#1}",\number#2)}} + \def\strc_counters_first_sub #1#2{\ctxcommand{firstcountervalue ("\strc_counters_the{#1}",\number#2)}} + \def\strc_counters_next_sub #1#2{\ctxcommand{nextcountervalue ("\strc_counters_the{#1}",\number#2)}} + \def\strc_counters_prev_sub #1#2{\ctxcommand{previouscountervalue("\strc_counters_the{#1}",\number#2)}} + \def\strc_counters_subs_sub #1#2{\ctxcommand{subcountervalues ("\strc_counters_the{#1}",\number#2)}} + +\unexpanded\def\strc_counters_save #1{\ctxcommand{savecounter ("\strc_counters_the{#1}")}} +\unexpanded\def\strc_counters_restore #1{\ctxcommand{restorecounter("\strc_counters_the{#1}")}} + +\unexpanded\def\strc_counters_incremented #1{\ctxcommand{incrementedcounter("\strc_counters_the{#1}",1, 1)}} +\unexpanded\def\strc_counters_decremented #1{\ctxcommand{incrementedcounter("\strc_counters_the{#1}",1,-1)}} + +\unexpanded\def\showcounter [#1]{\ctxcommand{tracecounter("\strc_counters_the{#1}")}} + +\unexpanded\def\incrementedcounter [#1]{\strc_counters_incremented{#1}} % expandable, no \dosingleargument +\unexpanded\def\decrementedcounter [#1]{\strc_counters_decremented{#1}} % expandable, no \dosingleargument + +% public variants ... beware, for old cases, from now on the value variants are the +% ones that are expandable + +\def\rawcountervalue [#1]{\strc_counters_raw_sub {#1}\plusone} +\def\lastcountervalue [#1]{\strc_counters_last_sub {#1}\plusone} +\def\firstcountervalue[#1]{\strc_counters_first_sub{#1}\plusone} +\def\nextcountervalue [#1]{\strc_counters_next_sub {#1}\plusone} +\def\prevcountervalue [#1]{\strc_counters_prev_sub {#1}\plusone} + +\let\rawsubcountervalue \strc_counters_raw_two +\let\lastsubcountervalue \strc_counters_last_two +\let\firstsubcountervalue\strc_counters_first_two +\let\nextsubcountervalue \strc_counters_next_two +\let\prevsubcountervalue \strc_counters_prev_two + +% The bypage check needs a multipass reference and therefore we only check for it when we increment +% and know that some content will be placed. We could also check for spreads. + +\unexpanded\def\strc_counters_increment_sub#1#2% + {% this will be combined into one lua call + \edef\m_strc_counters_way{\strc_counters_way{#1}}% + \ifx\m_strc_counters_way\v!page + \checkpagechange{#1}% + \ifpagechanged + \strc_counters_reset{#1}% + \fi + \fi + \ctxcommand{addcounter("\strc_counters_the{#1}",\number#2,1)}} + +\unexpanded\def\convertedcounter + {\dodoubleempty\strc_counters_converted} + +\def\strc_counters_converted[#1][#2]% {\begingroup - \ifsecondargument\getparameters[\??nn#1][#2]\fi - \ctxlua{structures.counters.prefixedconverted( - "\@@thestructurecounter{#1}", + \ifsecondargument\getparameters[\??counter#1][#2]\fi + \ctxlua{structures.sections.prefixedconverted( + "\strc_counters_the{#1}", { - prefix = "\structurecounterparameter{#1}\c!prefix", - separatorset = "\structurecounterparameter{#1}\c!prefixseparatorset", - conversion = "\structurecounterparameter{#1}\c!prefixconversion", - conversionset = "\structurecounterparameter{#1}\c!prefixconversionset", - starter = \!!bs\structurecounterparameter{#1}\c!prefixstarter\!!es, - stopper = \!!bs\structurecounterparameter{#1}\c!prefixstopper\!!es, - set = "\structurecounterparameter{#1}\c!prefixset", - segments = "\structurecounterparameter{#1}\c!prefixsegments", - connector = \!!bs\structurecounterparameter{#1}\c!prefixconnector\!!es, + prefix = "\counterparameter{#1}\c!prefix", + separatorset = "\counterparameter{#1}\c!prefixseparatorset", + conversion = "\counterparameter{#1}\c!prefixconversion", + conversionset = "\counterparameter{#1}\c!prefixconversionset", + starter = \!!bs\counterparameter{#1}\c!prefixstarter\!!es, + stopper = \!!bs\counterparameter{#1}\c!prefixstopper\!!es, + set = "\counterparameter{#1}\c!prefixset", + segments = "\counterparameter{#1}\c!prefixsegments", + connector = \!!bs\counterparameter{#1}\c!prefixconnector\!!es, }, { - order = "\structurecounterparameter{#1}\c!numberorder", - separatorset = "\structurecounterparameter{#1}\c!numberseparatorset", - conversion = \!!bs\structurecounterparameter{#1}\c!numberconversion\!!es, - conversionset = "\structurecounterparameter{#1}\c!numberconversionset", - starter = \!!bs\structurecounterparameter{#1}\c!numberstarter\!!es, - stopper = \!!bs\structurecounterparameter{#1}\c!numberstopper\!!es, - segments = "\structurecounterparameter{#1}\c!numbersegments", - type = "\structurecounterparameter{#1}\c!type", - criterium = "\structurecounterparameter{#1}\c!criterium", % might change if we also want this with sectioning + order = "\counterparameter{#1}\c!numberorder", + separatorset = "\counterparameter{#1}\c!numberseparatorset", + conversion = \!!bs\counterparameter{#1}\c!numberconversion\!!es, + conversionset = "\counterparameter{#1}\c!numberconversionset", + starter = \!!bs\counterparameter{#1}\c!numberstarter\!!es, + stopper = \!!bs\counterparameter{#1}\c!numberstopper\!!es, + segments = "\counterparameter{#1}\c!numbersegments", + type = "\counterparameter{#1}\c!type", + criterium = "\counterparameter{#1}\c!criterium", % might change if we also want this with sectioning } )}% \endgroup} -\def\directconvertedstructurecounter#1#2% name, type - {\begingroup - \ctxlua{structures.counters.prefixedconverted( - "\@@thestructurecounter{#1}", +\def\directconvertedcounter#1#2% name, type + {\ctxlua{structures.sections.prefixedconverted( + "\strc_counters_the{#1}", { - prefix = "\structurecounterparameter{#1}\c!prefix", - separatorset = "\structurecounterparameter{#1}\c!prefixseparatorset", - conversion = "\structurecounterparameter{#1}\c!prefixconversion", - conversionset = "\structurecounterparameter{#1}\c!prefixconversionset", - % starter = \!!bs\structurecounterparameter{#1}\c!prefixstarter\!!es, - % stopper = \!!bs\structurecounterparameter{#1}\c!prefixstopper\!!es, - set = "\structurecounterparameter{#1}\c!prefixset", - segments = "\structurecounterparameter{#1}\c!prefixsegments", - connector = \!!bs\structurecounterparameter{#1}\c!prefixconnector\!!es, + prefix = "\counterparameter{#1}\c!prefix", + separatorset = "\counterparameter{#1}\c!prefixseparatorset", + conversion = "\counterparameter{#1}\c!prefixconversion", + conversionset = "\counterparameter{#1}\c!prefixconversionset", + % starter = \!!bs\counterparameter{#1}\c!prefixstarter\!!es, + % stopper = \!!bs\counterparameter{#1}\c!prefixstopper\!!es, + set = "\counterparameter{#1}\c!prefixset", + segments = "\counterparameter{#1}\c!prefixsegments", + connector = \!!bs\counterparameter{#1}\c!prefixconnector\!!es, }, { - order = "\structurecounterparameter{#1}\c!numberorder", - separatorset = "\structurecounterparameter{#1}\c!numberseparatorset", - conversion = \!!bs\structurecounterparameter{#1}\c!numberconversion\!!es, - conversionset = "\structurecounterparameter{#1}\c!numberconversionset", - starter = \!!bs\structurecounterparameter{#1}\c!numberstarter\!!es, - stopper = \!!bs\structurecounterparameter{#1}\c!numberstopper\!!es, - segments = "\structurecounterparameter{#1}\c!numbersegments", + order = "\counterparameter{#1}\c!numberorder", + separatorset = "\counterparameter{#1}\c!numberseparatorset", + conversion = \!!bs\counterparameter{#1}\c!numberconversion\!!es, + conversionset = "\counterparameter{#1}\c!numberconversionset", + starter = \!!bs\counterparameter{#1}\c!numberstarter\!!es, + stopper = \!!bs\counterparameter{#1}\c!numberstopper\!!es, + segments = "\counterparameter{#1}\c!numbersegments", type = "#2", } - )}% - \endgroup} + )}} -\unexpanded\def\convertedsubstructurecounter - {\dotripleempty\doconvertedsubstructurecounter} +\unexpanded\def\convertedsubcounter + {\dotripleempty\strc_counters_converted_sub} -\def\doconvertedsubstructurecounter[#1][#2][#3]% #2 can be n or n:m +\def\strc_counters_converted_sub[#1][#2][#3]% #2 can be n or n:m {\ifsecondargument - \doconvertedstructurecounter[#1][\c!numbersegments=#2,#3]% + \strc_counters_converted[#1][\c!numbersegments=#2,#3]% \else - \secondargumentfalse\doconvertedstructurecounter[#1][]% + \secondargumentfalse\strc_counters_converted[#1][]% \fi} -\let\getstructurecounter\convertedstructurecounter - -\def\doifdefinedstructurecounter #1{\doifdefined {\csname\s!structurecounter#1\c!number\endcsname}} -\def\doifundefinedstructurecounter #1{\doifundefined {\csname\s!number#1\c!number\endcsname}} -\def\doifdefinedstructurecounterelse#1{\doifdefinedelse{\csname\s!number#1\c!number\endcsname}} - -\ifx\checkstructurecounter\undefined \def\checkstructurecounter[#1]{} \fi - -\def\checkstructurecounter[#1]{} - -%D What follows is a compatibility layer. This will be phased out (at -%D least from core usage). - -\def\reset - {\dosingleargument\doreset} - -\def\doreset[#1]% - {\processcommalist[#1]\dodoreset} - -\def\dodoreset#1% - {\csname\s!reset#1\endcsname}% - -\let \numberparameter \structurecounterparameter % {name}\c!key +\unexpanded\def\doifdefinedcounter#1% + {\ifcsname\s!number#1\c!number\endcsname + \expandafter\firstofoneargument + \else + \expandafter\gobbleoneargument + \fi} -\let \definenumber \definestructurecounter % [name] -\let \setupnumber \setupstructurecounter % [name][setups] +\unexpanded\def\doifundefinedcounter#1% + {\ifcsname\s!number#1\c!number\endcsname + \expandafter\gobbleoneargument + \else + \expandafter\firstofoneargument + \fi} -\let \setnumber \setstructurecounter % [name]{value} -\let \resetnumber \resetstructurecounter % [name] -\let \savenumber \savestructurecounter % [name] -\let \restorenumber \restorestructurecounter % [name] -\let \incrementnumber \incrementstructurecounter % [name] -\let \decrementnumber \decrementstructurecounter % [name] -\let \rawnumber \rawstructurecounter % [name] -\let \getnumber \getstructurecounter % [name] -\let \convertednumber \getstructurecounter % [name] +\unexpanded\def\doifdefinedcounterelse#1% + {\ifcsname\s!number#1\c!number\endcsname + \expandafter\firstoftwoarguments + \else + \expandafter\secondoftwoarguments + \fi} -\let \doifdefinednumber \doifstructurecounter % {number}{true} -\let \doifundefinednumber \doifnotstructurecounter % {number}{true} -\let \doifdefinednumberelse \doifstructurecounterelse % {number}{true}{false} +%D What follows is a compatibility layer. -% weird one +\let \numberparameter \counterparameter % {name}\c!key -\def\accumulatednumber[#1]{} +\let \definenumber \definecounter % [name] +\let \setupnumber \setupcounter % [name][setups] -% funny, here, todo: these are the defaults +\let \setnumber \setcounter % [name]{value} +\let \resetnumber \resetcounter % [name] +\let \savenumber \savecounter % [name] +\let \restorenumber \restorecounter % [name] +\let \incrementnumber \incrementcounter % [name] +\let \decrementnumber \decrementcounter % [name] +\let \rawnumber \rawcounter % [name] +\let \getnumber \convertedcounter % [name] +\let \convertednumber \convertedcounter % [name] -\unexpanded\def\setupnumbering - {\dodoubleempty\getparameters[\??nr]} +\let \doifdefinednumber \doifdefinedcounter % {number}{true} +\let \doifundefinednumber \doifnotdefinedcounter % {number}{true} +\let \doifdefinednumberelse \doifdefinedcounterelse % {number}{true}{false} -\setupnumbering - [\c!way=\v!by\v!chapter, - \c!blockway=, - \c!state=\v!start] +\let \setupnumbering \setupstructurecounting %D Helpers: % call: % -% \dostructurecountercomponent +% \strc_counters_register_component % \currentfloat % \getfloatparameters \floatparameter \detokenizedfloatparameter % \hascaption \hastitle \hasnumber @@ -344,21 +503,22 @@ % % sets: % -% \laststructurecounternumber -% \laststructurecountersynchronize +% \m_strc_counters_last_registered_index +% \m_strc_counters_last_registered_attribute +% \m_strc_counters_last_registered_synchronize -\newconditional\hasstructurecountercaption -\newconditional\hasstructurecountertitle -\newconditional\hasstructurecounternumber +\newconditional\hascountercaption +\newconditional\hascountertitle +\newconditional\hascounternumber -\def\dostructurecountercomponent#1#2#3#4#5#6#7[#8][#9]% +\unexpanded\def\strc_counters_register_component#1#2#3#4#5#6#7[#8][#9]% maybe also nolist {\begingroup % #2[\s!haslevel=1,#8]% - \edef\hasstructurecountercaption{#3\s!hascaption}% - \edef\hasstructurecountertitle {#3\s!hastitle}% - \edef\hasstructurecounternumber {#3\s!hasnumber}% - \edef\hasstructurecounterlevel {#3\s!haslevel}% + \edef\hascounterlevel {#3\s!haslevel}% + \edef\hascountercaption{#3\s!hascaption}% + \edef\hascountertitle {#3\s!hastitle}% + \edef\hascounternumber {#3\s!hasnumber}% % \edef\askedprefixsegments{#3\c!prefixsegments}% \ifx\askedprefixsegments\v!auto @@ -374,60 +534,86 @@ \let\currentcounter\currentname \fi % - \doif{#3\c!title}\v!none{\setfalse\hasstructurecountercaption\setfalse\hasstructurecounternumber}% will become obsolete - % - \ifx\hasstructurecounternumber\v!yes % here due to previous test but best in callers - \doincrementsubstructurecounter[\currentcounter][\hasstructurecounterlevel]% - \fi - % - \ifx\hasstructurecountercaption\v!yes - \edef\currentexpansion{#3\c!expansion}% - \ifx\currentexpansion\s!xml - \edef\currenttitle{#4\c!title}% - \edef\currentbookmark{#4\c!bookmark}% + \ifx\hascountercaption\v!yes + \xdef\currentstructurecomponentname {#3\c!name}% + \xdef\currentstructurecomponentlevel {#3\c!level}% + \edef\currentstructurecomponentexpansion {#3\c!expansion}% + \xdef\currentstructurecomponentxmlsetup {#3\c!xmlsetup}% + \xdef\currentstructurecomponentcatcodes {#3\s!catcodes}% + \xdef\currentstructurecomponentlabel {#3\c!label}% + \xdef\currentstructurecomponentreference {#3\c!reference}% + \xdef\currentstructurecomponentreferenceprefix{#3\c!referenceprefix}% + \ifx\currentstructurecomponentexpansion\s!xml \xmlstartraw - \edef\currentlisttitle{#3\c!title}% + \xdef\currentstructurecomponenttitle {#3\c!title}% + \xdef\currentstructurecomponentbookmark{#3\c!bookmark}% + \xdef\currentstructurecomponentmarking {#3\c!marking}% + \xdef\currentstructurecomponentlist {#3\c!list}% \xmlstopraw - \let\currentcoding\s!xml + \ifx\currentstructurecomponentlist\empty + \globallet\currentstructurecomponentlist\currentstructurecomponenttitle + \fi + \globallet\currentstructurecomponentcoding\s!xml \else - \ifx\currentexpansion\v!yes - \edef\currenttitle{#3\c!title}% - \edef\currentbookmark{#3\c!bookmark}% + \ifx\currentstructurecomponentexpansion\v!yes + \xdef\currentstructurecomponenttitle {#3\c!title}% + \xdef\currentstructurecomponentbookmark{#3\c!bookmark}% + \xdef\currentstructurecomponentmarking {#3\c!marking}% + \xdef\currentstructurecomponentlist {#3\c!list}% \else - \edef\currenttitle{#4\c!title}% - \edef\currentbookmark{#4\c!bookmark}% + \xdef\currentstructurecomponenttitle {#4\c!title}% + \xdef\currentstructurecomponentbookmark{#4\c!bookmark}% + \xdef\currentstructurecomponentmarking {#4\c!marking}% + \xdef\currentstructurecomponentlist {#4\c!list}% + \iflocation \ifx\currentstructurecomponentbookmark\empty + \begingroup + \simplifycommands + \xdef\currentstructurecomponentbookmark{\detokenize\expandafter{\normalexpanded{#3\c!title}}}% + \endgroup + \fi \fi + \fi + \ifx\currentstructurecomponentlist\empty + \globallet\currentstructurecomponentlist\currentstructurecomponenttitle \fi - \let\currentlisttitle\currenttitle - \let\currentcoding\s!tex + \globallet\currentstructurecomponentcoding\s!tex \fi - \edef\currentlabel{#3\c!label}% - \edef\currentreference{#3\c!reference}% + % \setnextinternalreference - \xdef\laststructurecounternumber{\ctxlua{structures.lists.push{ + \xdef\m_strc_counters_last_registered_index{\ctxcommand{addtolist{ metadata = { kind = "#1", name = "\currentname", level = structures.sections.currentlevel(), - catcodes = \the\catcodetable, + catcodes = \the\ifx\currentstructurecomponentcatcodes\empty\catcodetable\else\csname\currentstructurecomponentcatcodes\endcsname\fi, + coding = "\currentstructurecomponentcoding", + \ifx\currentstructurecomponentcoding\s!xml + xmlroot = "\xmldocument", + \fi + \ifx\currentstructurecomponentxmlsetup\empty \else + xmlsetup = "\currentstructurexmlsetup", + \fi }, references = { internal = \nextinternalreference, - reference = "\currentreference", - referenceprefix = "\referenceprefix", - block = "\currentstructureblock", + block = "\currentsectionblock", + reference = "\currentstructurecomponentreference", + referenceprefix = "\currentstructurecomponentreferenceprefix", section = structures.sections.currentid(), }, titledata = { - label = \!!bs\detokenize\expandafter{\currentlabel }\!!es, - title = \!!bs\detokenize\expandafter{\currenttitle }\!!es, - \ifx\currentbookmark\currenttitle \else - bookmark = \!!bs\detokenize\expandafter{\currentbookmark }\!!es, + label = \!!bs\detokenize\expandafter{\currentstructurecomponentlabel }\!!es, + title = \!!bs\detokenize\expandafter{\currentstructurecomponenttitle }\!!es, + \ifx\currentstructurecomponentbookmark\currentstructurecomponenttitle \else + bookmark = \!!bs\detokenize\expandafter{\currentstructurecomponentbookmark }\!!es, + \fi + \ifx\currentstructurecomponentmarking\currentstructurecomponenttitle \else + marking = \!!bs\detokenize\expandafter{\currentstructurecomponentmarking }\!!es, \fi - \ifx\currentlisttitle\currenttitle \else - list = \!!bs\detokenize\expandafter{\currentlisttitle}\!!es, + \ifx\currentstructurecomponentlist\currentstructurecomponenttitle \else + list = \!!bs\detokenize\expandafter{\currentstructurecomponentlist}\!!es, \fi }, - \ifx\hasstructurecountercaption\v!yes + \ifx\hascounternumber\v!yes prefixdata = { prefix = "#3\c!prefix", separatorset = "#3\c!prefixseparatorset", @@ -448,24 +634,24 @@ segments = "#3\c!numbersegments", }, \fi - userdata = structures.helpers.touserdata(\!!bs\detokenize{#9}\!!es) + userdata = \!!bs\detokenize{#9}\!!es % will be converted to table at the lua end } }}% - \xdef\laststructurecounterattribute {\ctxlua {tex.write(structures.references.setinternalreference(nil,nil,\nextinternalreference))}}% - \xdef\laststructurecountersynchronize{\ctxlatelua{structures.lists.enhance(\laststructurecounternumber)}}% + \xdef\m_strc_counters_last_registered_attribute {\ctxlua {tex.write(structures.references.setinternalreference(nil,nil,\nextinternalreference))}}% + \xdef\m_strc_counters_last_registered_synchronize{\ctxlatecommand{enhancelist(\m_strc_counters_last_registered_index)}}% \else - \glet\laststructurecounternumber \relax - \glet\laststructurecounterattribute \attributeunsetvalue - \glet\laststructurecountersynchronize\relax + \glet\m_strc_counters_last_registered_index \relax + \glet\m_strc_counters_last_registered_attribute \attributeunsetvalue + \glet\m_strc_counters_last_registered_synchronize\relax \fi \endgroup} -\let\laststructurecounternumber \relax -\let\laststructurecounterattribute \relax -\let\laststructurecountersynchronize\relax +\let\m_strc_counters_last_registered_index \relax +\let\m_strc_counters_last_registered_attribute \relax +\let\m_strc_counters_last_registered_synchronize\relax -\def\dostructurecountersetup#1#2% name \someparameter - {\setupstructurecounter +\def\strc_counter_setup_using_parameter#1#2% name \someparameter + {\setupcounter [#1] [ \c!start=#2\c!start, \c!state=#2\c!state, % beware, "" == start @@ -489,7 +675,7 @@ \c!numberstopper=#2\c!numberstopper, \c!numbersegments=#2\c!numbersegments]} -\def\presetstructurecountersetup#1#2% \setupcommand \someparameter +\def\strc_counter_preset_using_parameter#1#2% \setupcommand \someparameter {#1% [\c!way =#2\c!way, \c!prefix =#2\c!prefix, |