%D \module %D [ file=strc-num, %D version=2008.10.20, %D title=\CONTEXT\ Structure Macros, %D subtitle=Basic Numbering, %D author=Hans Hagen, %D date=\currentdate, %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 %C details. \writestatus{loading}{ConTeXt Structure Macros / Basic Numbering} \registerctxluafile{strc-num}{1.001} \unprotect % work in progress % to be checked: can we use the command handler code here? % all settings will move to lua \installcorenamespace{counter} \installcommandhandler \??counter {counter} \??counter \let\setupstructurecounting\setupcounter \setupcounter [\c!way=\v!by\v!chapter, % \c!blockway=, % \c!prefixstarter=, % \c!prefixstopper=, \c!prefixconnector=., \c!prefixsegments=\autostructureprefixsegments\rootcounterparameter, \c!start=\zerocount, \c!prefix=\v!yes, \c!state=\v!start] \def\autostructureprefixsegments#1% todo: \c!prefixsegments=\v!auto {2:\thenamedheadlevel{\ctxcommand{way("#1\c!way")}}} \appendtoks \resetcounterparameter\s!counter \to \everypresetcounter \appendtoks \ifx\currentcounterparent\empty \edef\p_start{\counterparameter\c!start}% \ctxcommand{definecounter { name = "\currentcounter", start = \ifx\p_start\empty0\else\number\p_start\fi, counter = "\counterparameter\s!counter", method = "\counterparameter\c!method", }}% \letcounterparameter\s!name\currentcounter \else \letcounterparameter\s!name\currentcounterparent \fi \strc_counters_check_setup \to \everydefinecounter \appendtoks \ifx\currentcounter\empty \else \edef\p_start{\counterparameter\c!start}% \setexpandedcounterparameter\c!start{\ifx\p_start\empty0\else\number\p_start\fi}% \strc_counters_check_setup \fi \to \everysetupcounter % % % % \def\strc_counters_way#1% slow, we need to store it at the tex end {\ctxcommand{way("\namedcounterparameter{#1}\c!way")}} % \def\thenamedcounterlevel#1% % {\thenamedheadlevel{\strc_counters_way{#1}}} \def\thenamedcounterlevel#1% {\xthenamedheadlevel{\strc_counters_way{#1}}} % \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}}% % \edef\p_start{\counterparameter{#1}\c!start}% % \ctxcommand{checkcountersetup("#1",\currentcounterlevel,\ifx\p_start\empty0\else\number\p_start\fi,"\counterparameter{#1}\c!state")}% % \fi} \def\strc_counters_check_setup {\edef\p_name{\directcounterparameter\s!name}% \ifx\currentcounter\p_name \edef\currentcounterlevel{\thenamedcounterlevel\currentcounter}% \edef\p_start{\counterparameter\c!start}% \ctxcommand{checkcountersetup("\currentcounter",\currentcounterlevel,\ifx\p_start\empty0\else\number\p_start\fi,"\counterparameter\c!state")}% \fi} \unexpanded\def\doifcounterelse #1{\ctxcommand{doifelsecounter("\namedcounterparameter{#1}\s!name")}} \unexpanded\def\doifcounter #1{\ctxcommand{doifcounter ("\namedcounterparameter{#1}\s!name")}} \unexpanded\def\doifnotcounter #1{\ctxcommand{doifnotcounter ("\namedcounterparameter{#1}\s!name")}} \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\strc_counters_reset_interfaced {\ifsecondargument \singleexpandafter\strc_counters_reset_two \else\iffirstargument \doubleexpandafter\strc_counters_reset_one \else \doubleexpandafter\gobbletwooptionals \fi\fi} \def\strc_counters_increment_interfaced {\ifsecondargument \singleexpandafter\strc_counters_increment_two \else\iffirstargument \doubleexpandafter\strc_counters_increment_one \else \doubleexpandafter\gobbletwooptionals \fi\fi} \def\strc_counters_decrement_interfaced {\ifsecondargument \singleexpandafter\strc_counters_decrement_two \else\iffirstargument \doubleexpandafter\strc_counters_decrement_one \else \doubleexpandafter\gobbletwooptionals \fi\fi} \def\strc_counters_raw_interfaced {\ifsecondargument \singleexpandafter\strc_counters_raw_two \else\iffirstargument \doubleexpandafter\strc_counters_raw_one \else \doubleexpandafter\gobbletwooptionals \fi\fi} \def\strc_counters_last_interfaced {\ifsecondargument \singleexpandafter\strc_counters_last_two \else\iffirstargument \doubleexpandafter\strc_counters_last_one \else \doubleexpandafter\gobbletwooptionals \fi\fi} \def\strc_counters_first_interfaced {\ifsecondargument \singleexpandafter\strc_counters_first_two \else\iffirstargument \doubleexpandafter\strc_counters_first_one \else \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\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 ("\namedcounterparameter{#1}\s!name",\number#2,\number#3)}} \unexpanded\def\strc_counters_setown_sub #1#2#3{\ctxcommand{setowncounter ("\namedcounterparameter{#1}\s!name",\number#2,"#3")}} \unexpanded\def\strc_counters_restart_sub #1#2#3{\ctxcommand{restartcounter("\namedcounterparameter{#1}\s!name",\number#2,\number#3)}} \unexpanded\def\strc_counters_reset_sub #1#2{\ctxcommand{resetcounter ("\namedcounterparameter{#1}\s!name",\number#2)}} \unexpanded\def\strc_counters_increment_sub #1#2{\ctxcommand{addcounter ("\namedcounterparameter{#1}\s!name",\number#2,1)}} \unexpanded\def\strc_counters_decrement_sub #1#2{\ctxcommand{addcounter ("\namedcounterparameter{#1}\s!name",\number#2,-1)}} \def\strc_counters_raw_sub #1#2{\ctxcommand{countervalue ("\namedcounterparameter{#1}\s!name",\number#2)}} % maybe raw \def\strc_counters_last_sub #1#2{\ctxcommand{lastcountervalue ("\namedcounterparameter{#1}\s!name",\number#2)}} \def\strc_counters_first_sub #1#2{\ctxcommand{firstcountervalue ("\namedcounterparameter{#1}\s!name",\number#2)}} \def\strc_counters_next_sub #1#2{\ctxcommand{nextcountervalue ("\namedcounterparameter{#1}\s!name",\number#2)}} \def\strc_counters_prev_sub #1#2{\ctxcommand{previouscountervalue("\namedcounterparameter{#1}\s!name",\number#2)}} \def\strc_counters_subs_sub #1#2{\ctxcommand{subcountervalues ("\namedcounterparameter{#1}\s!name",\number#2)}} \unexpanded\def\strc_counters_save #1{\ctxcommand{savecounter ("\namedcounterparameter{#1}\s!name")}} \unexpanded\def\strc_counters_restore #1{\ctxcommand{restorecounter("\namedcounterparameter{#1}\s!name")}} \unexpanded\def\strc_counters_incremented #1{\ctxcommand{incrementedcounter("\namedcounterparameter{#1}\s!name",1, 1)}} \unexpanded\def\strc_counters_decremented #1{\ctxcommand{incrementedcounter("\namedcounterparameter{#1}\s!name",1,-1)}} \unexpanded\def\showcounter [#1]{\ctxcommand{tracecounter("\namedcounterparameter{#1}\s!name")}} \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("\namedcounterparameter{#1}\s!name",\number#2,1)}} \unexpanded\def\convertedcounter {\dodoubleempty\strc_counters_converted} \def\strc_counters_converted[#1][#2]% {\begingroup \edef\currentcounter{#1}% \ifsecondargument\setupcurrentcounter[#2]\fi \ctxlua{structures.sections.prefixedconverted( "\counterparameter\s!name", { prefix = "\counterparameter\c!prefix", separatorset = "\counterparameter\c!prefixseparatorset", conversion = "\counterparameter\c!prefixconversion", conversionset = "\counterparameter\c!prefixconversionset", starter = \!!bs\counterparameter\c!prefixstarter\!!es, stopper = \!!bs\counterparameter\c!prefixstopper\!!es, set = "\counterparameter\c!prefixset", segments = "\counterparameter\c!prefixsegments", connector = \!!bs\counterparameter\c!prefixconnector\!!es, }, { order = "\counterparameter\c!numberorder", separatorset = "\counterparameter\c!numberseparatorset", conversion = \!!bs\counterparameter\c!numberconversion\!!es, conversionset = "\counterparameter\c!numberconversionset", starter = \!!bs\counterparameter\c!numberstarter\!!es, stopper = \!!bs\counterparameter\c!numberstopper\!!es, segments = "\counterparameter\c!numbersegments", type = "\counterparameter\c!type", criterium = "\counterparameter\c!criterium", % might change if we also want this with sectioning } )}% \endgroup} \def\directconvertedcounter#1#2% name, type {\ctxlua{structures.sections.prefixedconverted( "\namedcounterparameter{#1}\s!name", { prefix = "\namedcounterparameter{#1}\c!prefix", separatorset = "\namedcounterparameter{#1}\c!prefixseparatorset", conversion = "\namedcounterparameter{#1}\c!prefixconversion", conversionset = "\namedcounterparameter{#1}\c!prefixconversionset", % starter = \!!bs\namedcounterparameter{#1}\c!prefixstarter\!!es, % stopper = \!!bs\namedcounterparameter{#1}\c!prefixstopper\!!es, set = "\namedcounterparameter{#1}\c!prefixset", segments = "\namedcounterparameter{#1}\c!prefixsegments", connector = \!!bs\namedcounterparameter{#1}\c!prefixconnector\!!es, }, { order = "\namedcounterparameter{#1}\c!numberorder", separatorset = "\namedcounterparameter{#1}\c!numberseparatorset", conversion = \!!bs\namedcounterparameter{#1}\c!numberconversion\!!es, conversionset = "\namedcounterparameter{#1}\c!numberconversionset", starter = \!!bs\namedcounterparameter{#1}\c!numberstarter\!!es, stopper = \!!bs\namedcounterparameter{#1}\c!numberstopper\!!es, segments = "\namedcounterparameter{#1}\c!numbersegments", type = "#2", } )}} \unexpanded\def\convertedsubcounter {\dotripleempty\strc_counters_converted_sub} \def\strc_counters_converted_sub[#1][#2][#3]% #2 can be n or n:m {\ifsecondargument \strc_counters_converted[#1][\c!numbersegments=#2,#3]% \else \secondargumentfalse\strc_counters_converted[#1][]% \fi} % \unexpanded\def\doifdefinedcounter#1% % {\ifcsname\namedcounterhash{#1}\s!name\endcsname % \expandafter\firstofoneargument % \else % \expandafter\gobbleoneargument % \fi} % % \unexpanded\def\doifundefinedcounter#1% % {\ifcsname\namedcounterhash{#1}\s!name\endcsname % \expandafter\gobbleoneargument % \else % \expandafter\firstofoneargument % \fi} % % \unexpanded\def\doifdefinedcounterelse#1% % {\ifcsname\namedcounterhash{#1}\s!name\endcsname % \expandafter\firstoftwoarguments % \else % \expandafter\secondoftwoarguments % \fi} \unexpanded\def\doifdefinedcounter {\doifcommandhandler \??counter} \unexpanded\def\doifundefinedcounter {\doifnotcommandhandler \??counter} \unexpanded\def\doifdefinedcounterelse{\doifelsecommandhandler\??counter} %D What follows is a compatibility layer. \let \numberparameter \namedcounterparameter % {name}\c!key \let \definenumber \definecounter % [name] \let \setupnumber \setupcounter % [name][setups] \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] \let \doifdefinednumber \doifdefinedcounter % {number}{true} \let \doifundefinednumber \doifnotdefinedcounter % {number}{true} \let \doifdefinednumberelse \doifdefinedcounterelse % {number}{true}{false} \let \setupnumbering \setupcounter %D Helpers: % call: % % \strc_counters_register_component % \currentfloat % \getfloatparameters \floatparameter \detokenizedfloatparameter % \hascaption \hastitle \hasnumber % [settings][userdata] % % sets: % % \m_strc_counters_last_registered_index % \m_strc_counters_last_registered_attribute % \m_strc_counters_last_registered_synchronize % currentstructurecomponent => \strc_current_ or just \m_strc_ \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\p_haslevel {#3\s!haslevel}% \edef\p_hascaption{#3\s!hascaption}% \edef\p_hastitle {#3\s!hastitle}% \edef\p_hasnumber {#3\s!hasnumber}% % \edef\p_prefixsegments{#3\c!prefixsegments}% \ifx\p_prefixsegments\v!auto \edef\p_prefixsegments{\autostructureprefixsegments#3}% \fi % \edef\currentname{#3\s!name}% \ifx\currentname\empty \edef\currentname{#1}% \fi \edef\currentcounter{#3\s!counter}% \ifx\currentcounter\empty \let\currentcounter\currentname \fi % \ifx\p_hascaption\v!yes \xdef\currentstructurecomponentname {#3\s!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 \xdef\currentstructurecomponenttitle {#3\c!title}% \xdef\currentstructurecomponentbookmark{#3\c!bookmark}% \xdef\currentstructurecomponentmarking {#3\c!marking}% \xdef\currentstructurecomponentlist {#3\c!list}% \xmlstopraw \ifx\currentstructurecomponentlist\empty \globallet\currentstructurecomponentlist\currentstructurecomponenttitle \fi \globallet\currentstructurecomponentcoding\s!xml \else \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 \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 \globallet\currentstructurecomponentcoding\s!tex \fi % \setnextinternalreference \xdef\m_strc_counters_last_registered_index{\ctxcommand{addtolist{ metadata = { kind = "#1", name = "\currentname", level = structures.sections.currentlevel(), 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, block = "\currentsectionblock", reference = "\currentstructurecomponentreference", referenceprefix = "\currentstructurecomponentreferenceprefix", section = structures.sections.currentid(), }, titledata = { 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\currentstructurecomponentlist\currentstructurecomponenttitle \else list = \!!bs\detokenize\expandafter{\currentstructurecomponentlist}\!!es, \fi }, \ifx\p_hasnumber\v!yes prefixdata = { prefix = "#3\c!prefix", separatorset = "#3\c!prefixseparatorset", conversion = \!!bs#3\c!prefixconversion\!!es, conversionset = "#3\c!prefixconversionset", set = "#3\c!prefixset", % segments = "#3\c!prefixsegments", segments = "\p_prefixsegments", connector = \!!bs#3\c!prefixconnector\!!es, }, numberdata = { % more helpers here, like compact elsewhere numbers = structures.counters.compact("\currentcounter",nil,true), group = "#3\c!group", groupsuffix = \!!bs#3\c!groupsuffix\!!es, counter = "\currentcounter", separatorset = "#3\c!numberseparatorset", conversion = \!!bs#3\c!numberconversion\!!es, conversionset = "#3\c!numberconversionset", starter = \!!bs#3\c!numberstarter\!!es, stopper = \!!bs#3\c!numberstopper\!!es, segments = "#3\c!numbersegments", }, \fi userdata = \!!bs\detokenize{#9}\!!es % will be converted to table at the lua end } }}% \xdef\m_strc_counters_last_registered_attribute {\ctxcommand {setinternalreference(nil,nil,\nextinternalreference)}}% \xdef\m_strc_counters_last_registered_synchronize{\ctxlatecommand{enhancelist(\m_strc_counters_last_registered_index)}}% \else \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\m_strc_counters_last_registered_index \relax \let\m_strc_counters_last_registered_attribute \relax \let\m_strc_counters_last_registered_synchronize\relax % This can be improved as we don't need to pas all these variables % each time (we can set them up once). \unexpanded\def\strc_counter_preset_using_parameter#1#2% \setupcommand \someparameter {#1% [\c!way =#2\c!way, \c!prefix =#2\c!prefix, \c!prefixseparatorset =#2\c!prefixseparatorset, \c!prefixconversion =#2\c!prefixconversion, \c!prefixconversionset=#2\c!prefixconversionset, \c!prefixstarter =#2\c!prefixstarter, \c!prefixstopper =#2\c!prefixstopper, \c!prefixsegments =#2\c!prefixsegments, \c!prefixset =#2\c!prefixset, \c!prefixconnector =#2\c!prefixconnector, \c!numberseparatorset =#2\c!numberseparatorset, \c!numberconversion =#2\c!numberconversion, \c!numberconversionset=#2\c!numberconversionset, \c!numberstarter =#2\c!numberstarter, \c!numberstopper =#2\c!numberstopper, \c!numbersegments =#2\c!numbersegments]} % \unexpanded\def\strc_counter_setup_using_parameter#1#2% name \someparameter % {\setupcounter % [#1] % [ \c!start=#2\c!start, % \c!state=#2\c!state, % beware, "" == start % \c!way=#2\c!way, % % % \c!prefix=#2\c!prefix, % \c!prefixseparatorset=#2\c!prefixseparatorset, % \c!prefixconversion=#2\c!prefixconversion, % \c!prefixconversionset=#2\c!prefixconversionset, % \c!prefixstarter=#2\c!prefixstarter, % \c!prefixstopper=#2\c!prefixstopper, % \c!prefixset=#2\c!prefixset, % \c!prefixsegments=#2\c!prefixsegments, % \c!prefixset=#2\c!prefixset, % \c!prefixconnector=#2\c!prefixconnector, % % % \c!numberseparatorset=#2\c!numberseparatorset, % \c!numberconversion=#2\c!numberconversion, % \c!numberconversionset=#2\c!numberconversionset, % \c!numberstarter=#2\c!numberstarter, % \c!numberstopper=#2\c!numberstopper, % \c!numbersegments=#2\c!numbersegments]} \unexpanded\def\strc_counter_setup_using_parameter#1#2% name \someparameter {\edef\currentcounter{#1}% % \setcounterparameter \c!start{#2\c!start}% \setcounterparameter \c!state{#2\c!state}% % beware, "" == start \setcounterparameter \c!way{#2\c!way}% % \setcounterparameter \c!prefix{#2\c!prefix}% \setcounterparameter \c!prefixseparatorset{#2\c!prefixseparatorset}% \setcounterparameter \c!prefixconversion{#2\c!prefixconversion}% \setcounterparameter\c!prefixconversionset{#2\c!prefixconversionset}% \setcounterparameter \c!prefixstarter{#2\c!prefixstarter}% \setcounterparameter \c!prefixstopper{#2\c!prefixstopper}% \setcounterparameter \c!prefixset{#2\c!prefixset}% \setcounterparameter \c!prefixsegments{#2\c!prefixsegments}% \setcounterparameter \c!prefixset{#2\c!prefixset}% \setcounterparameter \c!prefixconnector{#2\c!prefixconnector}% % \setcounterparameter \c!numberseparatorset{#2\c!numberseparatorset}% \setcounterparameter \c!numberconversion{#2\c!numberconversion}% \setcounterparameter\c!numberconversionset{#2\c!numberconversionset}% \setcounterparameter \c!numberstarter{#2\c!numberstarter}% \setcounterparameter \c!numberstopper{#2\c!numberstopper}% \setcounterparameter \c!numbersegments{#2\c!numbersegments}% % \the\everysetupcounter} \unexpanded\def\mult_interfaces_counter_association#1#2#3#4#5#6#7% tag current setup parameter list sync register {\strc_counter_preset_using_parameter#3\rootcounterparameter \newtoks#5% \unexpanded\def #6{\ifx#2\empty\the#5\else\strc_counter_setup_using_parameter#2#4\fi}% sync \unexpanded\def#7##1{\normalexpanded{#5{\the#5\strc_counter_setup_using_parameter{##1}\noexpand#4}}}} % register \unexpanded\def\installcounterassociation#1% => synchronize#1counters register#1counter {\normalexpanded {\mult_interfaces_counter_association {#1}% not \??xx but xx \expandafter\noexpand\csname current#1\endcsname \expandafter\noexpand\csname setup#1\endcsname \expandafter\noexpand\csname #1parameter\endcsname \expandafter\noexpand\csname counter_association_list_#1\endcsname \expandafter\noexpand\csname synchronize#1counters\endcsname \expandafter\noexpand\csname register#1counter\endcsname}} % needs testing: % % \unexpanded\def\strc_counter_setup_push#1#2#3% \someparameter \directsomeparameter \setexpandedsomeparameter % {\let\savedcounterparameter \counterparameter % \let\saveddirectcounterparameter \directcounterparameter % \let\savedsetexpandedcounterparameter\setexpandedcounterparameter % % remap % \let\counterparameter #1% % \let\directcounterparameter #2% % \let\setexpandedcounterparameter #3} % % \unexpanded\def\strc_counter_setup_pop % {\let\counterparameter \savedcounterparameter % \let\directcounterparameter \saveddirectcounterparameter % \let\setexpandedcounterparameter \savedsetexpandedcounterparameter} % % \unexpanded\def\mult_interfaces_counter_association#1#2#3#4#5#6#7% tag current setup parameter list sync register % {\strc_counter_preset_using_parameter#3\rootcounterparameter % \newtoks#5% % \unexpanded\def#6% sync % {\strc_counter_setup_push % \ifx#2\empty % \the#5% % \else % \let\currentcounter\empty % \the\everysetupcounter % \fi % \strc_counter_setup_pop}% % \unexpanded\def#7##1% register % {\normalexpanded{#5{\the#5\edef\noexpand\currentcounter{##1}\noexpand\the\everysetupcounter}}}} %D For good old times (easier to explain in manuals): %D %D \starttyping %D \setcounter[userpage][9] %D \setupcounter[userpage][number=9] %D \setupuserpagenumber[number=9] %D \stoptyping % needs testing: we might have conflicts with mixins % % \appendtoks % \ifx\currentcounter\empty \else % \edef\p_number{\counterparameter\c!number}% % \ifx\p_number\empty \else % \strc_counters_set\currentcounter\p_number % \letcounterparameter\c!number\empty % \fi % \fi % \to \everysetupcounter \protect \endinput