strc-ren.mkxl /size: 27 Kb    last modification: 2025-02-21 11:03
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\newdimension\d_strc_rendering_local_leftoffset
20\newdimension\d_strc_rendering_local_rightoffset
21
22% Martin Kolarik's problem:
23%
24% \setuphead[section][command=\doTitle]
25% \def\doTitle#1#2{\ruledvbox{\forgetall \hsize=4cm \ruledhbox{\ruledvtop{#1}\ruledvtop{#2}}}}
26% \section{test test test test test test test test test test test test test test test test test}
27
28% \newtoks\everyheadstart % not used currently
29
30\protected\def\strc_rendering_initialize_style_and_color
31  {\ifconditional\headisdisplay
32     \expandafter\strc_rendering_initialize_style_and_color_display
33   \else
34     \expandafter\strc_rendering_initialize_style_and_color_inline
35   \fi}
36
37\protected\def\strc_rendering_initialize_style_and_color_display#1#2%
38  {\dontconvertfont
39   \edef\p_strc_rendering_interlinespace{\headparameter\c!interlinespace}%
40   \ifempty\p_strc_rendering_interlinespace
41     % here the interline space is only set when style sets no space
42     \fontattributeisset\conditionalfalse % use the currentfontparameter state instead
43     \interlinespaceisset\conditionalfalse
44     \useheadstyleandcolor\c!style\c!color\relax
45     \ifconditional\fontattributeisset \ifconditional\interlinespaceisset \else
46       \setupinterlinespace
47     \fi \fi
48     \fontattributeisset\conditionalfalse
49     \useheadstyleandcolor#1#2\relax
50     \ifconditional\fontattributeisset \ifconditional\interlinespaceisset \else
51       \setupinterlinespace
52     \fi \fi
53   \else
54     % here the set interline space overloads any other set space in the style
55     \fontattributeisset\conditionalfalse
56     \useheadstyleandcolor\c!style\c!color\relax
57     \ifconditional\fontattributeisset
58       \dosetupcheckedinterlinespace\p_strc_rendering_interlinespace
59     \fi
60     \fontattributeisset\conditionalfalse
61     \useheadstyleandcolor#1#2\relax
62     \ifconditional\fontattributeisset
63       \dosetupcheckedinterlinespace\p_strc_rendering_interlinespace
64     \fi
65   \fi}
66
67\protected\def\strc_rendering_initialize_style_and_color_inline#1#2%
68   {\dontconvertfont
69    \fontattributeisset\conditionalfalse
70    \useheadstyleandcolor\c!style\c!color\relax
71    \ifconditional\fontattributeisset
72      \updateraggedskips % \setupspacing
73    \fi
74    \fontattributeisset\conditionalfalse
75    \useheadstyleandcolor#1#2\relax
76    \ifconditional\fontattributeisset
77      \updateraggedskips % \setupspacing
78    \fi}
79
80\let\currentstructurereferenceattribute\attributeunsetvalue
81
82\permanent\def\headreferenceattributes
83  {\iflocation
84   % \ctxlua{structures.lists.taglocation(\the\locationcount)}% maybe ... tags entry as used
85     attr \destinationattribute \currentstructureattribute
86     attr \referenceattribute   \currentstructurereferenceattribute
87   % attr \internalattribute    \locationcount
88   \fi}
89
90\permanent\def\setinlineheadreferenceattributes
91  {\ifconditional\headisdisplay\orelse\iflocation
92     \c_attr_destination\currentstructureattribute
93     \c_attr_reference  \currentstructurereferenceattribute
94   % \c_attr_internal   \locationcount
95   \fi}
96
97\permanent\protected\def\docheckheadreference
98  {\edef\currentheadinteraction{\headparameter\c!interaction}%
99   \ifx\currentheadinteraction\v!list
100     % setuphead[<section>][interaction=list,...]
101     \strc_references_get_simple_reference{*\the\locationcount}%
102     \let\currentstructurereferenceattribute\currentreferenceattribute
103   \orelse\ifx\currentheadinteraction\v!reference
104     % setuphead[<section>][interaction=reference,...] start<section>[backreference=abc,...]
105     \edef\currentheadbackreference{\structurevariable\c!backreference}% weird, was references.backreference
106     \ifempty\currentheadbackreference \else
107       \strc_references_get_simple_reference\currentheadbackreference
108       \let\currentstructurereferenceattribute\currentreferenceattribute
109     \fi
110   \else
111      % maybe auto: backreference when given, else list
112   \fi}
113
114% a bit messy ... empty in place instead of self .. might change (or use special
115% whatsig (invisible user one)
116
117\protected\def\strc_rendering_place_head_text
118  {\strc_rendering_start_placement
119   \setheadmarking
120   \strc_sectioning_reset_head_number_content
121   \ifconditional\c_strc_sectioning_empty
122     \setbox\b_strc_rendering_head\hpack \headreferenceattributes to \zeropoint\bgroup
123\strc_rendering_initialize_interaction % moved here
124       \strut
125     \egroup
126   \else
127     \docheckheadreference
128     \setbox\b_strc_rendering_head\hbox \headreferenceattributes\bgroup
129\strc_rendering_initialize_interaction % moved here
130       \spac_grids_set_local_snapping{\headparameter\c!internalgrid}%
131       \strc_sectioning_reset_head_number_content
132       \useheadstyleparameter\c!style
133       \setinlineheadreferenceattributes
134       \strc_rendering_inject_text
135     \egroup
136   \fi
137   \strc_rendering_stop_placement}
138
139\protected\def\strc_rendering_place_head_number_and_text
140  {\strc_rendering_start_placement
141   \setheadmarking
142   \iftext\getheadnumber
143     \strc_sectioning_set_head_number_content
144   \else
145     \strc_sectioning_reset_head_number_content
146   \fi
147   \ifconditional\c_strc_sectioning_empty
148     \setbox\b_strc_rendering_head\hpack \headreferenceattributes to \zeropoint\bgroup
149\strc_rendering_initialize_interaction % moved here
150       \strut
151     \egroup
152   \else % = needed
153     \docheckheadreference
154     \setbox\b_strc_rendering_head\hbox \headreferenceattributes\bgroup
155\strc_rendering_initialize_interaction % moved here
156       \spac_grids_set_local_snapping{\headparameter\c!internalgrid}%
157       \useheadstyleparameter\c!style
158       \setinlineheadreferenceattributes
159       \strc_rendering_inject_number_and_text
160     \egroup
161   \fi
162   \strc_rendering_stop_placement}
163
164\protected\def\strc_rendering_place_head_empty
165  {\hpack\headreferenceattributes{\getheadsyncs}}
166
167%D \starttyping
168%D \def\StretchedBox#1%
169%D   {\framed
170%D      [frame=off,offset=.5em,align=middle,width=broad]
171%D      {\sc\def\stretchedspaceamount{.3em}\stretchednormalcase{#1}}}
172%D
173%D \definehead[MySubject][subject]
174%D \setuphead [MySubject][deeptextcommand=\StretchedBox]
175%D
176%D \MySubject{feeling stretched feeling stretched feeling stretched feeling stretched}
177%D \stoptyping
178
179% helpers
180
181\permanent\protected\def\headhbox{\hbox\headreferenceattributes}
182\permanent\protected\def\headvbox{\vbox\headreferenceattributes}
183
184\permanent\protected\def\startlocalheadsetup{\bgroup\strc_rendering_initialize_spacing}
185\permanent\protected\def\stoplocalheadsetup {\egroup}
186
187\aliased\let\headsetupspacing\relax
188\aliased\let\localheadsetup  \relax
189
190\permanent\protected\def\strc_rendering_initialize_spacing
191  {\forgetall % local !
192   \edef\p_align{\headparameter\c!align}%
193   \ifempty\p_align \else
194     \setupalign[\p_align]%
195   \fi
196   \edef\p_tolerance{\headparameter\c!tolerance}%
197   \ifempty\p_tolerance \else
198     \setuptolerance[\p_tolerance]%
199   \fi
200   \edef\p_strut{\headparameter\c!strut}%
201   \ifx\p_strut\v!no
202     \setnostrut
203   \fi
204   \enforced\let\\\strc_rendering_shortcut_backslash}
205
206\protected\def\strc_rendering_shortcut_backslash
207  {\crlf
208   \strut
209   \ignorespaces}
210
211% maybe more needs to be moved inide the box
212
213\def\strc_rendering_start_placement
214  {\headparameter\c!beforehead
215   \bgroup
216   \setsystemmode\currenthead
217   \strc_rendering_initialize_alternatives
218   \strc_rendering_initialize_dimensions
219   \strc_rendering_initialize_line_state
220   \reseteverypar % needed indeed
221   \noindent      % ipv \whitespace elders, na \forgetall !
222   \bgroup
223   \synctexpushline
224   \edef\p_aligntitle{\headparameter\c!aligntitle}%
225   \ifx\p_aligntitle\v!yes
226     \strc_rendering_initialize_hsize_local
227   \orelse\ifx\p_aligntitle\v!float
228     \strc_rendering_initialize_hsize_local
229   \else
230     \strc_rendering_initialize_hsize_global
231   \fi
232   \inhibitmargindata\conditionalfalse % brrrr is set in forgetall
233   \dontcomplain
234   \postponenotes
235 % \strc_rendering_initialize_interaction % moved (otherwise can interfere with pagebody)
236   % delayed:
237   \enforced\let\localheadsetup  \strc_rendering_initialize_spacing  % historic name, kept around because some styles use it
238   \enforced\let\headsetupspacing\strc_rendering_initialize_spacing} % official name
239
240\def\strc_rendering_initialize_interaction
241  {\resetinteractionstyleandcolor}
242
243% \setuphead[chapter]         [style=\bfd,after=,hang=line] % fit broad 2
244% \setuphead[section]         [style=\bfc,after=,hang=line]
245% \setuphead[subsection]      [style=\bfb,after=,hang=line]
246% \setuphead[subsubsection]   [style=\bfa,after=,hang=line]
247% \setuphead[subsubsubsection][style=\bf ,after=,hang=line]
248%
249% \chapter         {Test} \input tufte \page
250% \section         {Test} \input tufte \page
251% \subsection      {Test} \input tufte \page
252% \subsubsection   {Test} \input tufte \page
253% \subsubsubsection{Test} \input tufte \page
254%
255% \chapter         {Test\\Test} \input tufte \page
256% \section         {Test\\Test} \input tufte \page
257% \subsection      {Test\\Test} \input tufte \page
258% \subsubsection   {Test\\Test} \input tufte \page
259% \subsubsubsection{Test\\Test} \input tufte \page
260
261\newdimension\d_strc_rendering_hang_height
262\newinteger  \n_strc_rendering_hang_lines
263\newdimension\d_strc_rendering_local_height
264\newdimension\d_strc_rendering_local_depth
265\newdimension\d_strc_rendering_local_lineheight
266
267\def\strc_rendering_initialize_line_state
268  {\global\d_strc_rendering_local_height\strutht
269   \global\d_strc_rendering_local_depth\strutdp
270   \global\d_strc_rendering_local_lineheight\lineheight}
271
272\def\strc_rendering_check_hang
273  {\begingroup
274   \openlineheight\d_strc_rendering_local_lineheight
275   \d_strc_rendering_hang_height\htdp\b_strc_rendering_head
276   \getnoflines\d_strc_rendering_hang_height
277   \normalexpanded{\endgroup\n_strc_rendering_hang_lines\tointeger{\noflines-\plusone}\relax}% brrr
278   \setbox\b_strc_rendering_head\hpack{\lower\n_strc_rendering_hang_lines\d_strc_rendering_hang_height\box\b_strc_rendering_head}%
279   \d_strc_rendering_hang_height{\htdp\b_strc_rendering_head-\d_strc_rendering_local_height+\strutdp}%
280   \ht\b_strc_rendering_head\strutht
281   \dp\b_strc_rendering_head\strutdp
282   \d_strc_rendering_local_depth\strutdp}
283
284\installcorenamespace{headplacementcheckhang}
285
286\defcsname\??headplacementcheckhang\v!line\endcsname
287  {\strc_rendering_check_hang
288   \n_strc_rendering_hang_lines\zerocount}
289
290\defcsname\??headplacementcheckhang\v!broad\endcsname
291  {\strc_rendering_check_hang
292   \getnoflines\d_strc_rendering_hang_height}
293
294\defcsname\??headplacementcheckhang\v!fit\endcsname
295  {\strc_rendering_check_hang
296   \getrawnoflines\d_strc_rendering_hang_height}
297
298\defcsname\??headplacementcheckhang\v!none\endcsname
299  {\n_strc_rendering_hang_lines\zerocount}
300
301\defcsname\??headplacementcheckhang\endcsname
302  {\n_strc_rendering_hang_lines\zerocount}
303
304\defcsname\??headplacementcheckhang\s!unknown\endcsname
305  {\strc_rendering_check_hang
306   \n_strc_rendering_hang_lines{(\headparameter\c!hang)-\plusone}}
307
308\def\strc_rendering_initialize_line_hang
309   {\ifconditional\headisdisplay
310      \expandnamespaceparameter\??headplacementcheckhang\headparameter\c!hang\s!unknown
311      \relax
312    \else
313      \n_strc_rendering_hang_lines \zerocount
314      \d_strc_rendering_hang_height\zeropoint
315    \fi}
316
317\def\strc_rendering_initialize_hsize_local
318  {\global\d_strc_rendering_local_leftoffset \leftskip
319   \global\d_strc_rendering_local_rightoffset\rightskip
320 % \forgetall
321 % \leftskip \d_strc_rendering_local_leftoffset  % no stretch
322 % \rightskip\d_strc_rendering_local_rightoffset % no stretch
323 % \setlocalhsize
324 % \hsize\localhsize
325 % \forgetbothskips}
326   \scratchwidth\availablehsize
327   \forgetall
328   \hsize\scratchwidth}
329
330\def\strc_rendering_initialize_hsize_global
331  {\global\d_strc_rendering_local_leftoffset \zeropoint
332   \global\d_strc_rendering_local_rightoffset\zeropoint
333   \forgetall}
334
335% \def\strc_sectioning_stay_on_this_line
336%   {\directcheckedvspacing{-\v!line,\v!samepage,\v!nowhite}%
337%    \directcheckedvspacing\v!disable}
338%
339% we now use \ignoreparskip, so:
340
341\def\strc_sectioning_stay_on_this_line
342  {\directcheckedvspacing{-\v!line,\v!samepage}%
343   \directcheckedvspacing\v!disable}
344
345\def\strc_rendering_stop_placement
346  {\n_strc_rendering_hang_lines\zerocount
347   \ifconditional\headisdisplay
348     \strc_rendering_initialize_line_hang
349     % kind of special, we want to snap heads also according to local specs local
350     \setbox\b_strc_rendering_head\hbox
351%        {\hskip{\d_strc_rendering_local_leftoffset+(\headparameter\c!margin)}%
352       {\hskip\glueexpr\d_strc_rendering_local_leftoffset+(\headparameter\c!margin)\relax
353        \box\b_strc_rendering_head
354        \getheadsyncs % a latelua why not in the box
355        }%
356     \ifgridsnapping
357       \applygridmethod
358         {\headparameter\c!grid}%
359         {\ifconditional\headisdisplay
360            \strc_rendering_initialize_style_and_color_display\c!textstyle\c!textcolor
361          \fi}%
362         {\box\b_strc_rendering_head}
363     \else
364       \box\b_strc_rendering_head
365     \fi
366     \flushnotes % new, not really needed
367     \endgraf
368     \ifvmode
369       \ifnum\n_strc_rendering_hang_lines>\zerocount
370         \dorecurse\n_strc_rendering_hang_lines{\nointerlineskip\dosomebreak\nobreak\strut\endgraf}% to be checked
371       \fi
372       \nointerlineskip
373       \dosomebreak\nobreak
374     \fi
375%      \getheadsyncs % a latelua why not in the box
376   \else
377     % somehow this goes ok even when we push in the margin probably because we gobble pars
378     % in the process of collecting index entries etc
379     \strut
380     \flushnotes % new, here since we're in par mode
381     \unhbox\b_strc_rendering_head
382     \getheadsyncs % a latelua
383     \ifconditional\headissomewhere
384       \strc_sectioning_stay_on_this_line % test case: alternative=margintext and \startparagraph ..
385     \else
386      %\hskip\headnumberdistance\s!plus\headnumberdistance\s!minus.25{\headnumberdistance}%
387       \hskip\headtextdistance\relax
388       \strc_sectioning_inject_continuous_signal
389     \fi
390   \fi
391   \ifconditional\headisdisplay
392     \ifvmode
393       \ifgridsnapping % important, font related depth, see comment
394         \prevdepth\strutdp
395       \else
396         \prevdepth\d_strc_rendering_local_depth
397       \fi
398     \fi
399   \fi
400   \synctexpopline
401   \egroup
402   \egroup
403   \ifconditional\headisdisplay
404     \useindentnextparameter\headparameter
405   \orelse\ifconditional\headissomewhere
406     \ignoreparskip
407     \noindentation
408   \else
409     \ignoreparskip
410     \doindentation
411   \fi
412   % this can interfere with the above but is just there for symmetry
413   \headparameter\c!afterhead}
414
415% nice testcase
416%
417% \setupheads[aligntitle=yes]
418%
419% \startnarrower
420%   \subject{\dorecurse{100}{x }}
421%   \section{\dorecurse{100}{x }}
422%   \input tufte \par
423%   \setupheads[alternative=inmargin]
424%   \subject{\dorecurse{100}{x }}
425%   \section{\dorecurse{100}{x }}
426%   \input tufte \par
427% \stopnarrower
428
429% \dodefineheadplacement[sectiona][vertical]{#1->#2}
430% \dodefineheadplacement[sectionb][vertical]#1#2{#1->#2}
431%
432% \setuphead[section][alternative=sectiona]
433% \setuphead[subsection][alternative=sectionb]
434
435% \startsetups[\??headrenderings:\v!vertical:\v!sectiona]
436%     ... there will be a more public namespace
437% \stopsetups
438
439\installcorenamespace{headplacementalternative}
440\installcorenamespace{headrenderings}
441\installcorenamespace{headalternative}
442
443\installcommandhandler \??headalternative {headalternative} \??headalternative % or just \??head
444
445\setupheadalternative
446  [%\c!width=\headparameter\c!width,
447   %\c!distance=\headparameter\c!distance,
448   \c!alternative=\v!vertical,
449   \c!renderingsetup=\??headrenderings:\currentheadalternative]
450
451\let\currentheadalternative         \v!normal
452\let\currentheadrenderingalternative\v!vertical
453
454\lettonothing\currentheadrenderingsetup
455
456\permanent\tolerant\protected\def\defineheadplacement[#1]#*[#2]%
457  {\doifelsenextbgroup
458     {\strc_rendering_define_placement_yes[#1][#2]}%
459     {\strc_rendering_define_placement_nop[#1][#2]}}
460
461\def\strc_rendering_define_placement_yes[#1][#2]%
462  {\defineheadalternative[#1][\c!alternative=#2,\c!renderingsetup=\??headrenderings:\v!command]%
463   \protected\defcsname\??headplacementalternative#1\endcsname##1##2}
464
465\def\strc_rendering_define_placement_nop[#1][#2]%
466  {\defineheadalternative[#1][\c!alternative=#2,\c!renderingsetup=\??headrenderings:\v!command]%
467   \protected\defcsname\??headplacementalternative#1\endcsname}
468
469% these can be used in setups:
470%
471% \headnumbercontent
472% \headtextcontent
473%
474% \headwidth
475% \headtextwidth
476% \headnumberdistance
477% \headnumberwidth
478% \headsetupspacing
479%
480% \headshownumber
481% \headisdisplay
482
483\lettonothing\headnumbercontent
484\lettonothing\headtextcontent
485
486\newdimension\headwidth
487\newdimension\headtextwidth
488\newgluespec \headtextdistance
489\newdimension\headnumberdistance
490\newdimension\headnumberwidth
491
492% \newconditional\headshownumber % defined already
493% \newconditional\headisdisplay  % defined already
494
495\protected\def\strc_rendering_initialize_alternatives
496  {\edef\currentheadalternative{\headparameter\c!alternative}%
497   \ifcsname\currentheadalternativehash\s!parent\endcsname \else
498      \let\currentheadalternative\v!normal % cf. mkii
499   \fi
500   \edef\currentheadrenderingsetup{\headalternativeparameter\c!renderingsetup}%
501   \edef\currentheadrenderingalternative{\headalternativeparameter\c!alternative}%
502   \ifempty\currentheadrenderingalternative
503     \let\currentheadrenderingalternative\v!vertical
504   \fi
505   \ifx\currentheadrenderingalternative\v!horizontal
506     \global\headisdisplay\conditionalfalse   % global
507     \global\headissomewhere\conditionalfalse % global
508   \orelse\ifx\currentheadrenderingalternative\v!somewhere
509     \global\headisdisplay\conditionalfalse   % global
510     \global\headissomewhere\conditionaltrue  % global
511   \else
512     \global\headisdisplay\conditionaltrue    % global
513     \global\headissomewhere\conditionalfalse % global
514   \fi}
515
516\protected\def\strc_rendering_initialize_dimensions
517  {\headwidth         {\headparameter\c!width       }% % \zeropoint == unset
518   \headnumberwidth   {\headparameter\c!numberwidth }% % \zeropoint == unset
519   \headnumberdistance{\headparameter\c!distance    }%
520   \headtextdistance  \glueexpr\headparameter\c!textdistance\relax
521   \headtextwidth     {\headparameter\c!textwidth   }} % \zeropoint == unset
522
523\permanent\protected\def\headtextcontent
524  {\begingroup
525     \strc_rendering_initialize_style_and_color\c!textstyle\c!textcolor
526     \headparameter\c!commandbefore\relax
527     \ifcsname\currentheadhash\c!deeptextcommand\endcsname
528      %\expandafter\let\expandafter\deepstructuretitlecommand\csname\currentheadhash\c!deeptextcommand\endcsname
529       \expandafter\let\expandafter\deepstructuretitlecommand\lastnamedcs
530     \fi
531     \ifconditional\headisdisplay
532       % struts can be nilled with \setnostrut
533       \headparameter\c!textcommand{\setstrut\begstrut\getheadtitle\endstrut}%
534       \global\d_strc_rendering_local_height\strutht
535       \global\d_strc_rendering_local_depth\strutdp
536       \global\d_strc_rendering_local_lineheight\lineheight
537       \headparameter\c!commandafter\relax
538       \endgraf
539     \else
540       \headparameter\c!textcommand{\getheadtitle}%
541       \headparameter\c!commandafter\relax
542     \fi
543   \endgroup}
544
545\permanent\protected\def\headnumbercontent
546  {\begingroup
547     \strc_rendering_initialize_style_and_color\c!numberstyle\c!numbercolor
548     \ifcsname\currentheadhash\c!deepnumbercommand\endcsname
549      %\expandafter\let\expandafter\deepstructurenumbercommand\csname\currentheadhash\c!deepnumbercommand\endcsname
550       \expandafter\let\expandafter\deepstructurenumbercommand\lastnamedcs
551     \fi
552     \ifconditional\headisdisplay
553       % can be nilled with \setnostrut
554       \headparameter\c!numbercommand{\setstrut\begstrut\getheadnumber\endstrut}%
555     \else
556       \headparameter\c!numbercommand{\getheadnumber}%
557     \fi
558   \endgroup}
559
560\permanent\protected\def\fakedheadnumber{\vphantom{0}} % needed for mathplus
561
562% \permanent\protected\def\fakeheadnumbercontent
563%   {\hbox to \zeropoint{\let\getheadnumber\fakedheadnumber\headnumbercontent}}
564
565\permanent\protected\def\fakeheadnumbercontent
566  {\ifcstok{\headparameter\c!hidenumber}\v!yes\else
567     \hbox to \zeropoint{\let\getheadnumber\fakedheadnumber\headnumbercontent}%
568   \fi}
569
570\permanent\protected\def\strc_rendering_inject_number_and_text
571  {\edef\p_command{\headparameter\c!command}% assumes \protected definition
572   \ifempty\p_command
573     \directsetup\currentheadrenderingsetup
574   \else
575     \p_command\headnumbercontent\headtextcontent
576   \fi}
577
578\protected\def\strc_rendering_inject_text
579  {\edef\p_command{\headparameter\c!command}% assumes \protected definition
580   \ifempty\p_command
581     \directsetup\currentheadrenderingsetup
582   \else
583     \p_command\empty\headtextcontent
584   \fi}
585
586\startsetups[\??headrenderings:\v!command]
587    \csname\??headplacementalternative\currentheadalternative\endcsname \headnumbercontent \headtextcontent
588\stopsetups
589
590% obsolete
591%
592% \def\normalplacehead % hooks into \c!command
593%   {\csname\??headplacementalternative\ifcsname\??headplacementalternative\currentheadalternative\endcsname\currentheadalternative\else\v!normal\fi\endcsname}
594
595\defineheadalternative
596  [\v!paragraph]
597  [\c!alternative=\v!vertical,
598   \c!renderingsetup=\??headrenderings:\v!paragraph]
599
600\startsetups[\??headrenderings:\v!paragraph]
601    \vbox {
602        \headsetupspacing
603        \begstrut
604        \ifconditional\headshownumber % \ifheadnumbercontent
605            \headnumbercontent
606            \hskip\headnumberdistance
607        \fi
608        \headtextcontent
609    }
610\stopsetups
611
612% \setuphead
613%   [chapter]
614%   [numberwidth=2cm,hang=line,after={\blank[3*line]}]
615%
616% \chapter{Oeps oeps oeps} \input tufte   \section{Oeps}
617% \chapter{Oeps oeps oeps} \section{Oeps} \input tufte
618
619\defineheadalternative
620  [\v!normal]
621  [\c!alternative=\v!vertical,
622   \c!renderingsetup=\??headrenderings:\v!normal]
623
624\startsetups[\??headrenderings:\v!normal]
625    \vbox {
626        \headsetupspacing
627        \ifconditional\headshownumber
628            \ifzeropt\headwidth \else
629                \ifzeropt\headnumberwidth
630                    \ifzeropt\headtextwidth \else
631                        \headnumberwidth{\headwidth-\headtextwidth}%
632                    \fi
633                \else
634                    \ifzeropt\headtextwidth
635                        \headtextwidth{\headwidth-\headnumberwidth}%
636                    \fi
637                \fi
638                \hsize\headwidth
639            \fi
640            \ifzeropt\headnumberwidth \else
641                \headnumberdistance\zeropoint
642            \fi
643            \setbox\scratchbox\hbox \ifzeropt\headnumberwidth\else to \headnumberwidth\fi{\headnumbercontent}
644            \scratchdimen{\wd\scratchbox+\headnumberdistance}%
645            \ifzeropt\headtextwidth \else
646                \hsize{\scratchdimen+\headtextwidth}%
647            \fi
648            \hangindent\scratchdimen
649            \hangafter \plusone
650            \noindent
651            \box\scratchbox
652            \hskip\headnumberdistance
653        \else
654            \ifzeropt\headtextwidth
655                \ifzeropt\headwidth \else
656                    \hsize\headwidth
657                \fi
658            \else
659                \hsize\headtextwidth
660            \fi
661            \noindent
662            \fakeheadnumbercontent % will also be done in the other ones (force consistency with numbered)
663        \fi
664        \headtextcontent
665    }
666\stopsetups
667
668\defineheadalternative
669  [\v!inmargin]
670  [\c!alternative=\v!vertical,
671   \c!renderingsetup=\??headrenderings:\v!inmargin]
672
673\startsetups[\??headrenderings:\v!inmargin]
674    \vbox {
675        \headsetupspacing
676        \dontleavehmode % in case there is no strut, else side effects with llap
677        \begstrut % use one \strut here!
678        \ifconditional\headshownumber
679            \ifempty {\headparameter\c!location}
680                % normal backward compatible variant
681                \llap {
682                    \signalrightpage
683                    \hbox {
684                        \hfill
685                        \headnumbercontent
686                        \doifelserightpage{
687                            \scratchdistance\leftmargindistance
688                        } {
689                            \scratchdistance\rightmargindistance
690                        }
691%                         \hskip{\d_strc_rendering_local_leftoffset+\scratchdistance}%
692                        \hskip\glueexpr\d_strc_rendering_local_leftoffset+\scratchdistance\relax
693                    }
694                }
695            \else
696                % kind of new
697                \margindata [\headparameter\c!location] {
698                    \headnumbercontent
699                }
700            \fi
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        \headisdisplay\conditionalfalse % 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            \advanceby\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            \advanceby\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