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