strc-ren.mkiv /size: 28 Kb    last modification: 2023-12-21 09:44
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.
13
14\writestatus{loading}{ConTeXt Structure Macros / Section Rendering}
15
16\unprotect
17
18\newbox\b_strc_rendering_head
19
20\newdimen\d_strc_rendering_local_leftoffset
21\newdimen\d_strc_rendering_local_rightoffset
22
23% Martin Kolarik's problem:
24%
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}
28
29% \newtoks\everyheadstart % not used currently
30
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}
37
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}
67
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}
80
81\let\currentstructurereferenceattribute\attributeunsetvalue
82
83\def\headreferenceattributes
84  {\iflocation
85   % \ctxlua{structures.lists.taglocation(\the\locationcount)}% maybe ... tags entry as used
86     attr \destinationattribute \currentstructureattribute
87     attr \referenceattribute   \currentstructurereferenceattribute
88   % attr \internalattribute    \locationcount
89   \fi}
90
91\def\setinlineheadreferenceattributes
92  {\ifconditional\headisdisplay \else \iflocation
93     \c_attr_destination\currentstructureattribute
94     \c_attr_reference  \currentstructurereferenceattribute
95   % \c_attr_internal   \locationcount
96   \fi \fi}
97
98\def\docheckheadreference
99  {\edef\currentheadinteraction{\headparameter\c!interaction}%
100   \ifx\currentheadinteraction\v!list
101     % setuphead[<section>][interaction=list,...]
102     \strc_references_get_simple_reference{*\the\locationcount}%
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_reference\currentheadbackreference
109       \let\currentstructurereferenceattribute\currentreferenceattribute
110     \fi
111   \else
112      % maybe auto: backreference when given, else list
113   \fi\fi}
114
115% a bit messy ... empty in place instead of self .. might change (or use special
116% whatsig (invisible user one)
117
118\unexpanded\def\strc_rendering_place_head_text
119  {\strc_rendering_start_placement
120   \setheadmarking
121   \doresetstructureheadnumbercontent
122   \ifconditional\c_strc_sectioning_empty
123     \setbox\b_strc_rendering_head\hpack \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        \doresetstructureheadnumbercontent
129        \useheadstyleparameter\c!style
130        \setinlineheadreferenceattributes
131        \strc_rendering_inject_text}%
132   \fi
133   \strc_rendering_stop_placement}
134
135\unexpanded\def\strc_rendering_place_head_number_and_text
136  {\strc_rendering_start_placement
137   \setheadmarking
138   \doifelsetext\getheadnumber
139     \dosetstructureheadnumbercontent
140     \doresetstructureheadnumbercontent
141   \ifconditional\c_strc_sectioning_empty
142     \setbox\b_strc_rendering_head\hpack \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}
152
153\unexpanded\def\strc_rendering_place_head_empty
154  {\hpack\headreferenceattributes{\getheadsyncs}}
155
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}}}
161%D
162%D \definehead[MySubject][subject]
163%D \setuphead [MySubject][deeptextcommand=\StretchedBox]
164%D
165%D \MySubject{feeling stretched feeling stretched feeling stretched feeling stretched}
166%D \stoptyping
167
168% helpers
169
170\unexpanded\def\headhbox{\hbox\headreferenceattributes}
171\unexpanded\def\headvbox{\vbox\headreferenceattributes}
172
173\unexpanded\def\startlocalheadsetup{\bgroup\strc_rendering_initialize_spacing}
174\unexpanded\def\stoplocalheadsetup {\egroup}
175
176\unexpanded\def\strc_rendering_initialize_spacing
177  {\forgetall % local !
178   \edef\p_align{\headparameter\c!align}%
179   \ifx\p_align\empty \else
180     \setupalign[\p_align]%
181   \fi
182   \edef\p_tolerance{\headparameter\c!tolerance}%
183   \ifx\p_tolerance\empty \else
184     \setuptolerance[\p_tolerance]%
185   \fi
186   \edef\p_strut{\headparameter\c!strut}%
187   \ifx\p_strut\v!no
188     \setnostrut
189   \fi
190   \enforced\let\\\strc_rendering_shortcut_backslash}
191
192\unexpanded\def\strc_rendering_shortcut_backslash
193  {\crlf
194   \strut
195   \ignorespaces}
196
197\def\strc_rendering_start_placement
198  {\bgroup
199   \setsystemmode\currenthead
200   \strc_rendering_initialize_alternatives
201   \strc_rendering_initialize_dimensions
202   \strc_rendering_initialize_line_state
203   \reseteverypar % needed indeed
204   \noindent      % ipv \whitespace elders, na \forgetall !
205   \bgroup
206   \synctexpushline
207   \edef\p_aligntitle{\headparameter\c!aligntitle}%
208   \ifx\p_aligntitle\v!yes
209     \strc_rendering_initialize_hsize_local
210   \else\ifx\p_aligntitle\v!float
211     \strc_rendering_initialize_hsize_local
212   \else
213     \strc_rendering_initialize_hsize_global
214   \fi\fi
215   \setfalse\inhibitmargindata % brrrr is set in forgetall
216   \dontcomplain
217   \postponenotes
218   \strc_rendering_initialize_interaction
219   % delayed
220   \let\localheadsetup  \strc_rendering_initialize_spacing % historic name
221   \let\headsetupspacing\strc_rendering_initialize_spacing}
222
223\def\strc_rendering_initialize_interaction
224  {\resetinteractionparameter\c!style
225   \resetinteractionparameter\c!color
226   \resetinteractionparameter\c!contrastcolor}
227
228% \setuphead[chapter]         [style=\bfd,after=,hang=line] % fit broad 2
229% \setuphead[section]         [style=\bfc,after=,hang=line]
230% \setuphead[subsection]      [style=\bfb,after=,hang=line]
231% \setuphead[subsubsection]   [style=\bfa,after=,hang=line]
232% \setuphead[subsubsubsection][style=\bf ,after=,hang=line]
233%
234% \chapter         {Test} \input tufte \page
235% \section         {Test} \input tufte \page
236% \subsection      {Test} \input tufte \page
237% \subsubsection   {Test} \input tufte \page
238% \subsubsubsection{Test} \input tufte \page
239%
240% \chapter         {Test\\Test} \input tufte \page
241% \section         {Test\\Test} \input tufte \page
242% \subsection      {Test\\Test} \input tufte \page
243% \subsubsection   {Test\\Test} \input tufte \page
244% \subsubsubsection{Test\\Test} \input tufte \page
245
246\newdimen\d_strc_rendering_hang_height
247\newcount\n_strc_rendering_hang_lines
248
249\newdimen\d_strc_rendering_local_height
250\newdimen\d_strc_rendering_local_depth
251\newdimen\d_strc_rendering_local_lineheight
252
253\def\strc_rendering_initialize_line_state
254  {\global\d_strc_rendering_local_height\strutht
255   \global\d_strc_rendering_local_depth\strutdp
256   \global\d_strc_rendering_local_lineheight\lineheight}
257
258\def\strc_rendering_check_hang
259  {\begingroup
260   \openlineheight\d_strc_rendering_local_lineheight
261   \d_strc_rendering_hang_height\htdp\b_strc_rendering_head
262   \getnoflines\d_strc_rendering_hang_height
263   \normalexpanded{\endgroup\n_strc_rendering_hang_lines\the\numexpr\noflines-\plusone\relax}% brrr
264   \setbox\b_strc_rendering_head\hpack{\lower\n_strc_rendering_hang_lines\d_strc_rendering_hang_height\box\b_strc_rendering_head}%
265   \d_strc_rendering_hang_height\dimexpr\htdp\b_strc_rendering_head-\d_strc_rendering_local_height+\strutdp\relax
266   \ht\b_strc_rendering_head\strutht
267   \dp\b_strc_rendering_head\strutdp
268   \d_strc_rendering_local_depth\strutdp}
269
270\installcorenamespace{headplacementcheckhang}
271
272\setvalue{\??headplacementcheckhang\v!line   }{\strc_rendering_check_hang
273                                               \n_strc_rendering_hang_lines\zerocount}
274\setvalue{\??headplacementcheckhang\v!broad  }{\strc_rendering_check_hang
275                                               \getnoflines\d_strc_rendering_hang_height}
276\setvalue{\??headplacementcheckhang\v!fit    }{\strc_rendering_check_hang
277                                               \getrawnoflines\d_strc_rendering_hang_height}
278\setvalue{\??headplacementcheckhang\v!none   }{\n_strc_rendering_hang_lines\zerocount}
279\setvalue{\??headplacementcheckhang          }{\n_strc_rendering_hang_lines\zerocount}
280\setvalue{\??headplacementcheckhang\s!unknown}{\strc_rendering_check_hang
281                                               \n_strc_rendering_hang_lines\numexpr\headparameter\c!hang-\plusone\relax}
282
283\def\strc_rendering_initialize_line_hang
284   {\ifconditional\headisdisplay
285      \expandnamespaceparameter\??headplacementcheckhang\headparameter\c!hang\s!unknown
286      \relax
287    \else
288      \n_strc_rendering_hang_lines \zerocount
289      \d_strc_rendering_hang_height\zeropoint
290    \fi}
291
292\def\strc_rendering_initialize_hsize_local
293  {\global\d_strc_rendering_local_leftoffset \leftskip
294   \global\d_strc_rendering_local_rightoffset\rightskip
295 % \forgetall
296 % \leftskip \d_strc_rendering_local_leftoffset  % no stretch
297 % \rightskip\d_strc_rendering_local_rightoffset % no stretch
298 % \setlocalhsize
299 % \hsize\localhsize
300 % \forgetbothskips}
301   \scratchwidth\availablehsize
302   \forgetall
303   \hsize\scratchwidth}
304
305\def\strc_rendering_initialize_hsize_global
306  {\global\d_strc_rendering_local_leftoffset \zeropoint
307   \global\d_strc_rendering_local_rightoffset\zeropoint
308   \forgetall}
309
310% \def\strc_sectioning_stay_on_this_line
311%   {\directcheckedvspacing{-\v!line,\v!samepage,\v!nowhite}%
312%    \directcheckedvspacing\v!disable}
313%
314% we now use \ignoreparskip, so:
315
316\def\strc_sectioning_stay_on_this_line
317  {\directcheckedvspacing{-\v!line,\v!samepage}%
318   \directcheckedvspacing\v!disable}
319
320\def\strc_rendering_stop_placement
321  {\n_strc_rendering_hang_lines\zerocount
322   \ifconditional\headisdisplay
323     \strc_rendering_initialize_line_hang
324     % kind of special, we want to snap heads also according to local specs local
325     \setbox\b_strc_rendering_head\hbox
326       {\hskip\dimexpr\d_strc_rendering_local_leftoffset+\headparameter\c!margin\relax
327        \box\b_strc_rendering_head
328        \getheadsyncs % a latelua why not in the box
329        }%
330     \ifgridsnapping
331       \applygridmethod
332         {\headparameter\c!grid}%
333         {\ifconditional\headisdisplay
334            \strc_rendering_initialize_style_and_color_display\c!textstyle\c!textcolor
335          \fi}%
336         {\box\b_strc_rendering_head}
337     \else
338       \box\b_strc_rendering_head
339     \fi
340     \flushnotes % new, not really needed
341     \endgraf
342     \ifvmode
343       \ifnum\n_strc_rendering_hang_lines>\zerocount
344         \dorecurse\n_strc_rendering_hang_lines{\nointerlineskip\dosomebreak\nobreak\strut\endgraf}% to be checked
345       \fi
346       \nointerlineskip
347       \dosomebreak\nobreak
348     \fi
349%      \getheadsyncs % a latelua why not in the box
350   \else
351     % somehow this goes ok even when we push in the margin probably because we gobble pars
352     % in the process of collecting index entries etc
353     \strut
354     \flushnotes % new, here since we're in par mode
355     \unhbox\b_strc_rendering_head
356     \getheadsyncs % a latelua
357     \ifconditional\headissomewhere
358       \strc_sectioning_stay_on_this_line % test case: alternative=margintext and \startparagraph ..
359     \else
360      %\hskip\headnumberdistance\s!plus\headnumberdistance\s!minus.25\dimexpr\headnumberdistance\relax
361       \hskip\headtextdistance\relax
362       \strc_sectioning_inject_continuous_signal
363     \fi
364   \fi
365   \ifconditional\headisdisplay
366     \ifvmode
367       \ifgridsnapping % important, font related depth, see comment
368         \prevdepth\strutdp
369       \else
370         \prevdepth\d_strc_rendering_local_depth
371       \fi
372     \fi
373   \fi
374   \synctexpopline
375   \egroup
376   \egroup
377   \ifconditional\headisdisplay
378     \useindentnextparameter\headparameter
379   \else\ifconditional\headissomewhere
380     \ignoreparskip
381     \noindentation
382   \else
383     \ignoreparskip
384     \doindentation
385   \fi\fi}
386
387% nice testcase
388%
389% \setupheads[aligntitle=yes]
390%
391% \startnarrower
392%   \subject{\dorecurse{100}{x }}
393%   \section{\dorecurse{100}{x }}
394%   \input tufte \par
395%   \setupheads[alternative=inmargin]
396%   \subject{\dorecurse{100}{x }}
397%   \section{\dorecurse{100}{x }}
398%   \input tufte \par
399% \stopnarrower
400
401% \dodefineheadplacement[sectiona][vertical]{#1->#2}
402% \dodefineheadplacement[sectionb][vertical]#1#2{#1->#2}
403%
404% \setuphead[section][alternative=sectiona]
405% \setuphead[subsection][alternative=sectionb]
406
407% \startsetups[\??headrenderings:\v!vertical:\v!sectiona]
408%     ... there will be a more public namespace
409% \stopsetups
410
411\installcorenamespace{headplacementalternative}
412\installcorenamespace{headrenderings}
413\installcorenamespace{headalternative}
414
415\installcommandhandler \??headalternative {headalternative} \??headalternative % or just \??head
416
417\setupheadalternative
418  [%\c!width=\headparameter\c!width,
419   %\c!distance=\headparameter\c!distance,
420   \c!alternative=\v!vertical,
421   \c!renderingsetup=\??headrenderings:\currentheadalternative]
422
423\let\currentheadalternative         \v!normal
424\let\currentheadrenderingsetup      \empty
425\let\currentheadrenderingalternative\v!vertical
426
427\unexpanded\def\defineheadplacement % old mechanism
428  {\dodoubleargument\strc_rendering_define_placement}
429
430\def\strc_rendering_define_placement[#1][#2]%
431  {\doifelsenextbgroup
432     {\strc_rendering_define_placement_yes[#1][#2]}%
433     {\strc_rendering_define_placement_nop[#1][#2]}}
434
435\def\strc_rendering_define_placement_yes[#1][#2]%
436  {\defineheadalternative[#1][\c!alternative=#2,\c!renderingsetup=\??headrenderings:\v!command]%
437   \setuvalue{\??headplacementalternative#1}##1##2}
438
439\def\strc_rendering_define_placement_nop[#1][#2]%
440  {\defineheadalternative[#1][\c!alternative=#2,\c!renderingsetup=\??headrenderings:\v!command]%
441   \setuvalue{\??headplacementalternative#1}}
442
443% these can be used in setups:
444%
445% \headnumbercontent
446% \headtextcontent
447%
448% \headwidth
449% \headtextwidth
450% \headnumberdistance
451% \headnumberwidth
452% \headsetupspacing
453%
454% \headshownumber
455% \headisdisplay
456
457\let\headnumbercontent\empty
458\let\headtextcontent  \empty
459
460\newdimen\headwidth
461\newdimen\headtextwidth
462\newskip \headtextdistance
463\newdimen\headnumberdistance
464\newdimen\headnumberwidth
465
466% \newconditional\headshownumber % defined already
467% \newconditional\headisdisplay  % defined already
468
469\unexpanded\def\strc_rendering_initialize_alternatives
470  {\edef\currentheadalternative{\headparameter\c!alternative}%
471   \ifcsname\currentheadalternativehash\s!parent\endcsname \else
472      \let\currentheadalternative\v!normal % cf. mkii
473   \fi
474   \edef\currentheadrenderingsetup{\headalternativeparameter\c!renderingsetup}%
475   \edef\currentheadrenderingalternative{\headalternativeparameter\c!alternative}%
476   \ifx\currentheadrenderingalternative\empty
477     \let\currentheadrenderingalternative\v!vertical
478   \fi
479   \ifx\currentheadrenderingalternative\v!horizontal
480     \global\setfalse\headisdisplay   % global
481     \global\setfalse\headissomewhere % global
482   \else\ifx\currentheadrenderingalternative\v!somewhere
483     \global\setfalse\headisdisplay   % global
484     \global\settrue \headissomewhere % global
485   \else
486     \global\settrue \headisdisplay   % global
487     \global\setfalse\headissomewhere % global
488   \fi\fi}
489
490\unexpanded\def\strc_rendering_initialize_dimensions
491  {\headwidth         \headparameter\c!width       \relax  % \zeropoint == unset
492   \headnumberwidth   \headparameter\c!numberwidth \relax  % \zeropoint == unset
493   \headnumberdistance\headparameter\c!distance    \relax
494   \headtextdistance  \headparameter\c!textdistance\relax
495   \headtextwidth     \headparameter\c!textwidth   \relax} % \zeropoint == unset
496
497\unexpanded\def\headtextcontent
498  {\begingroup
499     \strc_rendering_initialize_style_and_color\c!textstyle\c!textcolor
500     \headparameter\c!commandbefore\relax
501     \ifcsname\currentheadhash\c!deeptextcommand\endcsname
502      %\expandafter\let\expandafter\deepstructuretitlecommand\csname\currentheadhash\c!deeptextcommand\endcsname
503       \expandafter\let\expandafter\deepstructuretitlecommand\lastnamedcs
504     \fi
505     \ifconditional\headisdisplay
506       % struts can be nilled with \setnostrut
507       \headparameter\c!textcommand{\setstrut\begstrut\getheadtitle\endstrut}%
508       \global\d_strc_rendering_local_height\strutht
509       \global\d_strc_rendering_local_depth\strutdp
510       \global\d_strc_rendering_local_lineheight\lineheight
511       \headparameter\c!commandafter\relax
512       \endgraf
513     \else
514       \headparameter\c!textcommand{\getheadtitle}%
515       \headparameter\c!commandafter\relax
516     \fi
517   \endgroup}
518
519\unexpanded\def\headnumbercontent
520  {\begingroup
521     \strc_rendering_initialize_style_and_color\c!numberstyle\c!numbercolor
522     \ifcsname\currentheadhash\c!deepnumbercommand\endcsname
523      %\expandafter\let\expandafter\deepstructurenumbercommand\csname\currentheadhash\c!deepnumbercommand\endcsname
524       \expandafter\let\expandafter\deepstructurenumbercommand\lastnamedcs
525     \fi
526     \ifconditional\headisdisplay
527       % can be nilled with \setnostrut
528       \headparameter\c!numbercommand{\setstrut\begstrut\getheadnumber\endstrut}%
529     \else
530       \headparameter\c!numbercommand{\getheadnumber}%
531     \fi
532   \endgroup}
533
534\def\fakedheadnumber{\vphantom{0}} % needed for mathplus
535
536% \unexpanded\def\fakeheadnumbercontent
537%   {\hbox to \zeropoint{\let\getheadnumber\fakedheadnumber\headnumbercontent}}
538
539\unexpanded\def\fakeheadnumbercontent
540  {\edef\p_hidenumber{\headparameter\c!hidenumber}%
541   \ifx\p_hidenumber\v!yes\else
542     \hbox to \zeropoint{\let\getheadnumber\fakedheadnumber\headnumbercontent}%
543   \fi}
544
545\unexpanded\def\strc_rendering_inject_number_and_text
546  {\edef\p_command{\headparameter\c!command}% assumes \unexpanded definition
547   \ifx\p_command\empty
548     \directsetup\currentheadrenderingsetup
549   \else
550     \p_command\headnumbercontent\headtextcontent
551   \fi}
552
553\unexpanded\def\strc_rendering_inject_text
554  {\edef\p_command{\headparameter\c!command}% assumes \unexpanded definition
555   \ifx\p_command\empty
556     \directsetup\currentheadrenderingsetup
557   \else
558     \p_command\empty\headtextcontent
559   \fi}
560
561\startsetups[\??headrenderings:\v!command]
562    \csname\??headplacementalternative\currentheadalternative\endcsname \headnumbercontent \headtextcontent
563\stopsetups
564
565% obsolete
566%
567% \def\normalplacehead % hooks into \c!command
568%   {\csname\??headplacementalternative\ifcsname\??headplacementalternative\currentheadalternative\endcsname\currentheadalternative\else\v!normal\fi\endcsname}
569
570\defineheadalternative
571  [\v!paragraph]
572  [\c!alternative=\v!vertical,
573   \c!renderingsetup=\??headrenderings:\v!paragraph]
574
575\startsetups[\??headrenderings:\v!paragraph]
576    \vbox {
577        \headsetupspacing
578        \begstrut
579        \ifconditional\headshownumber % \ifheadnumbercontent
580            \headnumbercontent
581            \hskip\headnumberdistance
582        \fi
583        \headtextcontent
584    }
585\stopsetups
586
587% \setuphead
588%   [chapter]
589%   [numberwidth=2cm,hang=line,after={\blank[3*line]}]
590%
591% \chapter{Oeps oeps oeps} \input tufte   \section{Oeps}
592% \chapter{Oeps oeps oeps} \section{Oeps} \input tufte
593
594\defineheadalternative
595  [\v!normal]
596  [\c!alternative=\v!vertical,
597   \c!renderingsetup=\??headrenderings:\v!normal]
598
599\startsetups[\??headrenderings:\v!normal]
600    \vbox {
601        \headsetupspacing
602        \ifconditional\headshownumber
603            \ifzeropt\headwidth \else
604                \ifzeropt\headnumberwidth
605                    \ifzeropt\headtextwidth \else
606                        \headnumberwidth\dimexpr\headwidth-\headtextwidth\relax
607                    \fi
608                \else
609                    \ifzeropt\headtextwidth
610                        \headtextwidth\dimexpr\headwidth-\headnumberwidth\relax
611                    \fi
612                \fi
613                \hsize\headwidth
614            \fi
615            \ifzeropt\headnumberwidth \else
616                \headnumberdistance\zeropoint
617            \fi
618            \setbox\scratchbox\hbox \ifzeropt\headnumberwidth\else to \headnumberwidth\fi{\headnumbercontent}
619            \scratchdimen\dimexpr\wd\scratchbox+\headnumberdistance\relax
620            \ifzeropt\headtextwidth \else
621                \hsize\dimexpr\scratchdimen+\headtextwidth\relax
622            \fi
623            \hangindent\scratchdimen
624            \hangafter \plusone
625            \noindent
626            \box\scratchbox
627            \hskip\headnumberdistance
628        \else
629            \ifzeropt\headtextwidth
630                \ifzeropt\headwidth \else
631                    \hsize\headwidth
632                \fi
633            \else
634                \hsize\headtextwidth
635            \fi
636            \noindent
637            \fakeheadnumbercontent % will also be done in the other ones (force consistency with numbered)
638        \fi
639        \headtextcontent
640    }
641\stopsetups
642
643\defineheadalternative
644  [\v!inmargin]
645  [\c!alternative=\v!vertical,
646   \c!renderingsetup=\??headrenderings:\v!inmargin]
647
648% \startsetups[\??headrenderings:\v!inmargin]
649%     \vbox {
650%         \headsetupspacing
651%         \begstrut % use one \strut here!
652%         \dontleavehmode % in case there is no strut, else side effects with llap
653%         \ifconditional\headshownumber
654%             \llap {
655%                 \signalrightpage
656%                 \hbox {
657%                     \hfill
658%                     \headnumbercontent
659%                     \doifelserightpage{
660%                         \scratchdistance\leftmargindistance
661%                     } {
662%                         \scratchdistance\rightmargindistance
663%                     }
664%                     \hskip\dimexpr\d_strc_rendering_local_leftoffset+\scratchdistance\relax
665%                 }
666%             }
667%         \else
668%             \fakeheadnumbercontent % will also be done in the other ones (force consistency with numbered)
669%         \fi
670%         \headtextcontent
671%     }
672% \stopsetups
673
674\startsetups[\??headrenderings:\v!inmargin]
675    \vbox {
676        \headsetupspacing
677        \dontleavehmode % in case there is no strut, else side effects with llap
678        \begstrut % use one \strut here!
679        \ifconditional\headshownumber
680            \doifelsesomething {\headparameter\c!location} {
681                % kind of new
682                \margindata [\headparameter\c!location] {
683                    \headnumbercontent
684                }
685            } {
686                % normal backward compatible variant
687                \llap {
688                    \signalrightpage
689                    \hbox {
690                        \hfill
691                        \headnumbercontent
692                        \doifelserightpage{
693                            \scratchdistance\leftmargindistance
694                        } {
695                            \scratchdistance\rightmargindistance
696                        }
697                        \hskip\dimexpr\d_strc_rendering_local_leftoffset+\scratchdistance\relax
698                    }
699                }
700            }
701        \else
702            \fakeheadnumbercontent % will also be done in the other ones (force consistency with numbered)
703        \fi
704        \headtextcontent
705    }
706\stopsetups
707
708\defineheadalternative
709  [\v!margin]
710  [\v!inmargin]
711
712% \startsetups[\??headrenderings:\v!vertical:\v!margin]
713%     \directsetup{\??headrenderings:\v!vertical:\v!inmargin}
714% \stopsetups
715
716%D This one is for head based numbering usage: foo 1.2 and so:
717
718\defineheadalternative
719  [\v!reverse]
720  [\c!alternative=\v!vertical,
721   \c!renderingsetup=\??headrenderings:\v!reverse]
722
723\startsetups[\??headrenderings:\v!reverse]
724    \vbox {
725        \headsetupspacing
726        \noindent
727        \begstrut
728        \setfalse\headisdisplay % so a kind of mix
729        \headtextcontent
730        \ifconditional\headshownumber
731            \kern\headnumberdistance
732            \headnumbercontent
733        \else
734            \fakeheadnumbercontent
735        \fi
736        \endstrut
737    }
738\stopsetups
739
740\defineheadalternative
741  [\v!middle]
742  [\c!alternative=\v!vertical,
743   \c!renderingsetup=\??headrenderings:\v!middle]
744
745\startsetups[\??headrenderings:\v!middle]
746    \vbox {
747        \headsetupspacing
748        \veryraggedcenter
749        \enforced\let\\\endgraf
750        \enforced\let\crlf\endgraf
751        \ifconditional\headshownumber
752            \strut
753            \headnumbercontent
754            \par
755        \else
756            \fakeheadnumbercontent
757        \fi
758        \begstrut
759        \headtextcontent
760        \endstrut
761    }
762\stopsetups
763
764\defineheadalternative
765  [\v!text]
766  [\c!alternative=\v!horizontal,
767   \c!renderingsetup=\??headrenderings:\v!text]
768
769\startsetups[\??headrenderings:\v!text]
770    \begingroup
771    \headsetupspacing % no stretch in distance
772    \ifconditional\headshownumber
773        \headnumbercontent
774        \kern\headnumberdistance
775    \fi
776    \begstrut
777    \headtextcontent
778    \endstrut
779    \endgroup
780\stopsetups
781
782% onder/boven lijnt het nummer op de onderste/bovenste regel uit van een meerregelige kop
783
784\defineheadalternative
785  [\v!bottom]
786  [\c!alternative=\v!vertical,
787   \c!renderingsetup=\??headrenderings:\v!bottom]
788
789\startsetups[\??headrenderings:\v!bottom]
790    \ifconditional\headshownumber
791        \setbox\scratchboxone\hbox {
792            \headnumbercontent
793        }
794        \setbox\scratchboxtwo\vbox {
795            \headsetupspacing
796            \advance\hsize-\wd\scratchboxone\relax
797            \headtextcontent
798        }
799        \hpack {
800            \box\scratchboxone
801            \hskip\headnumberdistance
802            \box\scratchboxtwo
803        }
804    \else
805        \vbox {
806            \headsetupspacing
807            \noindent
808            \headtextcontent
809        }
810    \fi
811\stopsetups
812
813\defineheadalternative
814  [\v!top]
815  [\c!alternative=\v!vertical,
816   \c!renderingsetup=\??headrenderings:\v!top]
817
818\startsetups[\??headrenderings:\v!top]
819    \ifconditional\headshownumber
820        \setbox\scratchboxone\hbox {
821            \headnumbercontent
822        }
823        \setbox\scratchboxtwo\vtop {
824            \headsetupspacing
825            \advance\hsize-\wd\scratchboxone\relax
826            \headtextcontent
827        }
828        \hpack {
829            \box\scratchboxone
830            \hskip\headnumberdistance
831            \box\scratchboxtwo
832        }
833    \else
834        \vtop{
835            \headsetupspacing
836            \noindent
837            \headtextcontent
838        }
839    \fi
840\stopsetups
841
842% see typo-mar.mkiv:
843%
844% \defineheadalternative
845%   [\v!margintext]
846
847\protect \endinput
848