beta 2014.02.14 17:07
[context.git] / tex / context / base / strc-ren.mkiv
blobfdf8fb7f4a4b44a2269151a717deae1c9985b811
1 %D \module
2 %D   [       file=strc-ren,
3 %D        version=2008.10.20,
4 %D          title=\CONTEXT\ Structure Macros,
5 %D       subtitle=Section Rendering,
6 %D         author=Hans Hagen,
7 %D           date=\currentdate,
8 %D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9 %C
10 %C This module is part of the \CONTEXT\ macro||package and is
11 %C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12 %C details.
14 \writestatus{loading}{ConTeXt Structure Macros / Section Rendering}
16 \unprotect
18 \newbox\b_strc_rendering_head
20 \newdimen\d_strc_rendering_local_leftoffset
21 \newdimen\d_strc_rendering_local_rightoffset
23 % Martin Kolarik's problem:
25 % \setuphead[section][command=\doTitle]
26 % \def\doTitle#1#2{\ruledvbox{\forgetall \hsize=4cm \ruledhbox{\ruledvtop{#1}\ruledvtop{#2}}}}
27 % \section{test test test test test test test test test test test test test test test test test}
29 % \newtoks\everyheadstart % not used currently
31 \unexpanded\def\strc_rendering_initialize_style_and_color
32   {\ifconditional\headisdisplay
33      \expandafter\strc_rendering_initialize_style_and_color_display
34    \else
35      \expandafter\strc_rendering_initialize_style_and_color_inline
36    \fi}
38 \unexpanded\def\strc_rendering_initialize_style_and_color_display#1#2%
39   {\dontconvertfont
40    \edef\p_strc_rendering_interlinespace{\headparameter\c!interlinespace}%
41    \ifx\p_strc_rendering_interlinespace\empty
42      % here the interline space is only set when style sets no space
43      \setfalse\fontattributeisset % use the currentfontparameter state instead
44      \setfalse\interlinespaceisset
45      \useheadstyleandcolor\c!style\c!color\relax
46      \ifconditional\fontattributeisset \ifconditional\interlinespaceisset \else
47        \setupinterlinespace
48      \fi \fi
49      \setfalse\fontattributeisset
50      \useheadstyleandcolor#1#2\relax
51      \ifconditional\fontattributeisset \ifconditional\interlinespaceisset \else
52        \setupinterlinespace
53      \fi \fi
54    \else
55      % here the set interline space overloads any other set space in the style
56      \setfalse\fontattributeisset
57      \useheadstyleandcolor\c!style\c!color\relax
58      \ifconditional\fontattributeisset
59        \dosetupcheckedinterlinespace\p_strc_rendering_interlinespace
60      \fi
61      \setfalse\fontattributeisset
62      \useheadstyleandcolor#1#2\relax
63      \ifconditional\fontattributeisset
64        \dosetupcheckedinterlinespace\p_strc_rendering_interlinespace
65      \fi
66    \fi}
68 \unexpanded\def\strc_rendering_initialize_style_and_color_inline#1#2%
69    {\dontconvertfont
70     \setfalse\fontattributeisset
71     \useheadstyleandcolor\c!style\c!color\relax
72     \ifconditional\fontattributeisset
73       \updateraggedskips % \setupspacing
74     \fi
75     \setfalse\fontattributeisset
76     \useheadstyleandcolor#1#2\relax
77     \ifconditional\fontattributeisset
78       \updateraggedskips % \setupspacing
79     \fi}
81 \let\currentstructurereferenceattribute\attributeunsetvalue
83 \def\headreferenceattributes
84   {\iflocation
85    % \ctxlua{structures.lists.taglocation(\nextinternalreference)}% maybe ... tags entry as used
86      attr \destinationattribute \currentstructureattribute
87      attr \referenceattribute   \currentstructurereferenceattribute
88    % attr \internalattribute    \nextinternalreference
89    \fi}
91 \def\setinlineheadreferenceattributes
92   {\ifconditional\headisdisplay \else \iflocation
93      \attribute\destinationattribute\currentstructureattribute
94      \attribute\referenceattribute  \currentstructurereferenceattribute
95    % \attribute\internalattribute   \nextinternalreference
96    \fi \fi}
98 \def\docheckheadreference
99   {\edef\currentheadinteraction{\headparameter\c!interaction}%
100    \ifx\currentheadinteraction\v!list
101      % setuphead[<section>][interaction=list,...]
102      \strc_references_get_simple_page_reference{bck:\nextinternalreference}%
103      \let\currentstructurereferenceattribute\currentreferenceattribute
104    \else\ifx\currentheadinteraction\v!reference
105      % setuphead[<section>][interaction=reference,...] start<section>[backreference=abc,...]
106      \edef\currentheadbackreference{\structurevariable\c!backreference}% weird, was references.backreference
107      \ifx\currentheadbackreference\empty \else
108        \strc_references_get_simple_page_reference\currentheadbackreference
109        \let\currentstructurereferenceattribute\currentreferenceattribute
110      \fi
111    \else
112       % maybe auto: backreference when given, else list
113    \fi\fi}
115 % a bit messy ... empty in place instead of self .. might change (or use special
116 % whatsig (invisible user one)
118 \unexpanded\def\strc_rendering_place_head_text
119   {\strc_rendering_start_placement
120    \setheadmarking
121    \doresettructureheadnumbercontent
122    \ifconditional\c_strc_sectioning_empty
123      \setbox\b_strc_rendering_head\hbox \headreferenceattributes to \zeropoint{\strut}%
124    \else
125      \docheckheadreference
126      \setbox\b_strc_rendering_head\hbox \headreferenceattributes
127        {\spac_grids_set_local_snapping{\headparameter\c!internalgrid}%
128         \doresettructureheadnumbercontent
129         \useheadstyleparameter\c!style
130         \setinlineheadreferenceattributes
131         \strc_rendering_inject_text}%
132    \fi
133    \strc_rendering_stop_placement}
135 \unexpanded\def\strc_rendering_place_head_number_and_text
136   {\strc_rendering_start_placement
137    \setheadmarking
138    \doiftextelse\getheadnumber
139      \dosettructureheadnumbercontent
140      \doresettructureheadnumbercontent
141    \ifconditional\c_strc_sectioning_empty
142      \setbox\b_strc_rendering_head\hbox \headreferenceattributes to \zeropoint{\strut}%
143    \else % = needed
144      \docheckheadreference
145      \setbox\b_strc_rendering_head\hbox \headreferenceattributes
146        {\spac_grids_set_local_snapping{\headparameter\c!internalgrid}%
147         \useheadstyleparameter\c!style
148         \setinlineheadreferenceattributes
149         \strc_rendering_inject_number_and_text}%
150    \fi
151    \strc_rendering_stop_placement}
153 \unexpanded\def\strc_rendering_place_head_empty
154   {\hbox \headreferenceattributes {\getheadsyncs}}
156 %D \starttyping
157 %D \def\StretchedBox#1%
158 %D   {\framed
159 %D      [frame=off,offset=.5em,align=middle,width=broad]
160 %D      {\sc\def\stretchedspaceamount{.3em}\stretchednormalcase{#1}}}
162 %D \definehead[MySubject][subject]
163 %D \setuphead [MySubject][deeptextcommand=\StretchedBox]
165 %D \MySubject{feeling stretched feeling stretched feeling stretched feeling stretched}
166 %D \stoptyping
168 % helpers
170 % \defineinmargin [ChapterInMargin] [outer] [normal] [distance=0.3em]
172 % \defineheadplacement[MyTest][horizontal]#1#2%
173 %   {\startlocalheadsetup
174 %   %\ChapterInMargin{\headhbox{\strut#2}}% proper destination, ref okay
175 %    \ChapterInMargin{\strut#2}% zero destination, ref okay
176 %    \stoplocalheadsetup}
178 % \setuphead
179 %   [chapter]
180 %   [alternative=MyTest]
182 \unexpanded\def\headhbox{\hbox\headreferenceattributes}
183 \unexpanded\def\headvbox{\vbox\headreferenceattributes}
185 \unexpanded\def\startlocalheadsetup{\bgroup\strc_rendering_initialize_spacing}
186 \unexpanded\def\stoplocalheadsetup {\egroup}
188 \unexpanded\def\strc_rendering_initialize_spacing
189   {\forgetall % local !
190    \edef\p_align{\headparameter\c!align}%
191    \ifx\p_align\empty \else
192      \setupalign[\p_align]%
193    \fi
194    \edef\p_tolerance{\headparameter\c!tolerance}%
195    \ifx\p_tolerance\empty \else
196      \setuptolerance[\p_tolerance]%
197    \fi
198    \edef\p_strut{\headparameter\c!strut}%
199    \ifx\p_strut\v!no
200      \setnostrut
201    \fi
202    \let\\\strc_rendering_shortcut_backslash}
204 \unexpanded\def\strc_rendering_shortcut_backslash
205   {\crlf
206    \strut
207    \ignorespaces}
209 \def\strc_rendering_start_placement
210   {\bgroup
211    \setsystemmode\currenthead
212    %
213    \strc_rendering_initialize_alternatives
214    \strc_rendering_initialize_dimensions
215    %
216    \strc_rendering_initialize_line_state
217    \reseteverypar % needed indeed
218    \noindent      % ipv \whitespace elders, na \forgetall !
219    \bgroup
220    \edef\p_aligntitle{\headparameter\c!aligntitle}%
221    \ifx\p_aligntitle\v!yes
222      \strc_rendering_initialize_hsize_local
223    \else\ifx\p_aligntitle\v!float
224      \strc_rendering_initialize_hsize_local
225    \else
226      \strc_rendering_initialize_hsize_global
227    \fi\fi
228    \setfalse\inhibitmargindata % brrrr is set in forgetall
229    \dontcomplain
230    \postponenotes
231    \strc_rendering_initialize_interaction
232    % delayed
233    \let\localheadsetup  \strc_rendering_initialize_spacing % historic name
234    \let\headsetupspacing\strc_rendering_initialize_spacing}
236 \def\strc_rendering_initialize_hsize_local
237   {\global\d_strc_rendering_local_leftoffset \leftskip
238    \global\d_strc_rendering_local_rightoffset\rightskip
239  % \forgetall
240  % \leftskip \d_strc_rendering_local_leftoffset  % no stretch
241  % \rightskip\d_strc_rendering_local_rightoffset % no stretch
242  % \setlocalhsize
243  % \hsize\localhsize
244  % \forgetbothskips}
245    \scratchwidth\availablehsize
246    \forgetall
247    \hsize\scratchwidth}
249 \def\strc_rendering_initialize_hsize_global
250   {\global\d_strc_rendering_local_leftoffset \zeropoint
251    \global\d_strc_rendering_local_rightoffset\zeropoint
252    \forgetall}
254 \def\strc_rendering_initialize_interaction
255   {\resetinteractionparameter\c!style
256    \resetinteractionparameter\c!color
257    \resetinteractionparameter\c!contrastcolor}
259 % \setuphead[chapter]         [style=\bfd,after=,hang=line] % fit broad 2
260 % \setuphead[section]         [style=\bfc,after=,hang=line]
261 % \setuphead[subsection]      [style=\bfb,after=,hang=line]
262 % \setuphead[subsubsection]   [style=\bfa,after=,hang=line]
263 % \setuphead[subsubsubsection][style=\bf ,after=,hang=line]
265 % \chapter         {Test} \input tufte \page
266 % \section         {Test} \input tufte \page
267 % \subsection      {Test} \input tufte \page
268 % \subsubsection   {Test} \input tufte \page
269 % \subsubsubsection{Test} \input tufte \page
271 % \chapter         {Test\\Test} \input tufte \page
272 % \section         {Test\\Test} \input tufte \page
273 % \subsection      {Test\\Test} \input tufte \page
274 % \subsubsection   {Test\\Test} \input tufte \page
275 % \subsubsubsection{Test\\Test} \input tufte \page
277 \newdimen\d_strc_rendering_hang_height
278 \newcount\n_strc_rendering_hang_lines
280 \newdimen\d_strc_rendering_local_height
281 \newdimen\d_strc_rendering_local_depth
282 \newdimen\d_strc_rendering_local_lineheight
284 \def\strc_rendering_initialize_line_state
285   {\global\d_strc_rendering_local_height\strutht
286    \global\d_strc_rendering_local_depth\strutdp
287    \global\d_strc_rendering_local_lineheight\lineheight}
289 \def\strc_rendering_check_hang
290   {\begingroup
291    \openlineheight\d_strc_rendering_local_lineheight
292    \d_strc_rendering_hang_height\htdp\b_strc_rendering_head
293    \getnoflines\d_strc_rendering_hang_height
294    \normalexpanded{\endgroup\n_strc_rendering_hang_lines\the\numexpr\noflines-\plusone\relax}% brrr
295    \setbox\b_strc_rendering_head\hbox{\lower\n_strc_rendering_hang_lines\d_strc_rendering_hang_height\box\b_strc_rendering_head}%
296    \d_strc_rendering_hang_height\dimexpr\htdp\b_strc_rendering_head-\d_strc_rendering_local_height+\strutdp\relax
297    \ht\b_strc_rendering_head\strutht
298    \dp\b_strc_rendering_head\strutdp
299    \d_strc_rendering_local_depth\strutdp}
301 \installcorenamespace{headplacementcheckhang}
303 \setvalue{\??headplacementcheckhang\v!line   }{\strc_rendering_check_hang
304                                                \n_strc_rendering_hang_lines\zerocount}
305 \setvalue{\??headplacementcheckhang\v!broad  }{\strc_rendering_check_hang
306                                                \getnoflines\d_strc_rendering_hang_height}
307 \setvalue{\??headplacementcheckhang\v!fit    }{\strc_rendering_check_hang
308                                                \getrawnoflines\d_strc_rendering_hang_height}
309 \setvalue{\??headplacementcheckhang\v!none   }{\n_strc_rendering_hang_lines\zerocount}
310 \setvalue{\??headplacementcheckhang          }{\n_strc_rendering_hang_lines\zerocount}
311 \setvalue{\??headplacementcheckhang\s!unknown}{\strc_rendering_check_hang
312                                                \n_strc_rendering_hang_lines\numexpr\headparameter\c!hang-\plusone\relax}
314 \def\strc_rendering_initialize_line_hang
315    {\ifconditional\headisdisplay
316       \expandnamespaceparameter\??headplacementcheckhang\headparameter\c!hang\s!unknown
317       \relax
318     \else
319       \n_strc_rendering_hang_lines \zerocount
320       \d_strc_rendering_hang_height\zeropoint
321     \fi}
323 \def\strc_rendering_stop_placement
324   {\n_strc_rendering_hang_lines\zerocount
325    \ifconditional\headisdisplay
326      \strc_rendering_initialize_line_hang
327      % kind of special, we want to snap heads also according to local specs local
328      \ifgridsnapping
329        \hbox\bgroup % extra hbox will trigger global snapper on top of local
330          \edef\p_grid{\headparameter\c!grid}%
331          \ifconditional\headisdisplay
332            \ifx\p_grid\empty\else
333              \useheadstyleandcolor\c!style\c!color
334              \setupinterlinespace
335              \useheadstyleandcolor\c!textstyle\c!textcolor
336              \setupinterlinespace
337            \fi
338          \fi
339          \snaptogrid[\p_grid]\hbox
340            {\hskip\dimexpr\d_strc_rendering_local_leftoffset+\headparameter\c!margin\relax\box\b_strc_rendering_head}%
341        \egroup
342      \else
343        \hbox
344          {\hskip\dimexpr\d_strc_rendering_local_leftoffset+\headparameter\c!margin\relax\box\b_strc_rendering_head}%
345      \fi
346      \flushnotes % new, not really needed
347      \endgraf
348      \ifvmode
349        \ifnum\n_strc_rendering_hang_lines>\zerocount
350          \dorecurse\n_strc_rendering_hang_lines{\nointerlineskip\dosomebreak\nobreak\strut\endgraf}% to be checked
351        \fi
352        \nointerlineskip
353        \dosomebreak\nobreak
354      \fi
355      \getheadsyncs
356    \else
357      \strut
358      \flushnotes % new, here since we're in par mode
359      \unhbox\b_strc_rendering_head
360      \getheadsyncs
361      \hskip\headnumberdistance\s!plus\headnumberdistance\s!minus.25\dimexpr\headnumberdistance\relax
362      \strc_sectioning_inject_continuous_signal
363    \fi
364    \ifconditional\headisdisplay
365      \ifvmode
366        \ifgridsnapping % important, font related depth, see comment
367          \prevdepth\strutdp
368        \else
369          \prevdepth\d_strc_rendering_local_depth
370        \fi
371      \fi
372    \fi
373    \egroup
374    \egroup
375    \ifconditional\headisdisplay
376      \useindentnextparameter\headparameter
377    \else
378      \nonoindentation % recently added, was a bug
379    \fi}
381 % nice testcase
383 % \setupheads[aligntitle=yes]
385 % \startnarrower
386 %   \subject{\dorecurse{100}{x }}
387 %   \section{\dorecurse{100}{x }}
388 %   \input tufte \par
389 %   \setupheads[alternative=inmargin]
390 %   \subject{\dorecurse{100}{x }}
391 %   \section{\dorecurse{100}{x }}
392 %   \input tufte \par
393 % \stopnarrower
395 % \dodefineheadplacement[sectiona][vertical]{#1->#2}
396 % \dodefineheadplacement[sectionb][vertical]#1#2{#1->#2}
398 % \setuphead[section][alternative=sectiona]
399 % \setuphead[subsection][alternative=sectionb]
401 % \startsetups[\??headrenderings:\v!vertical:\v!sectiona]
402 %     ... there will be a more public namespace
403 % \stopsetups
405 \installcorenamespace{headplacementalternative}
406 \installcorenamespace{headrenderings}
407 \installcorenamespace{headalternative}
409 \installcommandhandler \??headalternative {headalternative} \??headalternative % or just \??head
411 \setupheadalternative
412   [%\c!width=\headparameter\c!width,
413    %\c!distance=\headparameter\c!distance,
414    \c!alternative=\v!vertical,
415    \c!renderingsetup=\??headrenderings:\currentheadalternative]
417 \let\currentheadalternative         \v!normal
418 \let\currentheadrenderingsetup      \empty
419 \let\currentheadrenderingalternative\v!vertical
421 \unexpanded\def\defineheadplacement % old mechanism
422   {\dodoubleargument\strc_rendering_define_placement}
424 \def\strc_rendering_define_placement[#1][#2]%
425   {\doifnextbgroupelse
426      {\strc_rendering_define_placement_yes[#1][#2]}%
427      {\strc_rendering_define_placement_nop[#1][#2]}}
429 \def\strc_rendering_define_placement_yes[#1][#2]%
430   {\defineheadalternative[#1][\c!alternative=#2,\c!renderingsetup=\??headrenderings:\v!command]%
431    \setuvalue{\??headplacementalternative#1}##1##2}
433 \def\strc_rendering_define_placement_nop[#1][#2]%
434   {\defineheadalternative[#1][\c!alternative=#2,\c!renderingsetup=\??headrenderings:\v!command]%
435    \setuvalue{\??headplacementalternative#1}}
437 % these can be used in setups:
439 % \headnumbercontent
440 % \headtextcontent
442 % \headwidth
443 % \headtextwidth
444 % \headnumberdistance
445 % \headnumberwidth
446 % \headsetupspacing
448 % \headshownumber
449 % \headisdisplay
451 \let\headnumbercontent\empty
452 \let\headtextcontent  \empty
454 \newdimen\headwidth
455 \newdimen\headtextwidth
456 \newdimen\headnumberdistance
457 \newdimen\headnumberwidth
459 % \newconditional\headshownumber % defined already
460 % \newconditional\headisdisplay  % defined already
462 \unexpanded\def\strc_rendering_initialize_alternatives
463   {\edef\currentheadalternative{\headparameter\c!alternative}%
464    \ifcsname\currentheadalternativehash\s!parent\endcsname \else
465       \let\currentheadalternative\v!normal % cf. mkii
466    \fi
467    \edef\currentheadrenderingsetup{\headalternativeparameter\c!renderingsetup}%
468    \edef\currentheadrenderingalternative{\headalternativeparameter\c!alternative}%
469    \ifx\currentheadrenderingalternative\empty
470      \let\currentheadrenderingalternative\v!vertical
471    \fi
472    \ifx\currentheadrenderingalternative\v!horizontal
473      \global\setfalse\headisdisplay % global
474    \else
475      \global\settrue\headisdisplay  % global
476    \fi}
478 \unexpanded\def\strc_rendering_initialize_dimensions
479   {\headwidth         \headparameter\c!width      \relax  % \zeropoint == unset
480    \headnumberwidth   \headparameter\c!numberwidth\relax  % \zeropoint == unset
481    \headnumberdistance\headparameter\c!distance   \relax
482    \headtextwidth     \headparameter\c!textwidth  \relax} % \zeropoint == unset
484 \unexpanded\def\headtextcontent
485   {\begingroup
486      \strc_rendering_initialize_style_and_color\c!textstyle\c!textcolor
487      \headparameter\c!commandbefore\relax
488      \ifcsname\currentheadhash\c!deeptextcommand\endcsname
489        \expandafter\let\expandafter\deepstructuretitlecommand\csname\currentheadhash\c!deeptextcommand\endcsname
490      \fi
491      \ifconditional\headisdisplay
492        % struts can be nilled with \setnostrut
493        \headparameter\c!textcommand{\setstrut\begstrut\getheadtitle\endstrut}%
494        \global\d_strc_rendering_local_height\strutht
495        \global\d_strc_rendering_local_depth\strutdp
496        \global\d_strc_rendering_local_lineheight\lineheight
497        \headparameter\c!commandafter\relax
498        \endgraf
499      \else
500        \headparameter\c!textcommand{\getheadtitle}%
501        \headparameter\c!commandafter\relax
502      \fi
503    \endgroup}
505 \unexpanded\def\headnumbercontent
506   {\begingroup
507      \strc_rendering_initialize_style_and_color\c!numberstyle\c!numbercolor
508      \ifcsname\currentheadhash\c!deepnumbercommand\endcsname
509        \expandafter\let\expandafter\deepstructurenumbercommand\csname\currentheadhash\c!deepnumbercommand\endcsname
510      \fi
511      \ifconditional\headisdisplay
512        % can be nilled with \setnostrut
513        \headparameter\c!numbercommand{\setstrut\begstrut\getheadnumber\endstrut}%
514      \else
515        \headparameter\c!numbercommand{\getheadnumber}%
516      \fi
517    \endgroup}
519 \unexpanded\def\strc_rendering_inject_number_and_text
520   {\edef\p_command{\headparameter\c!command}% assumes \unexpanded definition
521    \ifx\p_command\empty
522      \directsetup\currentheadrenderingsetup
523    \else
524      \p_command\headnumbercontent\headtextcontent
525    \fi}
527 \unexpanded\def\strc_rendering_inject_text
528   {\edef\p_command{\headparameter\c!command}% assumes \unexpanded definition
529    \ifx\p_command\empty
530      \directsetup\currentheadrenderingsetup
531    \else
532      \p_command\empty\headtextcontent
533    \fi}
535 \startsetups[\??headrenderings:\v!command]
536     \csname\??headplacementalternative\currentheadalternative\endcsname \headnumbercontent \headtextcontent
537 \stopsetups
539 % obsolete
541 % \def\normalplacehead % hooks into \c!command
542 %   {\csname\??headplacementalternative\ifcsname\??headplacementalternative\currentheadalternative\endcsname\currentheadalternative\else\v!normal\fi\endcsname}
544 \defineheadalternative
545   [\v!paragraph]
546   [\c!alternative=\v!vertical,
547    \c!renderingsetup=\??headrenderings:\v!paragraph]
549 \startsetups[\??headrenderings:\v!paragraph]
550     \vbox {
551         \headsetupspacing
552         \begstrut
553         \ifconditional\headshownumber % \ifheadnumbercontent
554             \headnumbercontent
555             \hskip\headnumberdistance
556         \fi
557         \headtextcontent
558     }
559 \stopsetups
561 % \setuphead
562 %   [chapter]
563 %   [numberwidth=2cm,hang=line,after={\blank[3*line]}]
565 % \chapter{Oeps oeps oeps} \input tufte   \section{Oeps}
566 % \chapter{Oeps oeps oeps} \section{Oeps} \input tufte
568 \defineheadalternative
569   [\v!normal]
570   [\c!alternative=\v!vertical,
571    \c!renderingsetup=\??headrenderings:\v!normal]
573 \startsetups[\??headrenderings:\v!normal]
574     \vbox {
575         \headsetupspacing
576         \ifconditional\headshownumber
577             \ifdim\headwidth=\zeropoint \else
578                 \ifdim\headnumberwidth=\zeropoint
579                     \ifdim\headtextwidth=\zeropoint \else
580                         \headnumberwidth\dimexpr\headwidth-\headtextwidth\relax
581                     \fi
582                 \else
583                     \ifdim\headtextwidth=\zeropoint
584                         \headtextwidth\dimexpr\headwidth-\headnumberwidth\relax
585                     \fi
586                 \fi
587                 \hsize\headwidth
588             \fi
589             \ifdim\headnumberwidth=\zeropoint\else
590                 \headnumberdistance\zeropoint
591             \fi
592             \setbox\scratchbox\hbox \ifdim\headnumberwidth=\zeropoint\else to \headnumberwidth\fi{\headnumbercontent}
593             \scratchdimen\dimexpr\wd\scratchbox+\headnumberdistance\relax
594             \ifdim\headtextwidth=\zeropoint\else
595                 \hsize\dimexpr\scratchdimen+\headtextwidth\relax
596             \fi
597             \hangindent\scratchdimen
598             \hangafter \plusone
599             \noindent
600             \box\scratchbox
601             \hskip\headnumberdistance
602         \else
603             \ifdim\headtextwidth=\zeropoint
604                 \ifdim\headwidth=\zeropoint \else
605                     \hsize\headwidth
606                 \fi
607             \else
608                 \hsize\headtextwidth
609             \fi
610             \noindent
611         \fi
612         \headtextcontent
613     }
614 \stopsetups
616 \defineheadalternative
617   [\v!inmargin]
618   [\c!alternative=\v!vertical,
619    \c!renderingsetup=\??headrenderings:\v!inmargin]
621 \startsetups[\??headrenderings:\v!inmargin]
622     \vbox {
623         \headsetupspacing
624         \begstrut % use one \strut here!
625         \dontleavehmode % in case there is no strut, else side effects with llap
626         \ifconditional\headshownumber
627             \llap {
628                 \signalrightpage
629                 \hbox {
630                     \hfill
631                     \headnumbercontent
632                     \doifrightpageelse{
633                         \scratchdistance\leftmargindistance
634                     } {
635                         \scratchdistance\rightmargindistance
636                     }
637                     \hskip\dimexpr\d_strc_rendering_local_leftoffset+\scratchdistance\relax
638                 }
639             }
640         \fi
641         \headtextcontent
642     }
643 \stopsetups
645 \defineheadalternative
646   [\v!margin]
647   [\v!inmargin]
649 % \startsetups[\??headrenderings:\v!vertical:\v!margin]
650 %     \directsetup{\??headrenderings:\v!vertical:\v!inmargin}
651 % \stopsetups
653 \defineheadalternative
654   [\v!middle]
655   [\c!alternative=\v!vertical,
656    \c!renderingsetup=\??headrenderings:\v!middle]
658 \startsetups[\??headrenderings:\v!middle]
659     \vbox {
660         \headsetupspacing
661         \veryraggedcenter
662         \let\\\endgraf
663         \let\crlf\endgraf
664         \ifconditional\headshownumber
665             \strut
666             \headnumbercontent
667             \par
668         \fi
669         \begstrut
670         \headtextcontent
671         \endstrut
672     }
673 \stopsetups
675 \defineheadalternative
676   [\v!text]
677   [\c!alternative=\v!horizontal,
678    \c!renderingsetup=\??headrenderings:\v!text]
680 \startsetups[\??headrenderings:\v!text]
681     \begingroup
682     \headsetupspacing % no stretch in distance
683     \ifconditional\headshownumber
684         \headnumbercontent
685         \kern\headnumberdistance
686     \fi
687     \begstrut
688     \headtextcontent
689     \endstrut
690     \endgroup
691 \stopsetups
693 % onder/boven lijnt het nummer op de onderste/bovenste regel uit van een meerregelige kop
695 \defineheadalternative
696   [\v!bottom]
697   [\c!alternative=\v!vertical,
698    \c!renderingsetup=\??headrenderings:\v!bottom]
700 \startsetups[\??headrenderings:\v!bottom]
701     \ifconditional\headshownumber
702         \setbox0\hbox {
703             \headnumbercontent
704         }
705         \setbox2\vbox {
706             \headsetupspacing
707             \advance\hsize-\wd0\relax
708             \headtextcontent
709         }
710         \hbox {
711             \box0
712             \hskip\headnumberdistance
713             \box2
714         }
715     \else
716         \vbox {
717             \headsetupspacing
718             \noindent
719             \headtextcontent
720         }
721     \fi
722 \stopsetups
724 \defineheadalternative
725   [\v!top]
726   [\c!alternative=\v!vertical,
727    \c!renderingsetup=\??headrenderings:\v!top]
729 \startsetups[\??headrenderings:\v!top]
730     \ifconditional\headshownumber
731         \setbox0\hbox {
732             \headnumbercontent
733         }
734         \setbox2\vtop {
735             \headsetupspacing
736             \advance\hsize-\wd0\relax
737             \headtextcontent
738         }
739         \hbox {
740             \box0
741             \hskip\headnumberdistance
742             \box2
743         }
744     \else
745         \vtop{
746             \headsetupspacing
747             \noindent
748             \headtextcontent
749         }
750     \fi
751 \stopsetups
753 \protect \endinput