diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/typo-mar.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/typo-mar.mkiv | 335 |
1 files changed, 205 insertions, 130 deletions
diff --git a/Master/texmf-dist/tex/context/base/typo-mar.mkiv b/Master/texmf-dist/tex/context/base/typo-mar.mkiv index aba3ef95a74..a393fc25098 100644 --- a/Master/texmf-dist/tex/context/base/typo-mar.mkiv +++ b/Master/texmf-dist/tex/context/base/typo-mar.mkiv @@ -7,7 +7,7 @@ %D subtitle=Margindata, %D author=Hans Hagen, %D date=\currentdate, -%D copyright=\PRAGMA] +%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 @@ -99,11 +99,11 @@ %D argument concerns the data, the second the framed. Not sharing the setup is %D on purpose: location, offset, alignment and other parameters might clash. -\def\??mc{@@mc} % margincategory -\def\??mf{@@mf} % marginframed +\installcorenamespace{margindata} +\installcorenamespace{marginframed} -\installcommandhandler\??mc{margindata}\??mc -\installcommandhandler\??mf{marginframed}\??mf +\installcommandhandler \??margindata {margindata} \??margindata +\installframedcommandhandler \??marginframed {marginframed} \??marginframed \setupmargindata [\c!location=\v!left, @@ -119,6 +119,8 @@ \c!width=, % \c!stack=, \c!line=0, + \c!anchor=\v!text, + \c!bottomspace=\strutdepth, % slack used for keeptogether \c!dy=\zeropoint, \c!distance=\zeropoint, \c!hoffset=\zeropoint, @@ -139,95 +141,166 @@ \newconditional\inhibitmargindata % This one is used at the Lua end! \newtoks \everymargindatacontent % Later on we will set this one. -\unexpanded\def\margindata[#name]% - {\setfalse\inhibitmargindata % flushing afterwards - \begingroup - %\settrue\inhibitmargindata % no flushing in here - \def\currentmargindata{#name}% - \dodoubleempty\domargindata} - \appendtoks \settrue\inhibitmargindata \to \everyforgetall -% option test -> ruled - \appendtoks \forgetall \tf \deactivatecolor \to \everymargindatacontent -\unexpanded\def\domargindata[#dataparameters][#textparameters]#content% +% trialtypesetting: no need for margin stuff while trialing as +% is has no dimensions + +\definesystemconstant{margintext} + +\newcount\nofmargintexts + +\definepagestate[\s!margintext] + +\unexpanded\def\typo_margins_data_synchronize + {\doforcedtrackpagestate\s!margintext\nofmargintexts % includes increment + \docheckpagestate\s!margintext\nofmargintexts + %\doifrightpagestateelse\s!margintext\nofmargintexts\relax\relax + \realpageno\realpagestateno + \swapmargins} + +\unexpanded\def\margindata + {\iftrialtypesetting + \expandafter\typo_margins_data_nop + \else + \expandafter\typo_margins_data_yes + \fi} + +\def\typo_margins_data_nop[#name]% + {\dodoubleempty\typo_margins_data_nop_indeed} + +\def\typo_margins_data_yes[#name]% + {\setfalse\inhibitmargindata % flushing afterwards + \begingroup + %\settrue\inhibitmargindata % no flushing in here + \def\currentmargindata{#name}% + \let\currentmarginframed\currentmargindata + \dodoubleempty\typo_margins_data_yes_indeed} + +\unexpanded\def\typo_margins_data_nop_indeed[#dataparameters][#textparameters]#content% + {} + +\unexpanded\def\typo_margins_data_yes_indeed[#dataparameters][#textparameters]#content% {\iffirstargument - \setupmargindata[\currentmargindata][#dataparameters]% + \setupcurrentmargindata[#dataparameters]% \fi - \edef\currentmargindatastrut{\margindataparameter\c!strut}% - \the\everymargindatacontent - \dostarttagged\t!margintext\currentmargindata - \ifcsname\??mf\currentmargindata\s!parent\endcsname - \setbox\nextbox\hbox\bgroup - \the\everymargindatacontent - \dosetmargindataattributes\c!style\c!color - \localframedwithsettings[\??mf\currentmargindata][\c!location=\v!normal,#textparameters]\bgroup - \ifx\currentmargindatastrut\empty \else - \dosetupstrut[\currentmargindatastrut]% - \fi - \begstrut\margindataparameter\c!command{#content}\endstrut - \egroup - \egroup - \edef\currentmarginfirstheight{\number\dimexpr\framedfirstheight}% - \else - \edef\currentmargindatawidth{\margindataparameter\c!width}% - \ifx\currentmargindatawidth\empty - \setbox\nextbox\hbox\bgroup + \doifelsenothing{#content}\donefalse\donetrue + \ifdone + \edef\currentmarginreference{\margindataparameter\c!reference}% + \ifx\currentmarginreference\empty \else + \strc_references_set_page_only_destination_box_attribute\currentmarginreference\currentmarginreference + \fi + \edef\currentmargindatastrut{\margindataparameter\c!strut}% + \dostarttagged\t!margintext\currentmargindata + \ifcsname\currentmarginframedhash\s!parent\endcsname + \setbox\nextbox\hbox \currentmarginreference \bgroup \the\everymargindatacontent - \dosetmargindataattributes\c!style\c!color - \ifx\currentmargindatastrut\empty \else - \dosetupstrut[\currentmargindatastrut]% - \fi - \begstrut\margindataparameter\c!command{#content}\endstrut + \usemargindatastyleandcolor\c!style\c!color + \setupcurrentmarginframed[\c!location=\v!normal,#textparameters]% +\typo_margins_data_synchronize + \inheritedmarginframedframed\bgroup + \ifx\currentmargindatastrut\empty \else + \synchronizestrut\currentmargindatastrut + \fi + \begstrut + \strc_references_flush_destination_nodes + \margindataparameter\c!command{#content}% + \endstrut + \egroup \egroup - \let\currentmarginfirstheight\empty + \edef\currentmarginfirstheight{\number\dimexpr\framedfirstheight}% \else - \dosetraggedcommand{\margindataparameter\c!align}% - \setbox\nextbox\hbox \bgroup\vtop \bgroup % hbox is needed - \the\everymargindatacontent - \dosetmargindataattributes\c!style\c!color - \hsize\currentmargindatawidth - \raggedcommand - \ifx\currentmargindatastrut\empty \else - \dosetupstrut[\currentmargindatastrut]% - \fi - \begstrut\margindataparameter\c!command{#content}\endstrut - \egroup \egroup - \edef\currentmarginfirstheight{true}% + \edef\currentmargindatawidth{\margindataparameter\c!width}% + \ifx\currentmargindatawidth\empty + \setbox\nextbox\hbox \currentmarginreference \bgroup +\typo_margins_data_synchronize + \the\everymargindatacontent + \usemargindatastyleandcolor\c!style\c!color + \ifx\currentmargindatastrut\empty \else + \synchronizestrut\currentmargindatastrut + \fi + \begstrut + \strc_references_flush_destination_nodes + \margindataparameter\c!command{#content}% + \endstrut + \egroup + \let\currentmarginfirstheight\empty + \else + \setbox\nextbox\hbox \currentmarginreference \bgroup +\typo_margins_data_synchronize + \dosetraggedcommand{\margindataparameter\c!align}% + \vtop \bgroup + \the\everymargindatacontent + \usemargindatastyleandcolor\c!style\c!color + \hsize\currentmargindatawidth + \raggedcommand + \ifx\currentmargindatastrut\empty \else + \dosetupstrut[\currentmargindatastrut]% + \fi + \begstrut + \strc_references_flush_destination_nodes + \margindataparameter\c!command{#content}% + \endstrut + \egroup + \egroup + \edef\currentmarginfirstheight{true}% + \fi \fi + \dostoptagged \fi - \dostoptagged - \ctxlua{typesetters.margins.save{ - \c!location = "\margindataparameter\c!location", - \c!method = "\margindataparameter\c!method", - \c!category = "\margindataparameter\c!category", - \c!name = "\margindataparameter\c!name", - \c!margin = "\margindataparameter\c!margin", % local normal margin edge - \c!distance = \number\dimexpr\margindataparameter\c!distance, - \c!hoffset = \number\dimexpr\margindataparameter\c!hoffset, - \c!voffset = \number\dimexpr\margindataparameter\c!voffset, - \c!dy = \number\dimexpr\margindataparameter\c!dy, - \ifx\currentmarginfirstheight\empty \else - baseline = \currentmarginfirstheight, - \fi - threshold = \number\dimexpr\margindataparameter\c!threshold, % will change - \ifhmode - inline = true, + \ifdone + \anch_positions_initialize % we use positions at the lua end + \ctxlua{typesetters.margins.save{ + location = "\margindataparameter\c!location", + method = "\margindataparameter\c!method", + category = "\margindataparameter\c!category", + name = "\margindataparameter\c!name", + margin = "\margindataparameter\c!margin", % local normal margin edge + distance = \number\dimexpr\margindataparameter\c!distance, + hoffset = \number\dimexpr\margindataparameter\c!hoffset, + voffset = \number\dimexpr\margindataparameter\c!voffset, + dy = \number\dimexpr\margindataparameter\c!dy, + bottomspace = \number\dimexpr\margindataparameter\c!bottomspace, + \ifx\currentmarginfirstheight\empty \else + baseline = \currentmarginfirstheight, + \fi + threshold = \number\dimexpr\margindataparameter\c!threshold, % overlap related, will change + \ifhmode + inline = true, + \fi + anchor = "\margindataparameter\c!anchor", + % + % we're not in forgetall + % + % \ifzeropt\leftskip \else + % leftskip = \number\leftskip, + % \fi + % \ifzeropt\leftskip \else + % rightskip = \number\rightskip, + % \fi + scope = "\margindataparameter\c!scope", + align = "\margindataparameter\c!align", + line = \number\margindataparameter\c!line, + stack = "\margindataparameter\c!stack", + number = \number\nextbox, + }}% + \else + \ctxlua{typesetters.margins.save{ + location = "\margindataparameter\c!location", + method = "\margindataparameter\c!method", + category = "\margindataparameter\c!category", + name = "\margindataparameter\c!name", + scope = "\margindataparameter\c!scope", + }}% \fi - \c!scope = "\margindataparameter\c!scope", - \c!align = "\margindataparameter\c!align", - \c!line = "\margindataparameter\c!line", - \c!stack = "\margindataparameter\c!stack", - \c!number = \number\nextbox - }}% \endgroup} %D Downward compatible hack: @@ -241,23 +314,25 @@ %D Another one: -% \letvalue{\??mc->\v!left }\v!right -% \letvalue{\??mc->\v!right }\v!left -% \letvalue{\??mc->\v!inner }\v!outer -% \letvalue{\??mc->\v!outer }\v!inner -% \letvalue{\??mc->\v!normal}\v!normal +% \installcorenamespace{oppositemargin} +% +% \letvalue{\??oppositemargin\v!left }\v!right +% \letvalue{\??oppositemargin\v!right }\v!left +% \letvalue{\??oppositemargin\v!inner }\v!outer +% \letvalue{\??oppositemargin\v!outer }\v!inner +% \letvalue{\??oppositemargin\v!normal}\v!normal % % \def\oppositemargin#1% -% {\csname\??mc->\ifcsname\??mc->#1\endcsname#1\else\v!normal\fi\endcsname} +% {\csname\??oppositemargin\ifcsname\??oppositemargin#1\endcsname#1\else\v!normal\fi\endcsname} %D Definitions: % common to lines and text -\setupmargindata [\v!left ] [\c!method=\v!first,\c!location=\v!left ,\c!margin=\v!margin,\c!align=\v!flushright,\s!parent=\??mc] % we could autoparent when no define yet -\setupmargindata [\v!right] [\c!method=\v!first,\c!location=\v!right,\c!margin=\v!margin,\c!align=\v!flushleft, \s!parent=\??mc] -\setupmargindata [\v!outer] [\c!method=\v!first,\c!location=\v!outer,\c!margin=\v!margin,\c!align=\v!inner, \s!parent=\??mc] -\setupmargindata [\v!inner] [\c!method=\v!first,\c!location=\v!inner,\c!margin=\v!margin,\c!align=\v!outer, \s!parent=\??mc] +\setupmargindata [\v!left ] [\c!method=\v!first,\c!location=\v!left ,\c!margin=\v!margin,\c!align=\v!flushright,\s!parent=\??margindata] % we could autoparent when no define yet +\setupmargindata [\v!right] [\c!method=\v!first,\c!location=\v!right,\c!margin=\v!margin,\c!align=\v!flushleft, \s!parent=\??margindata] +\setupmargindata [\v!outer] [\c!method=\v!first,\c!location=\v!outer,\c!margin=\v!margin,\c!align=\v!inner, \s!parent=\??margindata] +\setupmargindata [\v!inner] [\c!method=\v!first,\c!location=\v!inner,\c!margin=\v!margin,\c!align=\v!outer, \s!parent=\??margindata] % lines @@ -276,22 +351,22 @@ % text -\definemargindata [inleft] [\v!left ] [\c!margin=\c!margin,\c!width=\leftmarginwidth ,\c!align=\v!flushright] -\definemargindata [inright] [\v!right] [\c!margin=\c!margin,\c!width=\rightmarginwidth,\c!align=\v!flushleft] -\definemargindata [inouter] [\v!outer] [\c!margin=\c!margin,\c!width=\outermarginwidth,\c!align=\v!inner] -\definemargindata [ininner] [\v!inner] [\c!margin=\c!margin,\c!width=\innermarginwidth,\c!align=\v!outer] +\definemargindata [inleft] [\v!left ] [\c!margin=\v!margin,\c!width=\leftmarginwidth ,\c!align=\v!flushright] +\definemargindata [inright] [\v!right] [\c!margin=\v!margin,\c!width=\rightmarginwidth,\c!align=\v!flushleft] +\definemargindata [inouter] [\v!outer] [\c!margin=\v!margin,\c!width=\outermarginwidth,\c!align=\v!inner] +\definemargindata [ininner] [\v!inner] [\c!margin=\v!margin,\c!width=\innermarginwidth,\c!align=\v!outer] % no longer auto auto-other -\definemargindata [inmargin] [\v!left] [\c!margin=\c!margin,\c!width=\leftmarginwidth, \c!align=\v!flushright] -\definemargindata [inother] [\v!right] [\c!margin=\c!margin,\c!width=\rightmarginwidth,\c!align=\v!flushleft] +\definemargindata [inmargin] [\v!left] [\c!margin=\v!margin,\c!width=\leftmarginwidth, \c!align=\v!flushright] +\definemargindata [inother] [\v!right] [\c!margin=\v!margin,\c!width=\rightmarginwidth,\c!align=\v!flushleft] -\definemargindata [margintext] [\v!left] [\c!margin=\c!margin,\c!width=\leftmarginwidth, \c!align=\v!flushright] +\definemargindata [margintext] [\v!left] [\c!margin=\v!margin,\c!width=\leftmarginwidth, \c!align=\v!flushright,\c!stack=\v!yes] -\setupmarginframed [\v!left ] [\c!method=\v!first,\c!align=\v!flushright,\s!parent=\??mf] % we could autoparent when no define yet -\setupmarginframed [\v!right] [\c!method=\v!first,\c!align=\v!flushleft, \s!parent=\??mf] -\setupmarginframed [\v!outer] [\c!method=\v!first,\c!align=\v!inner, \s!parent=\??mf] -\setupmarginframed [\v!inner] [\c!method=\v!first,\c!align=\v!outer, \s!parent=\??mf] +\setupmarginframed [\v!left ] [\c!method=\v!first,\c!align=\v!flushright,\s!parent=\??marginframed] % we could autoparent when no define yet +\setupmarginframed [\v!right] [\c!method=\v!first,\c!align=\v!flushleft, \s!parent=\??marginframed] +\setupmarginframed [\v!outer] [\c!method=\v!first,\c!align=\v!inner, \s!parent=\??marginframed] +\setupmarginframed [\v!inner] [\c!method=\v!first,\c!align=\v!outer, \s!parent=\??marginframed] \definemarginframed [inleft] [\v!left ] \definemarginframed [inright] [\v!right] @@ -300,52 +375,52 @@ \definemarginframed [inmargin] [\v!inleft] \definemarginframed [inother] [\v!inright] -\let\marginword \margintext -\let\margintitle\margintext +\let\marginword \margintext +\let\margintitle \margintext +\let\inothermargin\inother % for old times sake -%definemargindata [inouterextra] [\v!outer] [\c!margin=\c!edge,\c!location=\v!outer,\c!width=\outeredgewidth,\c!align=\v!outer,\c!category=\v!edge] -%definemargindata [ininnerextra] [\v!inner] [\c!margin=\c!edge,\c!location=\v!inner,\c!width=\inneredgewidth,\c!align=\v!inner,\c!category=\v!edge] +%definemargindata [inouterextra] [\v!outer] [\c!margin=\v!edge,\c!location=\v!outer,\c!width=\outeredgewidth,\c!align=\v!outer,\c!category=\v!edge] +%definemargindata [ininnerextra] [\v!inner] [\c!margin=\v!edge,\c!location=\v!inner,\c!width=\inneredgewidth,\c!align=\v!inner,\c!category=\v!edge] % %definemarginframed [inouterextra] [\v!outer] %definemarginframed [ininnerextra] [\v!inner] %D As we have more control we are not backward compatible although in -%D practice it won't hurt that much. -%D So, from now on use: +%D practice it won't hurt that much. So, from now on use: %D %D \starttyping +%D \definemargindata %D \setupmargindata -%D \setupmargintext +%D \definemarginframed +%D \setupmarginframed %D \stoptyping -% The following sort of works okay: -% -% \let\definemarginline\definemargindata -% -% \unexpanded\def\defineinmargin -% {\doquadrupleempty\dodefineinmargin} -% -% \def\dodefineinmargin[#name][#location][#align][#settings]% not completely compatible -% {\definemargindata[#name][\c!location=#location,\c!align=#align,#settings]% -% \definemarginframed[#name][#location][\c!align=#align,#settings]} +% The following sort of works okay but is to be avoided: -\let\setupinmargin\setupmargindata +\let\definemarginline\definemargindata -% The following is too dangerous: -% -% \unexpanded\def\setupinmargin -% {\dodoubleempty\dosetupinmargin} -% -% \def\dosetupinmargin[#1][#2]% -% {\ifsecondargument -% \processcommalist[#1]{\dodosetupinmargin[#2]}% -% \else -% \setupmargindata [#1]% beware, here we can have clashes, so -% \setupmarginframed[#1]% don't use setupinmargin any more -% \fi} +\unexpanded\def\defineinmargin + {\doquadrupleempty\typo_inmargin_define} + +\def\typo_inmargin_define[#name][#location][#align][#settings]% not completely compatible + {\definemargindata[#name][\c!location=#location,\c!align=#align,#settings]% + \definemarginframed[#name][#location][\c!align=#align,#settings]} + +\let\setupinmargin\setupmargindata % only partial (no framed) + +% begin of experimental code (will move) % -% \def\dodosetupinmargin[#1]#2% [settings]{class} -% {\setupmargindata[#2][#1]% -% \setupmargintext[#2][#1]} +% \dosetanchor{x}test \dostarthanchoring{x}\llap{crap}\dostophanchoring{x}test test test +% test \dostarthanchoring{text}\llap{crap}\dostophanchoring{text}test test test + +% \def\dosetanchor #1{\dontleavehmode\latelua{anchors.set("#1")}} +% \def\doresetanchor #1{\dontleavehmode\latelua{anchors.reset("#1")}} +% \def\doresetanchornow #1{\directlua{anchors.reset("#1")}} +% \def\dostartanchoring #1{\dontleavehmode\latelua{anchors.startmove("#1")}} +% \def\dostopanchoring #1{\dontleavehmode\latelua{anchors.stopmove("#1")}} +% \def\dostarthanchoring#1{\dontleavehmode\latelua{anchors.startmove("#1","h")}} +% \def\dostartvanchoring#1{\dontleavehmode\latelua{anchors.startmove("#1","v")}} +% \let\dostophanchoring \dostopanchoring +% \let\dostopvanchoring \dostopanchoring \protect \endinput |