diff options
author | Mojca Miklavec <mojca.miklavec@gmail.com> | 2012-05-14 17:38:55 +0000 |
---|---|---|
committer | Mojca Miklavec <mojca.miklavec@gmail.com> | 2012-05-14 17:38:55 +0000 |
commit | 15995e10bfc68edf79970c4ea4fbb6678566c46e (patch) | |
tree | 2de7ca2a83f2d37ef043ad7429a5cb945bb79ddb /Master/texmf-dist/tex/context/base/strc-sec.mkiv | |
parent | c9a39f716f1e5ec820ed3aab2c9aef25c5a9d730 (diff) |
ConTeXt 2012.05.14 16:00
git-svn-id: svn://tug.org/texlive/trunk@26371 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-sec.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/strc-sec.mkiv | 1133 |
1 files changed, 519 insertions, 614 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-sec.mkiv b/Master/texmf-dist/tex/context/base/strc-sec.mkiv index 6cb6f84c142..e9b613f219f 100644 --- a/Master/texmf-dist/tex/context/base/strc-sec.mkiv +++ b/Master/texmf-dist/tex/context/base/strc-sec.mkiv @@ -5,7 +5,7 @@ %D subtitle=Sectioning, %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 @@ -50,411 +50,350 @@ \def\getsomestructurenumber #1#2{\ctxlua{structures.sections.getnumber(#1,"#2")}} % level, what \def\getfullstructurenumber #1{\ctxlua{structures.sections.fullnumber(#1)}} % level \def\getsomefullstructurenumber#1#2{\ctxlua{structures.sections.fullnumber(#1,"#2")}} -\def\getspecificstructuretitle #1{\ctxlua{structures.sections.structuredata(#1,"titledata.title",nil,"\structureheadparameter\s!catcodes")}}% +\def\getspecificstructuretitle #1{\ctxlua{structures.sections.structuredata("#1","titledata.title",nil,"\headparameter\s!catcodes")}}% -% interface +% will be: +% +% \def\getfullstructurenumber #1{\ctxcommand{structurenumber(\thenamedheadlevel{#1})}} -\def\structureheadparameter #1{\csname\dostructureheadparameter{\??nh\currentstructurehead}{#1}\endcsname} -\def\structureheadparameterhash #1{\dostructureheadparameterhash {\??nh\currentstructurehead}{#1}} -\def\namedstructureheadparameter#1#2{\csname\dostructureheadparameter{\??nh#1}{#2}\endcsname} +% structure heads (like \startchapter) -\def\dostructureheadparameter #1#2{\ifcsname#1#2\endcsname#1#2\else\expandafter\dostructureheadparentparameter \csname#1\s!parent\endcsname{#2}\fi} -\def\dostructureheadparameterhash#1#2{\ifcsname#1#2\endcsname #1\else\expandafter\dostructureheadparentparameterhash\csname#1\s!parent\endcsname{#2}\fi} +% \c!deeptextcommand, \c!deepnumbercommand: undefined ! +% \c!before \c!after \c!distance +% \c!page \c!header \c!text \c!footer=, +% \c!numbercommand \c!textcommand \c!ownnumber \c!number +% \c!file \c!grid \c!margintext +% \c!expansion \c!xmlsetup \s!catcode -\def\dostructureheadparentparameter #1#2{\ifx#1\relax\s!empty\else\dostructureheadparameter #1{#2}\fi} -\def\dostructureheadparentparameterhash#1#2{\ifx#1\relax \else\dostructureheadparameterhash#1{#2}\fi} +\installcorenamespace{head} +\installcorenamespace{headlevel} +\installcorenamespace{headincrement} +\installcorenamespace{headplace} +\installcorenamespace{headmarkyes} +\installcorenamespace{headmarknop} -\def\structureheadparameterstrict#1{\csname\ifcsname\??nh\currentstructurehead#1\endcsname\??nh\currentstructurehead#1\else\s!empty\fi\endcsname} +\installcommandhandler \??head {head} \??head -\def\dosetstructureheadattributes#1#2% style color - {\edef\fontattributehash {\structureheadparameterhash#1}% - \edef\colorattributehash{\structureheadparameterhash#2}% - \ifx\fontattributehash \empty\else\dosetfontattribute \fontattributehash #1\fi - \ifx\colorattributehash\empty\else\dosetcolorattribute\colorattributehash#2\fi} +\let\setupheads\setuphead % will go -% so far +\appendtoks + \ifx\currentheadparent\empty + \edef\currentheaddefault{\headparameter\c!default}% + \edef\currentheadsection{\headparameter\c!section}% + \ifx\currenthead\currentheaddefault + \let\currentheadparent\currentheadsection + \else\ifx\currentheaddefault\empty + \let\currentheadparent\currentheadsection + \else + \let\currentheadparent\currentheaddefault + \fi\fi + \normalexpanded {% + \setheadparameter{\c!label}{\currenthead}% + \setheadparameter{\c!coupling}{\currenthead}% + \setheadparameter{\s!parent}{\??head\currentheadparent}% + \definemarking[\currenthead] [\currentheadsection]% + \definemarking[\currenthead\v!number][\currentheadsection]% + \setupmarking [\currenthead] [\c!filtercommand=\noexpand\sectionheadmarkingtitle {\currenthead}]% + \setupmarking [\currenthead\c!number][\c!filtercommand=\noexpand\sectionheadmarkingnumber{\currenthead}]% + }% + \doifelselist\currenthead\donothing + {\definelist[\currenthead][\c!prefix=\v!no]}% + \else + \normalexpanded {% + \setheadparameter{\c!label}{\currenthead}% + \setheadparameter{\c!coupling}{\currentheadparent}% + \definemarking[\currenthead] [\currentheadparent]% + \definemarking[\currenthead\v!number][\currentheadparent\c!number]% + }% + \doifelselist\currenthead\donothing + {\normalexpanded{\definelist[\currenthead][\currentheadparent][\c!prefix=\v!no]}}% + \fi + \presetlabeltext[\currenthead=]% + \the\everysetuphead +\to \everydefinehead -\newcount\maxstructuredepth +\appendtoks + \setstructurelevel\currenthead{\thenamedheadlevel\currenthead}% +\to \everydefinehead + +\appendtoks + % beware, this is a global register + \begingroup + \edef\currentsectionheadcoupling{\sectionheadcoupling\currenthead}% + \edef\currentsectionheadsection {\sectionheadsection \currentsectionheadcoupling}% + \edef\currentsectionlevel {\sectionlevel \currentsectionheadsection}% + \ctxlua{structures.sections.register("\currenthead",{ + coupling = "\currentsectionheadcoupling", + section = "\currentsectionheadsection", + level = \currentsectionlevel, + })}% + \endgroup +\to \everydefinehead + +\appendtoks + % \setevalue{\e!next \currenthead}{\donexthead [\currenthead]}% + \setevalue{\e!start\currenthead}{\dostarthead[\currenthead]}% + \setevalue{\e!stop \currenthead}{\dostophead [\currenthead]}% +\to \everydefinehead + +\appendtoks + \doifelse{\headparameter\c!ownnumber}\v!yes + {\setevalue\currenthead{\dohandleheadown[\currenthead]}} + {\setevalue\currenthead{\dohandleheadnop[\currenthead]}}% +\to \everysetuphead + +\let\currentnamedsection\empty + +\unexpanded\def\startnamedsection + {\dotripleempty\dostartnamedsection} -\let\laststructuresectionname\empty +\def\dostartnamedsection[#1]% [#2][#3] + {\pushmacro\currentnamedsection + \edef\currentnamedsection{#1}% + \normalexpanded{\dodostarthead[\currentnamedsection]}} % [#2][#3] + +\unexpanded\def\stopnamedsection + {\normalexpanded{\dostophead[\currentnamedsection]}% + \popmacro\currentnamedsection} + +% structure sections (the parents of chapter etc) + +\let\firstsectionname\empty +\let\lastsectionname \empty \let\resetallstructuremarks \relax \let\resetcurrentstructuremarks \relax \let\resetcurrentstructuremarkswithpage\relax -\def\resetallstructuremarks {\resetmarking[\v!section-1]} % will become option -\def\resetcurrentstructuremarks {\resetmarking[\laststructuresectionname]} % will become option -%def\resetcurrentstructuremarkswithpage{\resetmarking[\laststructuresectionname]} % will become option - -% \c!before=, -% \c!after=, -% \c!distance=\zeropoint, -% \c!page=, -% \c!header=, -% \c!text=, -% \c!footer=, -% \c!numbercommand=, -% \c!textcommand=, -% \c!ownnumber=\v!no, -% \c!number=\v!yes, -% \c!file=, -% \c!expansion=, -% \c!grid=, -% \c!margintext=, -% -% \c!xmlsetup=, -% \s!catcodes=, +\def\resetallstructuremarks {\resetmarking[\firstsectionname]} % will become option (was \v!section-1) +\def\resetcurrentstructuremarks {\resetmarking[\lastsectionname]} % will become option +%def\resetcurrentstructuremarkswithpage{\resetmarking[\lastsectionname]} % will become option -\newtoks\everydefinestructuresection +% -2=text -1=manual 0=block 1+=structurelevel -\appendtoks - % This is a rather practical default that we don't want to - % be part of the parent chain lookup mechanism; it's also - % mkii compatible. Somewhat weird that it's part of the - % top level structure but it will be flattened anyway. - \getparameters[\??nh\currentstructuresection] - [ \c!textstyle=\structureheadparameterstrict\c!style, - \c!textcolor=\structureheadparameterstrict\c!color, - \c!numberstyle=\structureheadparameterstrict\c!style, - \c!numbercolor=\structureheadparameterstrict\c!color]% -\to \everydefinestructuresection - -\unexpanded\def\definestructuresection[#1]% - {\ifcsname\??nh#1\endcsname - % redefinition is a rather fatal error - \else - \edef\currentstructuresection{#1}% - \global\advance\maxstructuredepth\plusone - \setevalue{\??nh#1\c!level}{\the\maxstructuredepth}% - \setstructurelevel{#1}{\the\maxstructuredepth}% - \normalexpanded{\noexpand\getparameters[\??nh#1][\s!parent=\??nh\laststructuresectionname]}% - \the\everydefinestructuresection +\newcount\maxstructuredepth + +\def\setnextsectionlevel#1% + {\global\advance\maxstructuredepth\plusone + \setevalue{\??headlevel#1}{\the\maxstructuredepth}} + +\def\sectionlevel#1% + {\csname\??headlevel\ifcsname\??headlevel#1\endcsname#1\else\v!none\fi\endcsname} + +\setvalue{\??headlevel\v!block}{0} +\setvalue{\??headlevel\v!none }{-1} +\setvalue{\??headlevel\v!text }{-2} + +\newtoks\everydefinesection + +\unexpanded\def\definesection[#1]% + {\ifcsname\??headlevel#1\endcsname \else + \edef\currentsection{#1}% not used, will go + \edef\currenthead{#1}% + \setnextsectionlevel{#1}% + \setstructurelevel{#1}{\sectionlevel{#1}}% + \normalexpanded{\setheadparameter{\s!parent}{\??head\lastsectionname}}% TO BE CHECKED, WE HAVE A HELPER + \the\everydefinesection % so far for these default inheritances \definemarking[#1]% \ifnum\maxstructuredepth>\plusone - \normalexpanded{\noexpand\relatemarking[#1][\laststructuresectionname]}% so, the parent will reset the child + \normalexpanded{\noexpand\relatemarking[#1][\lastsectionname]}% so, the parent will reset the child \fi - \xdef\laststructuresectionname{#1}% - \fi} - -\unexpanded\def\setupstructuresection - {\dotripleempty\dosetupstructuresection} + \xdef\lastsectionname{#1}% + \ifx\firstsectionname\empty + \glet\firstsectionname\lastsectionname + \fi + \fi} -\def\dosetupstructuresection[#1]% - {\doifdefinedelse{\??nh#1} - {\dodosetupstructuresection[#1]} - {\dodosetupstructuresection[\structuresectionheadsection{#1}]}} +\unexpanded\def\setupsection + {\dotripleempty\dosetupsection} -\def\dodosetupstructuresection[#1][#2][#3]% - {\ifthirdargument - \getparameters[\??nh#1#2][#3]% ? probably sectionblock +\def\dosetupsection[#1][#2][#3]% + {\ifcsname\??headlevel#1\endcsname + \dodosetupsection[#1][#2][#3]% \else - \getparameters[\??nh#1][#2]% + \dodosetupsection[\sectionheadsection{#1}][#2][#3]% \fi} -% -2=text -1=manual 0=block 1+=structurelevel +\def\dodosetupsection[#1][#2][#3]% + {\pushmacro\currenthead + \ifthirdargument + \edef\currenthead{#1#2}% % not used at any more in mkiv (sets now) + \setupcurrenthead[#3]% + \else + \edef\currenthead{#1}% + \setupcurrenthead[#2]% + \fi + \popmacro\currenthead} -\def\structuresectionlevel#1% - {\executeifdefined{\??nh#1\c!level}{-1}} - -\setvalue{\??nh\v!block\c!level}{0} -\setvalue{\??nh\v!none \c!level}{-1} -\setvalue{\??nh\v!text \c!level}{-2} - -% head -> structurehead - -\let\currentstructurehead\empty -\newtoks\everystructureheadsetup - -\unexpanded\def\setupstructureheads{\dosingleargument\dosetupstructureheads} -\unexpanded\def\setupstructurehead {\dodoubleempty\dosetupstructurehead} -\unexpanded\def\definestructurehead{\dodoubleempty\dodefinestructurehead} - -\newif\ifsectionnumber % maybe conditional - -\def\dosetupstructureheads[#1]% - {\getparameters[\??nh][#1]% - \doifelse{\structureheadparameter\c!sectionnumber}\v!yes\sectionnumbertrue\sectionnumberfalse} - -\def\dosetupstructurehead[#1][#2]% we move the test for command being nothing elsewhere (needed, else hard to trace) - {\processcommalist[#1]{\dodosetupstructurehead{#2}}} - -\def\dodosetupstructurehead#1#2% - {\edef\currentstructurehead{#2}% - \getparameters[\??nh#2][#1]% - \the\everystructureheadsetup} - -\def\dodefinestructurehead[#1][#2]% - {\processcommalist[#1]{\dododefinestructurehead{#2}}} - -\def\dododefinestructurehead#1#2% #1: parameters|parent, #2: self - {\doifsomethingelse{#2} - {\doifassignmentelse{#1} - \dodefineuniquestructurehead - {\doifdefinedelse{\??nh#1\s!parent} % just a check - \dodefineclonedstructurehead - \dodefineerrorstructurehead}} - \dodefineerrorstructurehead - {#2}{#1}} - -\def\dodefineerrorstructurehead#1#2% - {\setvalue{#1}{\par error: #1 is undefined\par}} - -% deeptextcommand and deepnumbercommand are left undefined ! - -\def\dodefineuniquestructurehead#1#2% class, parent - {\def\currentstructurehead{#1}% - \presetlabeltext[#1=]% - \getparameters[\??nh#1][\c!label=#1,#2]% - \edef\currentstructureheaddefault{\structureheadparameter\c!default}% - \edef\currentstructureheadsection{\structureheadparameter\c!section}% - \edef\currentstructureheadparent - {\ifx\currentstructurehead\currentstructureheaddefault - \currentstructureheadsection - \else\ifx\currentstructureheaddefault\empty - \currentstructureheadsection - \else - \currentstructureheaddefault - \fi\fi}% - \normalexpanded{\noexpand\getparameters[\??nh#1][\s!parent=\??nh\currentstructureheadparent]}% - % or just \setevalue{\??nh#1\s!parent}{\??nh\currentstructureheadparent}% - \definemarking[#1] [\currentstructureheadsection]% - \definemarking[#1\v!number][\currentstructureheadsection]% - \setupmarking [#1] [\c!filtercommand=\sectionheadmarkingtitle {#1}]% - \setupmarking [#1\c!number][\c!filtercommand=\sectionheadmarkingnumber{#1}]% - \doifundefined{\??li#1}{\definelist[#1][\c!prefix=\v!no]}% definestructurelist ? - \the\everystructureheadsetup} +% we share the parameters as sections are roots of heads so eventually we can +% consider \definesection -> \definehead with one argument + +\appendtoks + % This is a rather practical default that we don't want to + % be part of the parent chain lookup mechanism; it's also + % mkii compatible. Somewhat weird that it's part of the + % top level structure but it will be flattened anyway. + \let\currenthead\currentsection % + \setheadparameter\c!textstyle {\strictheadparameter\c!style}% + \setheadparameter\c!textcolor {\strictheadparameter\c!color}% + \setheadparameter\c!numberstyle{\strictheadparameter\c!style}% + \setheadparameter\c!numbercolor{\strictheadparameter\c!color}% +\to \everydefinesection + +% head -> head \def\sectionheadmarkingtitle #1#2{\ctxlua{structures.marks.title("#1","#2")}} \def\sectionheadmarkingnumber#1#2{\ctxlua{structures.marks.number("#1","#2")}} -\def\dodefineclonedstructurehead#1#2% class parent - {\def\currentstructurehead{#1}% - \presetlabeltext[#1=]% - \doifelse{#1}{#2} - {\getparameters[\??nh#1][\c!label=#1]% - \doifundefined{\??li#1}{\definelist[#1][\c!prefix=\v!no]}}% definestructurelist ? - {\getparameters[\??nh#1][\s!parent=\??nh#2,\c!label=#1,\c!coupling=#2]% - \definemarking[#1] [#2]% - \definemarking[#1\v!number][#2\c!number]% - \doifundefined{\??li#1}{\definelist[#1][#2][\c!prefix=\v!no]}}% definestructurelist ? - \the\everystructureheadsetup} - -\appendtoks - \setstructurelevel\currentstructurehead{\thenamedstructureheadlevel\currentstructurehead}% - \doifelse{\structureheadparameter\c!ownnumber}\v!yes - {\setevalue\currentstructurehead{\dohandlestructureheadown[\currentstructurehead]}} - {\setevalue\currentstructurehead{\dohandlestructureheadnop[\currentstructurehead]}}% - \setevalue{\e!next \currentstructurehead}{\donextstructurehead [\currentstructurehead]}% - \setevalue{\e!start\currentstructurehead}{\dostartstructurehead[\currentstructurehead]}% - \setevalue{\e!stop \currentstructurehead}{\dostopstructurehead [\currentstructurehead]}% -\to \everystructureheadsetup - -% todo, check if section is defined - -\def\structuresectionheadcoupling#1% - {\ifcsname\??nh#1\c!coupling\endcsname - \expandafter\structuresectionheadcoupling\csname\??nh#1\c!coupling\endcsname\else#1% - \fi} - -\def\structuresectionheadsection#1% - {\ifcsname\??nh#1\c!section\endcsname - \expandafter\structuresectionheadcoupling\csname\??nh#1\c!section\endcsname\else#1% - \fi} +\def\sectionheadcoupling#1{\namedheadparameter{#1}\c!coupling} +\def\sectionheadsection #1{\namedheadparameter{#1}\c!section} % head construction -\unexpanded\def\dohandlestructureheadown{\dodoubleempty\dodohandlestructureheadown} % [ref] {nr} {title} -\unexpanded\def\dohandlestructureheadnop{\dodoubleempty\dodohandlestructureheadnop} % [ref] {title} -\unexpanded\def\dostartstructurehead {\dotripleempty\dodostartstructurehead} % [settings] [userdata] +\unexpanded\def\dohandleheadown{\dodoubleempty\dodohandleheadown} % [ref] {nr} {title} +\unexpanded\def\dohandleheadnop{\dodoubleempty\dodohandleheadnop} % [ref] {title} +\unexpanded\def\dostarthead {\dotripleempty\dodostarthead} % [settings] [userdata] !!! also used at lua end \newconditional\currentstructureown -\newtoks\everybeforestructurehead % hook, todo: before/after keys -\newtoks\everyafterstructurehead % hook, todo: before/after keys +\newtoks\everybeforehead % hook, todo: before/after keys +\newtoks\everyafterhead % hook, todo: before/after keys -\unexpanded\def\dodohandlestructureheadown[#1][#2]#3#4% +\unexpanded\def\dodohandleheadown[#1][#2]#3#4% {\settrue\currentstructureown - \dohandlestructurehead{#1}{\c!reference={#2},\c!ownnumber={#3},\c!title={#4}}{}} % name ref nr title -- - -% \unexpanded\def\dodohandlestructureheadnop[#1][#2]#3% -% {\setfalse\currentstructureown -% \dohandlestructurehead{#1}{\c!reference={#2},\c!title={#3}}{}} % name ref nr title -- + \triggerautostructurelevel + \dohandlehead{#1}{\c!reference={#2},\c!ownnumber={#3},\c!title={#4}}{}} % name ref nr title -- -\unexpanded\def\dodohandlestructureheadnop[#1][#2]% for taco: [key=value] variant +\unexpanded\def\dodohandleheadnop[#1][#2]% for taco: [key=value] variant {\setfalse\currentstructureown - \doifassignmentelse{#2}\dodohandlestructureheadnopA\dodohandlestructureheadnopB{#1}{#2}} + \triggerautostructurelevel + \doifassignmentelse{#2}\dodohandleheadnopA\dodohandleheadnopB{#1}{#2}} -\unexpanded\def\dodohandlestructureheadnopA#1#2% - {\dohandlestructurehead{#1}{#2}{}} +\unexpanded\def\dodohandleheadnopA#1#2% + {\dohandlehead{#1}{#2}{}} -\unexpanded\def\dodohandlestructureheadnopB#1#2#3% - {\dohandlestructurehead{#1}{\c!reference={#2},\c!title={#3}}{}} % name ref nr title -- +\unexpanded\def\dodohandleheadnopB#1#2#3% + {\dohandlehead{#1}{\c!reference={#2},\c!title={#3}}{}} % name ref nr title -- -\unexpanded\def\dodostartstructurehead[#1][#2][#3]% for the moment no grouping, too annoying with page breaks +\unexpanded\def\dodostarthead[#1][#2][#3]% for the moment no grouping, too annoying with page breaks {\setfalse\currentstructureown - %\globalpushmacro\currentstructurehead - \xdef\currentstructurehead{#1}% - \structureheadparameter\c!beforesection - \the\everybeforestructurehead - \dohandlestructurehead{#1}{#2}{#3}} % name -- -- -- userdata (we might move the tagged to here) - -\unexpanded\def\dostopstructurehead[#1]% - {\dostoptagged\dostoptagged - %\globalpopmacro\currentstructurehead - \xdef\currentstructurehead{#1}% recover - \structureheadparameter\c!aftersection - \the\everyafterstructurehead} - -\unexpanded\def\donextstructurehead[#1][#2][#3]% - {\setfalse\currentstructureown - \xdef\currentstructurehead{#1}% - \dohandlestructurehead{#1}{#2}{#3}} % name -- -- -- userdata + %\globalpushmacro\currenthead % this does not work out well + \xdef\currenthead{#1}% + \setsystemmode\currenthead % new, also here now + \headparameter\c!beforesection % beware, no users vars set yet + \the\everybeforehead + \dohandlehead{#1}{#2}{#3}% name -- -- -- userdata (we might move the tagged to here) + \headparameter\c!insidesection} + +\unexpanded\def\dostophead[#1]% !!! also used at lua end + {\dostoptagged + \dostoptagged + %\globalpopmacro\currenthead % so we do a hard recover + \xdef\currenthead{#1}% recover + \headparameter\c!aftersection + \the\everyafterhead + \resetsystemmode\currenthead} % new, also here now + +% \unexpanded\def\donexthead[#1][#2][#3]% obsolete +% {\setfalse\currentstructureown +% \xdef\currenthead{#1}% +% \dohandlehead{#1}{#2}{#3}} % name -- -- -- userdata % \newconditional\structurereversesectionnumbers % todo: key/val -\newconditional\structureheadtolist -\newconditional\structureheaddoincrement -\newconditional\structureheaddoplace -\newconditional\structureheadleaveempty -\newconditional\structureheadhidden -\newconditional\structureheadshownumber -\newconditional\structureheadisdisplay - -\let\structureheadprefix\empty \def\structureheadprefixplus{+} - -% When do we reset the referenceprefix? This needs to be checked. Does it work -% at all? Todo: pushpop. - -% \def\setstructureheadreference -% {\edef\structureheadreference {\structureheadparameter\c!reference}% -% \edef\structureheadreferenceprefix{\structureheadparameter\c!prefix}% -% \ifx\structureheadreferenceprefix\empty -% \ifx\currentrefenceprefix\structureheadreferenceprefixplus -% \setupreferenceprefix[]% yes or no? only when set by structure -% \fi -% \else\ifx\structureheadreferenceprefix\structureheadreferenceprefixplus -% \ifx\structureheadreference\empty -% \expanded{\setupreferenceprefix[\structureheadreferenceprefixplus]}% -% \else -% \expanded{\setupreferenceprefix[\structureheadreference]}% we assume just one reference -% \fi -% \else -% \expanded{\setupreferenceprefix[\structureheadreferenceprefix]}% -% \fi\fi} - -% pop in stopsection commands unless empty - -\def\setstructureheadreference - {\edef\structureheadreference {\structureheadparameter\c!reference}% - \edef\structureheadreferenceprefix{\structureheadparameter\c!prefix}% - \ifx\structureheadreferenceprefix\empty - \let\structureheadreferenceprefix\referenceprefix - \else - \setupreferenceprefix[\structureheadreferenceprefix]% currenty no pop - \fi} - -\setvalue{\??nh:\c!incrementnumber:\v!yes }{\settrue \structureheaddoincrement\settrue \structureheadtolist} -\setvalue{\??nh:\c!incrementnumber:\v!no }{\setfalse\structureheaddoincrement\setfalse\structureheadtolist} -\setvalue{\??nh:\c!incrementnumber:\v!list }{\setfalse\structureheaddoincrement\settrue \structureheadtolist} -\setvalue{\??nh:\c!incrementnumber:\s!empty}{\settrue \structureheaddoincrement\settrue \structureheadtolist} - -\def\setstructureheadincrement - {\edef\currentstructureheadincrement{\structureheadparameter\c!incrementnumber}% - \ifcsname\??nh:\c!incrementnumber:\currentstructureheadincrement\endcsname - \csname\??nh:\c!incrementnumber:\currentstructureheadincrement\endcsname +\newconditional\headtolist +\newconditional\headdoincrement +\newconditional\headdoplace +\newconditional\headleaveempty +\newconditional\headhidden +\newconditional\headshownumber +\newconditional\headisdisplay + +\setvalue{\??headincrement\v!yes }{\settrue \headdoincrement\settrue \headtolist} +\setvalue{\??headincrement\v!no }{\setfalse\headdoincrement\setfalse\headtolist} +\setvalue{\??headincrement\v!list }{\setfalse\headdoincrement\settrue \headtolist} +\setvalue{\??headincrement\s!empty}{\settrue \headdoincrement\settrue \headtolist} + +\def\setheadincrement + {\edef\currentheadincrement{\headparameter\c!incrementnumber}% + \ifcsname\??headincrement\currentheadincrement\endcsname + \csname\??headincrement\currentheadincrement\endcsname \else - \settrue \structureheaddoincrement\settrue \structureheadtolist - % \filterstructureheadnumber + \settrue \headdoincrement\settrue \headtolist + % \filterheadnumber \fi} -\def\filterstructureheadnumber - {\settrue\structureheaddoincrement - \settrue\structureheadtolist +\def\filterheadnumber + {\settrue\headdoincrement + \settrue\headtolist \ifx\currentproduct\empty % todo : filter from other toc (number, file, title) - % use : \currentstructureheadincrement as spec + % use : \currentheadincrement as spec \fi} -% \def\setstructureheadplacement -% {\setfalse\structureheadleaveempty -% \settrue \structureheaddoplace -% \setfalse\structureheadhidden -% \processaction -% [\structureheadparameter\c!placehead] -% [ \v!yes=>, -% \v!empty=>\settrue\structureheadleaveempty, -% \v!no=>\settrue\structureheadleaveempty\setfalse\structureheaddoplace, -% \v!hidden=>\settrue\structureheadleaveempty\setfalse\structureheaddoplace\settrue\structureheadhidden]} - -\setvalue{\??nh:\c!placehead:\v!yes}% - {\setfalse\structureheadleaveempty - \settrue \structureheaddoplace - \setfalse\structureheadhidden} - -\setvalue{\??nh:\c!placehead:\v!empty}% - {\settrue \structureheadleaveempty - \settrue \structureheaddoplace - \setfalse\structureheadhidden} - -\setvalue{\??nh:\c!placehead:\v!no}% - {\settrue \structureheadleaveempty - \setfalse\structureheaddoplace - \setfalse\structureheadhidden} - -\setvalue{\??nh:\c!placehead:\v!hidden}% - {\settrue \structureheadleaveempty - \setfalse\structureheaddoplace - \settrue \structureheadhidden} - -\def\setstructureheadplacement +\setvalue{\??headplace\v!yes}% + {\setfalse\headleaveempty + \settrue \headdoplace + \setfalse\headhidden} + +\setvalue{\??headplace\v!empty}% + {\settrue \headleaveempty + \settrue \headdoplace + \setfalse\headhidden} + +\setvalue{\??headplace\v!no}% + {\settrue \headleaveempty + \setfalse\headdoplace + \setfalse\headhidden} + +\setvalue{\??headplace\v!hidden}% + {\settrue \headleaveempty + \setfalse\headdoplace + \settrue \headhidden} + +\def\setheadplacement {\executeifdefined - {\??nh:\c!placehead:\structureheadparameter\c!placehead} - {\getvalue{\??nh:\c!placehead:\v!yes}}} + {\??headplace\headparameter\c!placehead} + {\getvalue{\??headplace\v!yes}}} + + +\ifdefined\setheaddisplay \else \let\setheaddisplay\relax \fi -\def\setstructureheaddisplay - {\doifelsevalue{\??nh:\structureheadparameter\c!alternative}\v!horizontal - {\setfalse\structureheadisdisplay} - {\settrue \structureheadisdisplay}} +\newmode\v!sectionnumber \def\dosettructureheadnumbercontent - {\setsystemmode \v!sectionnumber - \settrue\structureheadshownumber} + {\setsystemmode\v!sectionnumber + \settrue\headshownumber} % why ? \def\doresettructureheadnumbercontent {\resetsystemmode\v!sectionnumber - \setfalse\structureheadshownumber} - -\def\setstructureheadnumber - {\ifsectionnumber - \doifelse{\structureblockparameter\c!number}\v!yes % todo - {\doifelse{\structureheadparameter\c!number}\v!yes - {\settrue\structureheadshownumber} - {\setfalse\structureheadshownumber}} - {\setfalse\structureheadshownumber}% - \else - \setfalse\structureheadshownumber - \fi} + \setfalse\headshownumber} % why ? + +\def\setheadnumber + {\doifelse{\sectionblockparameter\c!number}\v!yes % todo + {\doifelse{\headparameter\c!number}\v!yes + {\settrue\headshownumber} + {\setfalse\headshownumber}} + {\setfalse\headshownumber}} -\unexpanded\def\thestructureheadsynchonization - {\pagetype[\currentstructureheadcoupling]% hm also number - \currentstructuresynchronize} +\unexpanded\def\theheadsynchonization + {\currentstructuresynchronize} -\unexpanded\def\setstructureheadmarking - {\normalexpanded{\noexpand\setmarking[\currentstructurehead]{\currentstructurelistnumber}}} +% BEWARE: \marking[section]{my text} does not work as we use list indices instead +% so we need a 'keep track of raw set option' (or maybe a funny internal prefix) -% \unexpanded\def\fullstructureheadnumber{\labeltexts{\structureheadparameter\c!label}{\structurenumber}} % todo -% \def\fullstructureheadtitle {\structurevariable{titledata.title}} % no catcode! -% \unexpanded\def\fullstructureheadtitle{\structureautocatcodedget{titledata.title}{\structureheadparameter\s!catcodes}} +\unexpanded\def\setheadmarking % li:: so that we can use \marking[section]{Taco needed this} + {\normalexpanded{\setmarking[\currenthead]{li::\currentstructurelistnumber}}} \let\deepstructurenumbercommand\relax \let\deepstructuretitlecommand \relax -\unexpanded\def\fullstructureheadnumber - {\edef\currentstructureheadlabeltag{\currentstructureblock\c!label}% +\unexpanded\def\fullheadnumber + {\edef\currentheadlabeltag{\currentsectionblock\c!label}% \dostarttagged\t!sectionnumber\empty \labeltexts - {\structureheadparameter\currentstructureheadlabeltag} + {\headparameter\currentheadlabeltag} {\ifx\deepstructurenumbercommand\relax \structurenumber \else @@ -462,7 +401,7 @@ \fi}% \dostoptagged} -\unexpanded\def\fullstructureheadtitle +\unexpanded\def\fullheadtitle {\dostarttagged\t!sectiontitle\empty \ifx\deepstructuretitlecommand\relax \structuretitle @@ -471,92 +410,94 @@ \fi \dostoptagged} -\let\currentstructurehead \empty -\let\currentstructureheadcoupling\empty -\let\currentstructureheadsection \empty -\let\currentstructureheadlevel \!!zerocount -\let\currentstructureheadcounter \!!zerocount +\let\currenthead \empty +\let\currentheadcoupling\empty +\let\currentheadsection \empty +\let\currentheadlevel \!!zerocount +\let\currentheadcounter \!!zerocount % here we could inherit as well but it's a bit complex -\def\doregisterstructurehead#1#2#3% name data userdata +\def\doregisterhead#1#2#3% name data userdata {\structurecomponent - %[\c!label={\structureheadparameter\c!label}, % why { } - [\c!label={\structureheadparameter{\currentstructureblock\c!label}}, - \c!incrementnumber=\ifconditional\structureheaddoincrement\v!yes\else\v!no\fi, % not that needed - \c!saveinlist=\ifconditional\structureheadtolist\v!yes\else\v!no\fi, - \c!level=\currentstructureheadlevel, + %[\c!label={\headparameter\c!label}, % why { } + [\c!label={\headparameter{\currentsectionblock\c!label}}, + \c!incrementnumber=\ifconditional\headdoincrement\v!yes\else\v!no\fi, % not that needed + \c!saveinlist=\ifconditional\headtolist\v!yes\else\v!no\fi, + \c!level=\currentheadlevel, \c!name=#1, - \c!number=\ifconditional\structureheaddoincrement\ifconditional\structureheadshownumber\v!yes\else\v!no\fi\else\v!no\fi, + \c!number=\ifconditional\headdoincrement\ifconditional\headshownumber\v!yes\else\v!no\fi\else\v!no\fi, \c!bookmark=, \c!marking=, \c!list=, - \c!expansion=\structureheadparameter\c!expansion, - \c!xmlsetup=\structureheadparameter\c!xmlsetup, - \s!catcodes=\structureheadparameter\s!catcodes, - \c!sectionresetset=\structureheadparameter\c!sectionresetset, - \c!sectionseparatorset=\structureheadparameter\c!sectionseparatorset, - \c!sectionconversionset=\structureheadparameter\c!sectionconversionset, - \c!sectionconversion=\structureheadparameter\c!conversion, % just for compatibility - \c!sectionstarter=\structureheadparameter\c!sectionstarter, - \c!sectionstopper=\structureheadparameter\c!sectionstopper, - \c!sectionset=\structureheadparameter\c!sectionset, - \c!sectionsegments=\structureheadparameter\c!sectionsegments, - \c!reference=\structureheadreference, - \c!referenceprefix=\structureheadreferenceprefix, + \c!expansion=\headparameter\c!expansion, + \c!xmlsetup=\headparameter\c!xmlsetup, + \s!catcodes=\headparameter\s!catcodes, + \c!sectionresetset=\headparameter\c!sectionresetset, + \c!sectionseparatorset=\headparameter\c!sectionseparatorset, + \c!sectionconversionset=\headparameter\c!sectionconversionset, + \c!sectionconversion=\headparameter\c!conversion, % just for compatibility + \c!sectionstarter=\headparameter\c!sectionstarter, + \c!sectionstopper=\headparameter\c!sectionstopper, + \c!sectionset=\headparameter\c!sectionset, + \c!sectionsegments=\headparameter\c!sectionsegments, + \c!reference=\headparameter\c!reference, + \c!referenceprefix=\headparameter\c!referenceprefix, \c!backreference=, \c!command=, #2]% [#3]% \reportcurrentstructure} -\unexpanded\def\placeheadtext {\dosingleempty\doplaceheadtext } % use with care -\unexpanded\def\placeheadnumber{\dosingleempty\doplaceheadnumber} % use with care +\unexpanded\def\placeheadtext {\dosingleempty\strc_sections_place_head_text } % use with care +\unexpanded\def\placeheadnumber{\dosingleempty\strc_sections_place_head_number} % use with care \ifdefined\setupheadcomponentfont \else \unexpanded\def\setupheadcomponentfont#1#2% {\dontconvertfont - \dosetstructureheadattributes\c!style\c!color - \dosetstructureheadattributes#1#2% + \useheadstyleandcolor\c!style\c!color + \useheadstyleandcolor#1#2% \setupinterlinespace} \fi -\def\doplaceheadtext[#1]% +\def\strc_sections_place_head_text[#1]% {\dontleavehmode \begingroup - \edef\currentstructurehead{#1}% + \edef\currenthead{#1}% \setupheadcomponentfont\c!textstyle\c!textcolor \relax - \getspecificstructuretitle{\thenamedstructureheadlevel{#1}}% + \getspecificstructuretitle{\thenamedheadlevel{#1}}% \endgraf \endgroup} -\def\doplaceheadnumber[#1]% +\def\strc_sections_place_head_number[#1]% {\dontleavehmode \begingroup - \edef\currentstructurehead{#1}% + \edef\currenthead{#1}% \setupheadcomponentfont\c!numberstyle\c!numbercolor \relax - \getfullstructurenumber{\thenamedstructureheadlevel{#1}}% + \getfullstructurenumber{\thenamedheadlevel{#1}}% \endgraf \endgroup} -\ifdefined \else \let\presetnumberheadalternative\relax \fi +\ifdefined\presetnumberheadalternative \else \let\presetnumberheadalternative\relax \fi +\ifdefined\setautostructurelevel \else \let\setautostructurelevel \relax \fi +\ifdefined\triggerautostructurelevel \else \let\triggerautostructurelevel \relax \fi -\def\dohandlestructurehead#1#2#3% name data userdata (we can move #1 to the caller) - {\xdef\currentstructurehead {#1}% - \xdef\currentstructureheadcoupling{\structuresectionheadcoupling\currentstructurehead}% - \xdef\currentstructureheadsection {\structuresectionheadsection \currentstructureheadcoupling}% - \xdef\currentstructureheadlevel {\structuresectionlevel \currentstructureheadsection}% - %writestatus\m!system{setup: \currentstructurehead,\currentstructureheadcoupling,\currentstructureheadsection,\currentstructureheadlevel}% +\def\dohandlehead#1#2#3% name data userdata (we can move #1 to the caller) + {\xdef\currenthead {#1}% + \xdef\currentheadcoupling{\sectionheadcoupling\currenthead}% + \xdef\currentheadsection {\sectionheadsection \currentheadcoupling}% + \xdef\currentheadlevel {\sectionlevel \currentheadsection}% + %writestatus\m!system{setup: \currenthead,\currentheadcoupling,\currentheadsection,\currentheadlevel}% % - \setstructureheadreference % does not do much currently - \setstructureheadincrement - \setstructureheadplacement - \setstructureheaddisplay - \setstructureheadnumber + \setautostructurelevel + \setheadincrement + \setheadplacement + \setheaddisplay + \setheadnumber % \unexpanded\def\\{\space}% \flushingcolumnfloatsfalse @@ -565,69 +506,69 @@ % % we might remove the lower level % - % not here, after optional \page: \doregisterstructurehead\currentstructurehead{#2}{#3}% + % not here, after optional \page: \doregisterhead\currenthead{#2}{#3}% % -% \xdef\currentstructureheadcounter{\currentstructurecounter}% lua call +% \xdef\currentheadcounter{\currentsectioncountervalue}% lua call % % \currentstructuresynchronize % will move % - \edef\numberheaddistance {\structureheadparameter\c!distance }% compatibility - \edef\numberheadalternative{\structureheadparameter\c!alternative}% compatibility + \edef\numberheaddistance {\headparameter\c!distance }% compatibility + \edef\numberheadalternative{\headparameter\c!alternative}% compatibility \presetnumberheadalternative % - \let\getstructureheadnumber\empty - \let\getstructureheadtitle \empty - \let\getstructureheadsyncs \empty - \ifconditional\structureheaddoincrement - \ifconditional\structureheaddoplace - \dostructureheadspacingbeforeyes - \doregisterstructurehead\currentstructurehead{#2}{#3}% after optional \page - \let\getstructureheadsyncs\thestructureheadsynchonization - \let\getstructureheadtitle\fullstructureheadtitle - \ifconditional\structureheadshownumber - \let\getstructureheadnumber\fullstructureheadnumber - \placestructureheadnumbertext + \let\getheadnumber\empty + \let\getheadtitle \empty + \let\getheadsyncs \empty + \ifconditional\headdoincrement + \ifconditional\headdoplace + \doheadspacingbeforeyes + \doregisterhead\currenthead{#2}{#3}% after optional \page + \let\getheadsyncs\theheadsynchonization + \let\getheadtitle\fullheadtitle + \ifconditional\headshownumber + \let\getheadnumber\fullheadnumber + \placecurrentheadnumbertext \else - \placestructureheadtext + \placecurrentheadtext \fi - \dostructureheadspacingafteryes - \else\ifconditional\structureheadhidden - \doregisterstructurehead\currentstructurehead{#2}{#3}% after optional \page - \let\getstructureheadsyncs\thestructureheadsynchonization - \placestructureheadhidden % only something when tracing + \doheadspacingafteryes + \else\ifconditional\headhidden + \doregisterhead\currenthead{#2}{#3}% after optional \page + \let\getheadsyncs\theheadsynchonization + \placecurrentheadhidden % only something when tracing \else - \dostructureheadspacingbeforenop % toegevoegd ivm subpaginanr / tug sheets - \doregisterstructurehead\currentstructurehead{#2}{#3}% after optional \page - \let\getstructureheadsyncs\thestructureheadsynchonization - \placestructureheadempty % just flush 'm - \dostructureheadspacingafternop + \doheadspacingbeforenop % toegevoegd ivm subpaginanr / tug sheets + \doregisterhead\currenthead{#2}{#3}% after optional \page + \let\getheadsyncs\theheadsynchonization + \placecurrentheadempty % just flush 'm + \doheadspacingafternop \fi\fi \else - \ifconditional\structureheaddoplace - \dostructureheadspacingbeforeyes - \doregisterstructurehead\currentstructurehead{#2}{#3}% after optional \page - \let\getstructureheadsyncs\thestructureheadsynchonization - \let\getstructureheadtitle\fullstructureheadtitle - \placestructureheadtext - \dostructureheadspacingafteryes - \else\ifconditional\structureheadhidden - \doregisterstructurehead\currentstructurehead{#2}{#3}% after optional \page - \let\getstructureheadsyncs\thestructureheadsynchonization - \placestructureheadhidden % only something when tracing + \ifconditional\headdoplace + \doheadspacingbeforeyes + \doregisterhead\currenthead{#2}{#3}% after optional \page + \let\getheadsyncs\theheadsynchonization + \let\getheadtitle\fullheadtitle + \placecurrentheadtext + \doheadspacingafteryes + \else\ifconditional\headhidden + \doregisterhead\currenthead{#2}{#3}% after optional \page + \let\getheadsyncs\theheadsynchonization + \placecurrentheadhidden % only something when tracing \else % do nothing / should be vbox to 0pt - \dostructureheadspacingbeforenop - \doregisterstructurehead\currentstructurehead{#2}{#3}% after optional \page - \let\getstructureheadsyncs\thestructureheadsynchonization - \placestructureheadempty % just flush 'm - \dostructureheadspacingafternop + \doheadspacingbeforenop + \doregisterhead\currenthead{#2}{#3}% after optional \page + \let\getheadsyncs\theheadsynchonization + \placecurrentheadempty % just flush 'm + \doheadspacingafternop \fi\fi \fi \flushingcolumnfloatstrue \setfalse\ignorehandlepagebreak % ignorespaces prevents spaces creeping in when after=\dontleavehmode \dostarttagged\t!sectioncontent\empty - \ifconditional\structureheadisdisplay % \ifdisplaysectionhead + \ifconditional\headisdisplay % \ifdisplaysectionhead \ignorespaces \else \expandafter\GotoPar @@ -635,40 +576,48 @@ % typesetting -\unexpanded\def\placestructureheadnumbertext % dummy, will be overloaded - {\setstructureheadmarking - \getstructureheadnumber/\getstructureheadtitle - \getstructureheadsyncs} +\unexpanded\def\placecurrentheadnumbertext + {\setheadmarking + \getheadnumber/\getheadtitle + \getheadsyncs} -\unexpanded\def\placestructureheadtext % dummy, will be overloaded - {\setstructureheadmarking - \getstructureheadtitle - \getstructureheadsyncs} +\unexpanded\def\placecurrentheadtext + {\setheadmarking + \getheadtitle + \getheadsyncs} -\unexpanded\def\placestructureheadempty % dummy, will be overloaded - {\setstructureheadmarking - \getstructureheadsyncs} +\unexpanded\def\placecurrentheadempty + {\setheadmarking + \getheadsyncs} -\unexpanded\def\placestructureheadhidden - {\setxvalue{\currentstructurehead:sync}% - {\noexpand\setgvalue{\currentstructurehead:sync}{}% - \noexpand\pagetype[\currentstructureheadcoupling]% hm also number - \noexpand\setmarking[\currentstructureheadcoupling]{\currentstructurelistnumber}% - \currentstructuresynchronize}} +\installcorenamespace{hiddenheadattr} +\installcorenamespace{hiddenheadsync} -\def\synchronizestructurehead#1% - {\getvalue{#1:sync}} +% todo: when in the page builder we need to resolve the marking immediately +% because otherwise we have an async -\unexpanded\def\placerawheaddata [#1]{\synchronizestructurehead {#1}} -\unexpanded\def\placerawheadtext [#1]{\getspecificstructuretitle{\thenamedstructureheadlevel{#1}}} -\unexpanded\def\placerawheadnumber[#1]{\getfullstructurenumber {\thenamedstructureheadlevel{#1}}} +\unexpanded\def\placecurrentheadhidden % maybe trialtypesetting check + {\setxvalue{\??hiddenheadattr\currenthead}% + {\headreferenceattributes}% can be used when making a box + \setxvalue{\??hiddenheadsync\currenthead}% + {\noexpand\letgvalue{\??hiddenheadsync\currenthead}\relax + \noexpand\setmarking[\currentheadcoupling]{li::\currentstructurelistnumber}% + \hbox\headreferenceattributes{}% otherwise no destination ... maybe tag ref as hidden and fall back on page reference + \currentstructuresynchronize}} % and it's a node anyway + +\def\synchronizehead #1{\csname\??hiddenheadsync#1\endcsname} +\def\theheadreferenceattributes#1{\csname\??hiddenheadattr#1\endcsname} + +\unexpanded\def\placerawheaddata [#1]{\synchronizehead{#1}} +\unexpanded\def\placerawheadtext [#1]{\getspecificstructuretitle{\thenamedheadlevel{#1}}} +\unexpanded\def\placerawheadnumber[#1]{\getfullstructurenumber{\thenamedheadlevel{#1}}} % \setuphead[chapter][placehead=hidden] % \chapter {test} % -% %(\synchronizestructurehead{chapter}) % \getstructureheadsyncs -% %(\getfullstructurenumber{\thenamedstructureheadlevel{chapter}}) -% %(\getspecificstructuretitle{\thenamedstructureheadlevel{chapter}}) +% %(\synchronizehead{chapter}) % \getheadsyncs +% %(\getfullstructurenumber{\thenamedheadlevel{chapter}}) +% %(\getspecificstructuretitle{\thenamedheadlevel{chapter}}) % % (\placerawheaddata [chapter]) % (\placerawheadnumber[chapter]) @@ -679,55 +628,47 @@ \newcount\precedingstructurelevel \precedingstructurelevel\plusone \newconditional\ignorehandlepagebreak -\def\dostructureheadspacingbeforeyes - {\docheckstructureheadbefore - \dohandlestructureheadpagebreakyes - \structureheadparameter\c!inbetween - \dostarttagged\t!section\currentstructurehead} - -\def\dostructureheadspacingbeforenop - {\docheckstructureheadbefore - \dohandlestructureheadpagebreaknop - \structureheadparameter\c!inbetween - \dostarttagged\currentstructurehead\empty} - -% \def\emptystructureheadcorrection -% {\ifconditional\structureheadleaveempty % inlined \emptyheadcorrection (with after=\blank) -% \vskip-\lineheight -% \dosomebreak\nobreak % \penalty10000 in vspacing -% \kern\zeropoint -% \prevdepth\strutdepth -% \fi} - -\def\emptystructureheadcorrection - {\ifconditional\structureheadleaveempty % inlined \emptyheadcorrection (with after=\blank) +\def\doheadspacingbeforeyes + {\docheckheadbefore + \dohandleheadpagebreakyes + \headparameter\c!inbetween + \dostarttagged\t!section\currenthead} + +\def\doheadspacingbeforenop + {\docheckheadbefore + \dohandleheadpagebreaknop + \headparameter\c!inbetween + \dostarttagged\currenthead\empty} + +\def\emptyheadcorrection + {\ifconditional\headleaveempty % inlined \emptyheadcorrection (with after=\blank) \penalty10000 % first ... we need to adapt this all to vspacing \vskip-\lineheight \kern\zeropoint \prevdepth\strutdepth \fi} -\def\dostructureheadspacingafteryes - {\ifconditional\structureheadisdisplay +\def\doheadspacingafteryes + {\ifconditional\headisdisplay \dosomebreak\nobreak % needs to be adapted to vspacing - \emptystructureheadcorrection - \structureheadparameter\c!after + \emptyheadcorrection + \headparameter\c!after \fi} -\def\dostructureheadspacingafternop +\def\doheadspacingafternop {} -\newsignal\continuousstructureheadsignal +\newsignal\continuousheadsignal -\def\docheckstructureheadbefore#1% +\def\docheckheadbefore#1% {\ifhmode \scratchcounter\lastpenalty\unpenalty % no beauty in this - \ifdim\lastskip=\continuousstructureheadsignal + \ifdim\lastskip=\continuousheadsignal % no page break \ifconditional\ignorehandlepagebreak \setfalse\ignorehandlepagebreak \else - \global\precedingstructurelevel\currentstructureheadlevel + \global\precedingstructurelevel\currentheadlevel \nobreak \fi \global\settrue\continuoussectionhead @@ -741,125 +682,78 @@ #1% \fi} -\def\dodocheckstructureheadlayout#1#2% +\def\dodocheckheadlayout#1#2% {\doifelselayouttextline{#1} - {\doifsomething{\structureheadparameter#2}{\expanded{\setuplayouttext[#1][\c!state=\structureheadparameter#2]}}} + {\doifsomething{\headparameter#2}{\expanded{\setuplayouttext[#1][\c!state=\headparameter#2]}}} \donothing} -\setvalue{\??nh:\??mk:n:\v!page }{} -\setvalue{\??nh:\??mk:n:\v!reset}{\resetcurrentstructuremarks} -\setvalue{\??nh:\??mk:y:\v!page }{} % to be checked: {\resetcurrentstructuremarks} -\setvalue{\??nh:\??mk:y:\v!reset}{\resetcurrentstructuremarks} - -\def\docheckstructureheadlayout - {\doifelsenothing{\structureheadparameter\c!page} - {\getvalue{\??nh:\??mk:n:\structureheadparameter\c!marking}} - {\page[\structureheadparameter\c!page]% - \getvalue{\??nh:\??mk:y:\structureheadparameter\c!marking}% - \dodocheckstructureheadlayout\v!header\c!header - \dodocheckstructureheadlayout\v!text \c!text - \dodocheckstructureheadlayout\v!footer\c!footer}} - -\def\currentstructurecounter {\ctxlua{structures.sections.depthnumber(\thenamedstructureheadlevel\currentstructurehead)}} -\def\previousstructurecounter{\ctxlua{structures.sections.depthnumber(\thenamedstructureheadlevel\currentstructurehead-1)}} - -\def\dohandlestructureheadpagebreaknop - {\doifelse{\structureheadparameter\c!continue}\v!yes - {\ifnum\previousstructurecounter=\zerocount - \docheckstructureheadlayout - \else\ifnum\currentstructurecounter>\zerocount - \docheckstructureheadlayout +\setvalue{\??headmarknop\v!page }{} +\setvalue{\??headmarknop\v!reset}{\resetcurrentstructuremarks} +\setvalue{\??headmarkyes\v!page }{} % to be checked: {\resetcurrentstructuremarks} +\setvalue{\??headmarkyes\v!reset}{\resetcurrentstructuremarks} + +\def\docheckheadlayout + {\doifelsenothing{\headparameter\c!page} + {\getvalue{\??headmarknop\headparameter\c!marking}} + {\page[\headparameter\c!page]% + \getvalue{\??headmarkyes\headparameter\c!marking}% + \dodocheckheadlayout\v!header\c!header + \dodocheckheadlayout\v!text \c!text + \dodocheckheadlayout\v!footer\c!footer}} + +\def\currentsectioncountervalue {\ctxlua{structures.sections.depthnumber(\thenamedheadlevel\currenthead)}} +\def\previoussectioncountervalue{\ctxlua{structures.sections.depthnumber(\thenamedheadlevel\currenthead-1)}} + +\def\dohandleheadpagebreaknop + {\doifelse{\headparameter\c!continue}\v!yes + {\ifnum\previoussectioncountervalue=\zerocount + \docheckheadlayout + \else\ifnum\currentsectioncountervalue>\zerocount + \docheckheadlayout \fi\fi}% - {\docheckstructureheadlayout}} + {\docheckheadlayout}} -\def\dohandlestructureheadpagebreakyes - {%[[\currentstructurehead @\thenamedstructureheadlevel\currentstructurehead/prev:\previousstructurecounter/curr:\currentstructurecounter]] +\def\dohandleheadpagebreakyes + {%[[\currenthead @\thenamedheadlevel\currenthead/prev:\previoussectioncountervalue/curr:\currentsectioncountervalue]] \ifconditional\ignorehandlepagebreak \setfalse\ignorehandlepagebreak \else - \ifnum\lastpenalty>\zerocount +% \ifnum\lastpenalty>\zerocount % \global\pagebreakdisabledtrue - \fi +% \fi % beware, these numbers are not yet know here - \doifelse{\structureheadparameter\c!continue}\v!yes - {\ifnum\previousstructurecounter=\zerocount - \docheckstructureheadlayout - \else\ifnum\currentstructurecounter>\zerocount - \docheckstructureheadlayout + \doifelse{\headparameter\c!continue}\v!yes + {\ifnum\previoussectioncountervalue=\zerocount + \docheckheadlayout + \else\ifnum\currentsectioncountervalue>\zerocount + \docheckheadlayout \fi\fi}% - {\docheckstructureheadlayout}% - \doifnot{\structureheadparameter\c!aligntitle}\v!float\flushsidefloats - \structureheadparameter\c!before + {\docheckheadlayout}% + \doifnot{\headparameter\c!aligntitle}\v!float\page_otr_command_flush_side_floats + \headparameter\c!before \relax % \ifpagebreakdisabled % \global\pagebreakdisabledfalse % \else -% \dopreventbreakafterstructureheadauto % not ok as it binds the prev par +% \dopreventbreakafterheadauto % not ok as it binds the prev par % \fi - \doif{\structureheadparameter\c!aligntitle}\v!float\indent - \global\precedingstructurelevel\currentstructureheadlevel + \doif{\headparameter\c!aligntitle}\v!float\indent + \global\precedingstructurelevel\currentheadlevel \fi} -% the next one was: \somebreakmethod - - -% 0 = nothing, 1 = weighted, 2 = strict, 3 = vspacing +\settrue\autoheadbreak % todo: \vspacing[category:8] == keep_together -\setnewconstant\somestructureheadbreakmethod\plusthree - -% \def\dopreventbreakafterstructureheadauto % used after \c!before -% {\ifcase\somestructureheadbreakmethod -% % 0 = nothing -% \or -% % 1 = old weighted version -% \ifnum\currentstructureheadlevel>\precedingstructurelevel -% \dosomebreak{\penalty\numexpr20000+500*\currentstructureheadlevel\relax}% -% \else -% \dosomebreak\allowbreak % brr -% \fi -% \or -% % 2 = strict version -% \dosomebreak{\penalty\maxdimen}% -% \or -% % 3 = vspacing -% \vspacing[\v!samepage]% if preceded by ! then a loop -% \else -% % nothing -% \fi} -% -% \def\dopreventbreakafterstructureheadspec#1% see enumerations etc -% {\ifcase\somestructureheadbreakmethod -% % 0 = nothing -% \or -% % 1 = old weighted version -% \dosomebreak{\penalty\numexpr20000+500*(\currentstructureheadlevel+#1)\relax}% -% \or -% % 2 = strict version -% \dosomebreak{\penalty\maxdimen}% -% \or -% % 3 = vspacing -% \vspacing[\v!samepage]% -% \else -% % nothing -% \fi} -% -% todo: \vspacing[category:8] == keep_together - -\def\dopreventbreakafterstructureheadauto % used after \c!before - {\ifcase\somestructureheadbreakmethod - % 0 = nothing - \else - \vspacing[\v!samepage-\currentstructureheadlevel]% +\def\dopreventbreakafterheadauto % used after \c!before + {\ifconditional\autoheadbreak + \vspacing[\v!samepage-\currentheadlevel]% \fi} -\def\dopreventbreakafterstructureheadspec#1% see enumerations etc - {\ifcase\somestructureheadbreakmethod - % 0 = nothing - \else - \vspacing[\v!samepage-\the\numexpr\currentstructureheadlevel+1\relax]% todo #1 +\def\dopreventbreakafterheadspec#1% see enumerations etc + {\ifconditional\autoheadbreak + \vspacing[\v!samepage-\the\numexpr\currentheadlevel+1\relax]% todo #1 \fi} -\def\dohandlepagebreakX{\dopreventbreakafterstructureheadspec} % no \let so we can redefind +\def\dohandlepagebreakX{\dopreventbreakafterheadspec} % no \let so we can redefine % we do support negative numbers but it can have side effects that we won't % catch @@ -867,65 +761,76 @@ % \chapter{some} \setupheadnumber[chapter][3] \chapter{more} % \setupheadnumber[section][8] \section{b} \section{c} \setupheadnumber[section][-1] \section{d} -% \def\thecurrentstructureheadlevel#1% -% {\getcurrentstructurelevel{#1}} - -\def\thenamedstructureheadlevel#1% - {\structuresectionlevel{\structuresectionheadsection{\structuresectionheadcoupling{#1}}}} +\def\thenamedheadlevel#1% + {\sectionlevel{\sectionheadsection{\sectionheadcoupling{#1}}}} \unexpanded\def\setupheadnumber {\dodoubleargument\dosetupheadnumber} \def\dosetupheadnumber[#1][#2]% todo: reset if at other level - {\setstructurenumber{\thenamedstructureheadlevel{#1}}{#2}} + {\setstructurenumber{\thenamedheadlevel{#1}}{#2}} -\def\currentstructureheadnumber{0} % ==> \currentheadnumber +\def\currentheadnumber{0} % ==> \currentheadnumber \unexpanded\def\determineheadnumber[#1]% - {\xdef\currentstructureheadnumber{\getstructurenumber{\thenamedstructureheadlevel{#1}}}} + {\xdef\currentheadnumber{\getstructurenumber{\thenamedheadlevel{#1}}}} % The previous macro is been replaced by the expandable: -\def\namedheadnumber #1{\getstructurenumber {\thenamedstructureheadlevel{#1}}} -\def\somenamedheadnumber#1#2{\getsomestructurenumber{\thenamedstructureheadlevel{#1}}{#2}} +\def\namedheadnumber #1{\getstructurenumber {\thenamedheadlevel{#1}}} +\def\somenamedheadnumber#1#2{\getsomestructurenumber{\thenamedheadlevel{#1}}{#2}} -\unexpanded\def\structureheadnumber - {\dodoubleempty\dostructureheadnumber} +\unexpanded\def\headnumber + {\dodoubleempty\doheadnumber} -\def\dostructureheadnumber[#1][#2]% simple case is just a number - {\getsomefullstructurenumber{\iffirstargument\thenamedstructureheadlevel{#1}\fi}{#2}} +\def\doheadnumber[#1][#2]% simple case is just a number + {\getsomefullstructurenumber{\iffirstargument\thenamedheadlevel{#1}\fi}{#2}} -\def\somestructureheadnumber - {\dodoubleempty\dosomestructureheadnumber} +\def\someheadnumber + {\dodoubleempty\dosomeheadnumber} -\def\dosomestructureheadnumber[#1][#2]% +\def\dosomeheadnumber[#1][#2]% {\dontleavehmode \begingroup - \edef\currentstructurehead{#1}% - \getsomefullstructurenumber{\thenamedstructureheadlevel{#1}}{#2}% + \edef\currenthead{#1}% + \getsomefullstructurenumber{\thenamedheadlevel{#1}}{#2}% \endgroup} -% compatibility code (after all, we might offer different structure handlers as well -% but we might as well remove the 'structure' substring at some point (we needed it -% in order to test the old and new methods alongside) - -\let\definesectionblock \definestructureblock -\let\definesection \definestructuresection -\let\setupsection \setupstructuresection -\let\setupheads \setupstructureheads -\let\definehead \definestructurehead -\let\setuphead \setupstructurehead -\let\headnumber \structureheadnumber -\let\setupsectionblock \setupstructureblock - \let\sectioncountervalue\structurevalue -\def\currentheadnumber {\currentstructureheadnumber} -\def\currentheadtext {obsolete, use marks} +\def\currentheadtext{obsolete, use marks} % list references, will be redone in lua when we need it \let\startlistreferences\relax \let\stoplistreferences \relax +% experimental + +\newconditional\c_strc_sections_auto_levels + +\appendtoks + \settrue\c_strc_sections_auto_levels +\to \everyenableelements + +\def\setautostructurelevel + {\ifconditional\c_strc_sections_auto_levels + \ctxcommand{autonextstructurelevel(\number\currentheadlevel)}% + \global\setfalse\c_strc_sections_auto_levels + \fi} + +\def\triggerautostructurelevel + {\global\settrue\c_strc_sections_auto_levels} + +\def\finalizeautostructurelevels + {\ctxcommand{autofinishstructurelevels()}} + +\unexpanded\def\finalizeautostructurelevel + {\dostoptagged + \dostoptagged} + +\appendtoks + \finalizeautostructurelevels +\to \everystoptext + \protect \endinput |