%D \module %D [ file=strc-ren, %D version=2008.10.20, %D title=\CONTEXT\ Structure Macros, %D subtitle=Section Rendering, %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 / Section Rendering} \unprotect \newconstant\headtimingmode % Martin Kolarik's problem: % % \setuphead[section][command=\doTitle] % \def\doTitle#1#2{\ruledvbox{\forgetall \hsize=4cm \ruledhbox{\ruledvtop{#1}\ruledvtop{#2}}}} % \section{test test test test test test test test test test test test test test test test test} \newevery \everyheadstart \relax \unexpanded\def\setupheadcomponentfont#1#2% {\dontconvertfont \ifconditional\headisdisplay \edef\askedheadinterlinespace{\headparameter\c!interlinespace}% \ifx\askedheadinterlinespace\empty % here the interline space is only set when style sets no space \setfalse\fontattributeisset % use the currentfontparameter state instead \setfalse\interlinespaceisset \useheadstyleandcolor\c!style\c!color \ifconditional\fontattributeisset \ifconditional\interlinespaceisset \else \setupinterlinespace \fi \fi \setfalse\fontattributeisset \useheadstyleandcolor#1#2% \ifconditional\fontattributeisset \ifconditional\interlinespaceisset \else \setupinterlinespace \fi \fi \else % here the set interline space overloads any other set space in the style \setfalse\fontattributeisset \useheadstyleandcolor\c!style\c!color \ifconditional\fontattributeisset \dosetupcheckedinterlinespace\askedheadinterlinespace \fi \setfalse\fontattributeisset \useheadstyleandcolor#1#2% \ifconditional\fontattributeisset \dosetupcheckedinterlinespace\askedheadinterlinespace \fi \fi \else \setfalse\fontattributeisset \useheadstyleandcolor\c!style\c!color \ifconditional\fontattributeisset \setupspacing \fi \setfalse\fontattributeisset \useheadstyleandcolor#1#2% \ifconditional\fontattributeisset \setupspacing \fi \fi} \def\doplaceheadtextcomponent#1% {\begingroup \setupheadcomponentfont\c!textstyle\c!textcolor \headparameter\c!commandbefore \ifcsname\currentheadhash\c!deeptextcommand\endcsname \expandafter\let\expandafter\deepstructuretitlecommand\csname\currentheadhash\c!deeptextcommand\endcsname \fi \ifconditional\headisdisplay % \ifdisplaysectionhead % struts can be nilled with \setnostrut \headparameter\c!textcommand{\setstrut\begstrut#1\endstrut}% \xdef\localheadheight {\the\strutht}% \xdef\localheaddepth {\the\strutdp}% \xdef\localheadlineheight{\the\lineheight}% % == \globallet\localheaddepth\strutdepth \else \headparameter\c!textcommand{#1}% \fi \headparameter\c!commandafter \ifconditional\headisdisplay % \ifdisplaysectionhead \endgraf \fi \endgroup} \def\doplaceheadnumbercomponent#1% {\begingroup \setupheadcomponentfont\c!numberstyle\c!numbercolor \ifcsname\currentheadhash\c!deepnumbercommand\endcsname \expandafter\let\expandafter\deepstructurenumbercommand\csname\currentheadhash\c!deepnumbercommand\endcsname \fi \ifconditional\headisdisplay % \ifdisplaysectionhead % can be nilled with \setnostrut \headparameter\c!numbercommand{\setstrut\begstrut#1\endstrut}% \else \headparameter\c!numbercommand{#1}% \fi \endgroup} % \newif\ifheadnumbercontent % \newif\ifemptyhead % \newif\ifdisplaysectionhead \let\currentstructurereferenceattribute\attributeunsetvalue \def\headreferenceattributes {\iflocation % \ctxlua{structures.lists.taglocation(\nextinternalreference)}% maybe ... tags entry as used attr \destinationattribute \currentstructureattribute attr \referenceattribute \currentstructurereferenceattribute % attr \internalattribute \nextinternalreference \fi} \def\setinlineheadreferenceattributes {\ifconditional\headisdisplay \else \iflocation \attribute\destinationattribute\currentstructureattribute \attribute\referenceattribute \currentstructurereferenceattribute % \attribute\internalattribute \nextinternalreference \fi \fi} \def\docheckheadreference {\edef\currentheadinteraction{\headparameter\c!interaction}% \ifx\currentheadinteraction\v!list % setuphead[
][interaction=list,...] \strc_references_get_simple_page_reference{bck:\nextinternalreference}% \let\currentstructurereferenceattribute\currentreferenceattribute \else\ifx\currentheadinteraction\v!reference % setuphead[
][interaction=reference,...] start
[backreference=abc,...] \edef\currentheadbackreference{\structurevariable\c!backreference}% weird, was references.backreference \ifx\currentheadbackreference\empty \else \strc_references_get_simple_page_reference\currentheadbackreference \let\currentstructurereferenceattribute\currentreferenceattribute \fi \else % maybe auto: backreference when given, else list \fi\fi} \unexpanded\def\placecurrentheadtext {\beginheadplacement \setheadmarking \doresettructureheadnumbercontent \ifconditional\headleaveempty \setbox\sectionheadbox\hbox \headreferenceattributes to \zeropoint{}% \makestrutofbox\sectionheadbox \else \docheckheadreference \setbox\sectionheadbox\hbox \headreferenceattributes {\spac_grids_set_local_snapping{\headparameter\c!internalgrid}% \doresettructureheadnumbercontent \useheadstyleparameter\c!style \setinlineheadreferenceattributes \headparameter\c!command{}{\doplaceheadtextcomponent\getheadtitle}}% \fi \endheadplacement{\getheadsyncs}} \unexpanded\def\placecurrentheadnumbertext {\beginheadplacement \setheadmarking \doiftextelse{\getheadnumber}\dosettructureheadnumbercontent\doresettructureheadnumbercontent \ifconditional\headleaveempty \setbox\sectionheadbox\hbox \headreferenceattributes to \zeropoint{}% \makestrutofbox\sectionheadbox \else % = needed \docheckheadreference \setbox\sectionheadbox\hbox \headreferenceattributes {\spac_grids_set_local_snapping{\headparameter\c!internalgrid}% \useheadstyleparameter\c!style \setinlineheadreferenceattributes \headparameter\c!command{\doplaceheadnumbercomponent\getheadnumber}{\doplaceheadtextcomponent\getheadtitle}}% \fi \endheadplacement{\getheadsyncs}} \unexpanded\def\placecurrentheadempty {\hbox \headreferenceattributes {\getheadsyncs}} %D \starttyping %D \def\StretchedBox#1% %D {\framed %D [frame=off,offset=.5em,align=middle,width=broad] %D {\sc\def\stretchedspaceamount{.3em}\stretchednormalcase{#1}}} %D %D \definehead[MySubject][subject] %D \setuphead [MySubject][deeptextcommand=\StretchedBox] %D %D \MySubject{feeling stretched feeling stretched feeling stretched feeling stretched} %D \stoptyping \let\headlastlinewidth\!!zeropoint \def\localheadheight {\strutht} \def\localheaddepth {\strutdp} \def\localheadlineheight{\lineheight} \def\dolocalheadsetup % koppeling met standaard kopcommando / engels {\forgetall % traag dus ... \doifsomething{\headparameter\c!align } {\normalexpanded{\noexpand\setupalign [\headparameter\c!align ]}}% \doifsomething{\headparameter\c!tolerance} {\normalexpanded{\noexpand\setuptolerance[\headparameter\c!tolerance]}}% \doif {\headparameter\c!strut }\v!no{\setnostrut}% new \def\\{\crlf\strut\ignorespaces}} \def\beginheadplacement {\bgroup \setsystemmode\currenthead \xdef\localheadheight {\the\strutht}% \xdef\localheaddepth {\the\strutdp}% \xdef\localheadlineheight{\the\lineheight}% % == \globallet\localheaddepth\strutdp \everypar\emptytoks % needed indeed \noindent % ipv \whitespace elders, na \forgetall ! \bgroup \doifinsetelse{\headparameter\c!aligntitle}{\v!yes,\v!float}% new {\skip0 1\leftskip \skip2 1\rightskip \xdef\localheadskip{\the\skip0}% \forgetall \leftskip\skip0 \rightskip\skip2 \setlocalhsize\hsize\localhsize \forgetbothskips} {\globallet\localheadskip\!!zeropoint \forgetall}% \setfalse\inhibitmargindata % brrrr is set in forgetall \dontcomplain \postponenotes \iflocation \ifconditional\headisdisplay % \ifdisplaysectionhead \else % obsolete: \noninterferingmarks \fi \fi \resetinteractionparameter\c!style \resetinteractionparameter\c!color \resetinteractionparameter\c!contrastcolor %\strictouterreferencestrue % tzt instelling \let\localheadsetup\dolocalheadsetup} % \setuphead[chapter] [style=\bfd,after=,hang=line] % fit broad 2 % \setuphead[section] [style=\bfc,after=,hang=line] % \setuphead[subsection] [style=\bfb,after=,hang=line] % \setuphead[subsubsection] [style=\bfa,after=,hang=line] % \setuphead[subsubsubsection][style=\bf ,after=,hang=line] % % \chapter {Test} \input tufte \page % \section {Test} \input tufte \page % \subsection {Test} \input tufte \page % \subsubsection {Test} \input tufte \page % \subsubsubsection{Test} \input tufte \page % % \chapter {Test\\Test} \input tufte \page % \section {Test\\Test} \input tufte \page % \subsection {Test\\Test} \input tufte \page % \subsubsection {Test\\Test} \input tufte \page % \subsubsubsection{Test\\Test} \input tufte \page \def\hangheadplacement {\scratchdimen\localheadlineheight \bgroup \openlineheight\scratchdimen \scratchdimen\htdp0% \getnoflines\scratchdimen \advance\noflines\minusone \normalexpanded{\egroup\noflines\the\noflines}% brrr \setbox0\hbox{\lower\noflines\scratchdimen\box0}% \scratchdimen\dimexpr\htdp0-\localheadheight+\strutdp\relax \ht0 \strutht \dp0 \strutdp \edef\localheaddepth{\the\strutdp}} \newconditional\continuoussectionhead % oeps, \newif\ifcontinuoushead got lost \newbox\sectionheadbox \def\endheadplacement#1% {\noflines\zerocount \ifconditional\headisdisplay % \ifdisplaysectionhead % new (todo tight == one following line up) \processaction [\headparameter\c!hang] [ \v!line=>\hangheadplacement\noflines\zerocount, \v!broad=>\hangheadplacement\getnoflines\scratchdimen, \v!fit=>\hangheadplacement\getrawnoflines\scratchdimen, \v!none=>\noflines\zerocount, \v!default=>\noflines\zerocount, \v!unknown=>\hangheadplacement\noflines\numexpr0\commalistelement-1\relax]% % so far \let\headlastlinewidth\!!zeropoint % kind of special, we want to snap heads also according to local specs local \ifgridsnapping \hbox\bgroup % extra hbox will trigger global snapper on top of local \edef\currentheadgridsnapping{\headparameter\c!grid}% \ifconditional\headisdisplay \ifx\currentheadgridsnapping\empty\else \useheadstyleandcolor\c!style\c!color \setupinterlinespace \useheadstyleandcolor\c!textstyle\c!textcolor \setupinterlinespace \fi \fi \snaptogrid[\currentheadgridsnapping]\hbox {\hskip\localheadskip\hskip\headparameter\c!margin\box\sectionheadbox}% \egroup \else \hbox {\hskip\localheadskip\hskip\headparameter\c!margin\box\sectionheadbox}% \fi \flushnotes % new, not really needed \endgraf \ifvmode \ifnum\noflines>\zerocount \dorecurse\noflines{\nointerlineskip\dosomebreak\nobreak\strut\endgraf}% to be checked \fi \nointerlineskip \dosomebreak\nobreak \fi #1% \else \strut \flushnotes % new, here since we're in par mode \unhbox\sectionheadbox \globallet\headlastlinewidth\!!zeropoint #1% \hskip\numberheaddistance\!!plus\numberheaddistance\!!minus.25\dimexpr\numberheaddistance\relax \hskip\continuousheadsignal\ignorespaces \fi \ifconditional\headisdisplay % \ifdisplaysectionhead \ifvmode \ifgridsnapping % important, font related depth, see comment \prevdepth\strutdp \else \prevdepth\localheaddepth \fi \fi \fi \egroup \egroup \ifconditional\headisdisplay % \ifdisplaysectionhead \useindentnextparameter\headparameter \else \nonoindentation % recently added, was a bug \fi} % nice testcase % % \setupheads[aligntitle=yes] % % \startnarrower % \subject{\dorecurse{100}{x }} % \section{\dorecurse{100}{x }} % \input tufte \par % \setupheads[alternative=inmargin] % \subject{\dorecurse{100}{x }} % \section{\dorecurse{100}{x }} % \input tufte \par % \stopnarrower \installcorenamespace{headplacementalternative} \installcorenamespace{headplacementnature} \let\numberheadalternative\v!normal \unexpanded\def\defineheadplacement {\dodoubleargument\dodefineheadplacement} % \def\dodefineheadplacement[#1][#2]% #3#4 % {\setvalue{\??headplacementnature#1}{#2}% % \setvalue{\??headplacementalternative#1}} % \dodefineheadplacement[sectiona][vertical]{#1->#2} % \dodefineheadplacement[sectionb][vertical]#1#2{#1->#2} % % \setuphead[section][alternative=sectiona] % \setuphead[subsection][alternative=sectionb] \def\dodefineheadplacementyes[#1][#2]%#3#4% {\setvalue{\??headplacementnature#1}{#2}% \setvalue{\??headplacementalternative#1}##1##2} \def\dodefineheadplacementnop[#1][#2]% {\setvalue{\??headplacementnature#1}{#2}% \setvalue{\??headplacementalternative#1}} \def\dodefineheadplacement[#1][#2]% {\doifnextbgroupelse {\dodefineheadplacementyes[#1][#2]}% {\dodefineheadplacementnop[#1][#2]}} \def\presetnumberheadalternative {\doifelsevalue{\??headplacementnature\numberheadalternative}\v!horizontal\setfalse\settrue\headisdisplay} \def\normalplacehead {\csname\??headplacementalternative\ifcsname\??headplacementalternative\numberheadalternative\endcsname\numberheadalternative\else\v!normal\fi\endcsname} \def\setheaddisplay % used in strc-sec {\doifelsevalue{\??headplacementnature\headparameter\c!alternative}\v!horizontal {\setfalse\headisdisplay} {\settrue \headisdisplay}} \defineheadplacement[\v!paragraph][\v!vertical]#1#2% {\vbox {\localheadsetup \begstrut \ifconditional\headshownumber % \ifheadnumbercontent #1\hskip\numberheaddistance \fi #2}} % \setuphead % [chapter] % [numberwidth=2cm,hang=line,after={\blank[3*line]}] % % \chapter{Oeps oeps oeps} \input tufte \section{Oeps} % \chapter{Oeps oeps oeps} \section{Oeps} \input tufte \defineheadplacement[\v!normal][\v!vertical]#1#2% {\vbox {\localheadsetup \edef\headwidth {\headparameter\c!width }% \edef\headnumberwidth{\headparameter\c!numberwidth}% \edef\headtextwidth {\headparameter\c!textwidth }% \ifconditional\headshownumber \ifx\headwidth\empty \else \ifx\headnumberwidth\empty \ifx\headtextwidth\empty\else \edef\headnumberwidth{\the\dimexpr\headwidth-\headtextwidth\relax}% \fi \else \ifx\headtextwidth\empty \edef\headtextwidth{\the\dimexpr\headwidth-\headnumberwidth\relax}% \fi \fi \hsize\headwidth \fi \ifx\headnumberwidth\empty\else \let\numberheaddistance\!!zeropoint \fi \setbox\scratchbox\hbox \ifx\headnumberwidth\empty\else to \headnumberwidth\fi{{#1}}% \scratchdimen\dimexpr\wd\scratchbox+\numberheaddistance\relax \ifx\headtextwidth\empty\else \hsize\dimexpr\scratchdimen+\headparameter\c!textwidth\relax \fi \hangindent\scratchdimen \hangafter \plusone \noindent \box\scratchbox\hskip\numberheaddistance \else \ifx\headtextwidth\empty \ifx\headwidth\empty \else \hsize\headwidth \fi \else \hsize\headtextwidth \fi \noindent \fi #2}} % \unexpanded\def\placeheadmarginalternative#1#2% % {\vbox % {\localheadsetup % \begstrut % use one \strut here! % \dontleavehmode % in case there is no strut, else side effects with llap % \ifconditional\headshownumber % \llap{\hbox{\hfill{#1}\hskip\localheadskip\hskip\leftmargindistance}}% introduces whitespace % % maybe better: % % \inleftmargin{\hbox{\hss{#1}\hskip\localheadskip}}% % \fi % {#2}}} \unexpanded\def\placeheadmarginalternative#1#2% {\vbox {\localheadsetup \begstrut % use one \strut here! \dontleavehmode % in case there is no strut, else side effects with llap \ifconditional\headshownumber \llap{\hbox{\hfill{#1}\hskip\dimexpr\localheadskip+\doifoddpageelse\leftmargindistance\rightmargindistance\relax}}% introduces whitespace \fi {#2}}} \defineheadplacement[\v!inmargin][\v!vertical]#1#2{\placeheadmarginalternative{#1}{#2}} \defineheadplacement[\v!margin] [\v!vertical]#1#2{\placeheadmarginalternative{#1}{#2}} \defineheadplacement[\v!middle][\v!vertical]#1#2% {\vbox {\localheadsetup \veryraggedcenter \let\\\endgraf \let\crlf\endgraf \ifconditional\headshownumber \strut#1\par \fi \begstrut#2}} \defineheadplacement[\v!text][\v!horizontal]#1#2% {\bgroup \localheadsetup % no stretch in distance \ifconditional\headshownumber {#1}\kern\numberheaddistance \fi {\begstrut#2}% \egroup} \unexpanded\def\placeheadlohialternative#1#2#3% {\ifconditional\headshownumber \setbox0\hbox{#2} \setbox2=#1{\localheadsetup\advance\hsize-\wd0\relax#3}% \hbox{\box0\hskip\numberheaddistance\box2}% \else #1{\localheadsetup\noindent#3}% \fi} % onder/boven lijnt het nummer op de onderste/bovenste regel % uit van een meerregelige kop \defineheadplacement[\v!bottom][\v!vertical]#1#2{\placeheadlohialternative\vbox{#1}{#2}} \defineheadplacement[\v!top] [\v!vertical]#1#2{\placeheadlohialternative\vtop{#1}{#2}} % helpers % \defineinmargin [ChapterInMargin] [outer] [normal] [distance=0.3em] % % \defineheadplacement[MyTest][horizontal]#1#2% % {\startlocalheadsetup % %\ChapterInMargin{\headhbox{\strut#2}}% proper destination, ref okay % \ChapterInMargin{\strut#2}% zero destination, ref okay % \stoplocalheadsetup} % % \setuphead % [chapter] % [alternative=MyTest] \unexpanded\def\headhbox{\hbox\headreferenceattributes} \unexpanded\def\headvbox{\vbox\headreferenceattributes} \unexpanded\def\startlocalheadsetup{\bgroup\localheadsetup} \unexpanded\def\stoplocalheadsetup {\egroup} \protect \endinput