strc-ren.mkiv /size: 27 Kb    last modification: 2020-07-01 14:35
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
\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
\fi\fi
}
385 386
% nice testcase
387
%
388
% \setupheads[aligntitle=yes]
389
%
390
% \startnarrower
391
% \subject{\dorecurse{100}{x }}
392
% \section{\dorecurse{100}{x }}
393
% \input tufte \par
394
% \setupheads[alternative=inmargin]
395
% \subject{\dorecurse{100}{x }}
396
% \section{\dorecurse{100}{x }}
397
% \input tufte \par
398
% \stopnarrower
399 400
% \dodefineheadplacement[sectiona][vertical]{#1->#2}
401
% \dodefineheadplacement[sectionb][vertical]#1#2{#1->#2}
402
%
403
% \setuphead[section][alternative=sectiona]
404
% \setuphead[subsection][alternative=sectionb]
405 406
% \startsetups[\??headrenderings:\v!vertical:\v!sectiona]
407
% ... there will be a more public namespace
408
% \stopsetups
409 410
\installcorenamespace
{
headplacementalternative
}
411
\installcorenamespace
{
headrenderings
}
412
\installcorenamespace
{
headalternative
}
413 414
\installcommandhandler
\??headalternative
{
headalternative
}
\??headalternative
% or just \??head
415 416
\setupheadalternative
417
[
%\c!width=\headparameter\c!width,
418
%\c!distance=\headparameter\c!distance,
419
\c!alternative
=
\v!vertical
,
420
\c!renderingsetup
=
\??headrenderings
:
\currentheadalternative
]
421 422
\let
\currentheadalternative
\v!normal
423
\let
\currentheadrenderingsetup
\empty
424
\let
\currentheadrenderingalternative
\v!vertical
425 426
\unexpanded
\def
\defineheadplacement
% old mechanism
427
{
\dodoubleargument
\strc_rendering_define_placement
}
428 429
\def
\strc_rendering_define_placement
[#
1
][#
2
]
%
430
{
\doifelsenextbgroup
431
{
\strc_rendering_define_placement_yes
[#
1
][#
2
]
}
%
432
{
\strc_rendering_define_placement_nop
[#
1
][#
2
]
}}
433 434
\def
\strc_rendering_define_placement_yes
[#
1
][#
2
]
%
435
{
\defineheadalternative
[#
1
][
\c!alternative
=#
2
,
\c!renderingsetup
=
\??headrenderings
:
\v!command
]
%
436
\setuvalue
{
\??headplacementalternative
#
1
}
##
1
##
2
}
437 438
\def
\strc_rendering_define_placement_nop
[#
1
][#
2
]
%
439
{
\defineheadalternative
[#
1
][
\c!alternative
=#
2
,
\c!renderingsetup
=
\??headrenderings
:
\v!command
]
%
440
\setuvalue
{
\??headplacementalternative
#
1
}}
441 442
% these can be used in setups:
443
%
444
% \headnumbercontent
445
% \headtextcontent
446
%
447
% \headwidth
448
% \headtextwidth
449
% \headnumberdistance
450
% \headnumberwidth
451
% \headsetupspacing
452
%
453
% \headshownumber
454
% \headisdisplay
455 456
\let
\headnumbercontent
\empty
457
\let
\headtextcontent
\empty
458 459
\newdimen
\headwidth
460
\newdimen
\headtextwidth
461
\newskip
\headtextdistance
462
\newdimen
\headnumberdistance
463
\newdimen
\headnumberwidth
464 465
% \newconditional\headshownumber % defined already
466
% \newconditional\headisdisplay % defined already
467 468
\unexpanded
\def
\strc_rendering_initialize_alternatives
469
{
\edef
\currentheadalternative
{
\headparameter
\c!alternative
}
%
470
\ifcsname
\currentheadalternativehash
\s!parent
\endcsname
\else
471
\let
\currentheadalternative
\v!normal
% cf. mkii
472
\fi
473
\edef
\currentheadrenderingsetup
{
\headalternativeparameter
\c!renderingsetup
}
%
474
\edef
\currentheadrenderingalternative
{
\headalternativeparameter
\c!alternative
}
%
475
\ifx
\currentheadrenderingalternative
\empty
476
\let
\currentheadrenderingalternative
\v!vertical
477
\fi
478
\ifx
\currentheadrenderingalternative
\v!horizontal
479
\global
\setfalse
\headisdisplay
% global
480
\global
\setfalse
\headissomewhere
% global
481
\else\ifx
\currentheadrenderingalternative
\v!somewhere
482
\global
\setfalse
\headisdisplay
% global
483
\global
\settrue
\headissomewhere
% global
484
\else
485
\global
\settrue
\headisdisplay
% global
486
\global
\setfalse
\headissomewhere
% global
487
\fi\fi
}
488 489
\unexpanded
\def
\strc_rendering_initialize_dimensions
490
{
\headwidth
\headparameter
\c!width
\relax
% \zeropoint == unset
491
\headnumberwidth
\headparameter
\c!numberwidth
\relax
% \zeropoint == unset
492
\headnumberdistance
\headparameter
\c!distance
\relax
493
\headtextdistance
\headparameter
\c!textdistance
\relax
494
\headtextwidth
\headparameter
\c!textwidth
\relax
}
% \zeropoint == unset
495 496
\unexpanded
\def
\headtextcontent
497
{
\begingroup
498
\strc_rendering_initialize_style_and_color
\c!textstyle\c!textcolor
499
\headparameter
\c!commandbefore
\relax
500
\ifcsname
\currentheadhash
\c!deeptextcommand
\endcsname
501
%\expandafter\let\expandafter\deepstructuretitlecommand\csname\currentheadhash\c!deeptextcommand\endcsname
502
\expandafter\let\expandafter
\deepstructuretitlecommand
\lastnamedcs
503
\fi
504
\ifconditional
\headisdisplay
505
% struts can be nilled with \setnostrut
506
\headparameter
\c!textcommand
{
\setstrut\begstrut
\getheadtitle
\endstrut
}
%
507
\global
\d_strc_rendering_local_height
\strutht
508
\global
\d_strc_rendering_local_depth
\strutdp
509
\global
\d_strc_rendering_local_lineheight
\lineheight
510
\headparameter
\c!commandafter
\relax
511
\endgraf
512
\else
513
\headparameter
\c!textcommand
{
\getheadtitle
}
%
514
\headparameter
\c!commandafter
\relax
515
\fi
516
\endgroup
}
517 518
\unexpanded
\def
\headnumbercontent
519
{
\begingroup
520
\strc_rendering_initialize_style_and_color
\c!numberstyle\c!numbercolor
521
\ifcsname
\currentheadhash
\c!deepnumbercommand
\endcsname
522
%\expandafter\let\expandafter\deepstructurenumbercommand\csname\currentheadhash\c!deepnumbercommand\endcsname
523
\expandafter\let\expandafter
\deepstructurenumbercommand
\lastnamedcs
524
\fi
525
\ifconditional
\headisdisplay
526
% can be nilled with \setnostrut
527
\headparameter
\c!numbercommand
{
\setstrut\begstrut
\getheadnumber
\endstrut
}
%
528
\else
529
\headparameter
\c!numbercommand
{
\getheadnumber
}
%
530
\fi
531
\endgroup
}
532 533
\def
\fakedheadnumber
{
\vphantom
{
0
}}
% needed for mathplus
534 535
% \unexpanded\def\fakeheadnumbercontent
536
% {\hbox to \zeropoint{\let\getheadnumber\fakedheadnumber\headnumbercontent}}
537 538
\unexpanded
\def
\fakeheadnumbercontent
539
{
\edef
\p_hidenumber
{
\headparameter
\c!hidenumber
}
%
540
\ifx
\p_hidenumber
\v!yes
\else
541
\hbox
to
\zeropoint
{
\let
\getheadnumber
\fakedheadnumber
\headnumbercontent
}
%
542
\fi
}
543 544
\unexpanded
\def
\strc_rendering_inject_number_and_text
545
{
\edef
\p_command
{
\headparameter
\c!command
}
% assumes \unexpanded definition
546
\ifx
\p_command
\empty
547
\directsetup
\currentheadrenderingsetup
548
\else
549
\p_command
\headnumbercontent\headtextcontent
550
\fi
}
551 552
\unexpanded
\def
\strc_rendering_inject_text
553
{
\edef
\p_command
{
\headparameter
\c!command
}
% assumes \unexpanded definition
554
\ifx
\p_command
\empty
555
\directsetup
\currentheadrenderingsetup
556
\else
557
\p_command
\empty
\headtextcontent
558
\fi
}
559 560
\startsetups
[
\??headrenderings
:
\v!command
]
561
\csname
\??headplacementalternative
\currentheadalternative
\endcsname
\headnumbercontent
\headtextcontent
562
\stopsetups
563 564
% obsolete
565
%
566
% \def\normalplacehead % hooks into \c!command
567
% {\csname\??headplacementalternative\ifcsname\??headplacementalternative\currentheadalternative\endcsname\currentheadalternative\else\v!normal\fi\endcsname}
568 569
\defineheadalternative
570
[
\v!paragraph
]
571
[
\c!alternative
=
\v!vertical
,
572
\c!renderingsetup
=
\??headrenderings
:
\v!paragraph
]
573 574
\startsetups
[
\??headrenderings
:
\v!paragraph
]
575
\vbox
{
576
\headsetupspacing
577
\begstrut
578
\ifconditional
\headshownumber
% \ifheadnumbercontent
579
\headnumbercontent
580
\hskip
\headnumberdistance
581
\fi
582
\headtextcontent
583
}
584
\stopsetups
585 586
% \setuphead
587
% [chapter]
588
% [numberwidth=2cm,hang=line,after={\blank[3*line]}]
589
%
590
% \chapter{Oeps oeps oeps} \input tufte \section{Oeps}
591
% \chapter{Oeps oeps oeps} \section{Oeps} \input tufte
592 593
\defineheadalternative
594
[
\v!normal
]
595
[
\c!alternative
=
\v!vertical
,
596
\c!renderingsetup
=
\??headrenderings
:
\v!normal
]
597 598
\startsetups
[
\??headrenderings
:
\v!normal
]
599
\vbox
{
600
\headsetupspacing
601
\ifconditional
\headshownumber
602
\ifzeropt
\headwidth
\else
603
\ifzeropt
\headnumberwidth
604
\ifzeropt
\headtextwidth
\else
605
\headnumberwidth
\dimexpr
\headwidth
-
\headtextwidth
\relax
606
\fi
607
\else
608
\ifzeropt
\headtextwidth
609
\headtextwidth
\dimexpr
\headwidth
-
\headnumberwidth
\relax
610
\fi
611
\fi
612
\hsize
\headwidth
613
\fi
614
\ifzeropt
\headnumberwidth
\else
615
\headnumberdistance
\zeropoint
616
\fi
617
\setbox
\scratchbox
\hbox
\ifzeropt
\headnumberwidth
\else
to
\headnumberwidth
\fi
{
\headnumbercontent
}
618
\scratchdimen
\dimexpr\wd
\scratchbox
+
\headnumberdistance
\relax
619
\ifzeropt
\headtextwidth
\else
620
\hsize\dimexpr
\scratchdimen
+
\headtextwidth
\relax
621
\fi
622
\hangindent
\scratchdimen
623
\hangafter
\plusone
624
\noindent
625
\box
\scratchbox
626
\hskip
\headnumberdistance
627
\else
628
\ifzeropt
\headtextwidth
629
\ifzeropt
\headwidth
\else
630
\hsize
\headwidth
631
\fi
632
\else
633
\hsize
\headtextwidth
634
\fi
635
\noindent
636
\fakeheadnumbercontent
% will also be done in the other ones (force consistency with numbered)
637
\fi
638
\headtextcontent
639
}
640
\stopsetups
641 642
\defineheadalternative
643
[
\v!inmargin
]
644
[
\c!alternative
=
\v!vertical
,
645
\c!renderingsetup
=
\??headrenderings
:
\v!inmargin
]
646 647
% \startsetups[\??headrenderings:\v!inmargin]
648
% \vbox {
649
% \headsetupspacing
650
% \begstrut % use one \strut here!
651
% \dontleavehmode % in case there is no strut, else side effects with llap
652
% \ifconditional\headshownumber
653
% \llap {
654
% \signalrightpage
655
% \hbox {
656
% \hfill
657
% \headnumbercontent
658
% \doifelserightpage{
659
% \scratchdistance\leftmargindistance
660
% } {
661
% \scratchdistance\rightmargindistance
662
% }
663
% \hskip\dimexpr\d_strc_rendering_local_leftoffset+\scratchdistance\relax
664
% }
665
% }
666
% \else
667
% \fakeheadnumbercontent % will also be done in the other ones (force consistency with numbered)
668
% \fi
669
% \headtextcontent
670
% }
671
% \stopsetups
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
\doifelsesomething
{
\headparameter
\c!location
}
{
680
% kind of new
681
\margindata
[
\headparameter
\c!location
]
{
682
\headnumbercontent
683
}
684
}
{
685
% normal backward compatible variant
686
\llap
{
687
\signalrightpage
688
\hbox
{
689
\hfill
690
\headnumbercontent
691
\doifelserightpage
{
692
\scratchdistance
\leftmargindistance
693
}
{
694
\scratchdistance
\rightmargindistance
695
}
696
\hskip\dimexpr
\d_strc_rendering_local_leftoffset
+
\scratchdistance
\relax
697
}
698
}
699
}
700
\else
701
\fakeheadnumbercontent
% will also be done in the other ones (force consistency with numbered)
702
\fi
703
\headtextcontent
704
}
705
\stopsetups
706 707
\defineheadalternative
708
[
\v!margin
]
709
[
\v!inmargin
]
710 711
% \startsetups[\??headrenderings:\v!vertical:\v!margin]
712
% \directsetup{\??headrenderings:\v!vertical:\v!inmargin}
713
% \stopsetups
714 715
%D This one is for head based numbering usage: foo 1.2 and so:
716 717
\defineheadalternative
718
[
\v!reverse
]
719
[
\c!alternative
=
\v!vertical
,
720
\c!renderingsetup
=
\??headrenderings
:
\v!reverse
]
721 722
\startsetups
[
\??headrenderings
:
\v!reverse
]
723
\vbox
{
724
\headsetupspacing
725
\noindent
726
\begstrut
727
\setfalse
\headisdisplay
% so a kind of mix
728
\headtextcontent
729
\ifconditional
\headshownumber
730
\kern
\headnumberdistance
731
\headnumbercontent
732
\else
733
\fakeheadnumbercontent
734
\fi
735
\endstrut
736
}
737
\stopsetups
738 739
\defineheadalternative
740
[
\v!middle
]
741
[
\c!alternative
=
\v!vertical
,
742
\c!renderingsetup
=
\??headrenderings
:
\v!middle
]
743 744
\startsetups
[
\??headrenderings
:
\v!middle
]
745
\vbox
{
746
\headsetupspacing
747
\veryraggedcenter
748
\let
\\
\endgraf
749
\let
\crlf\endgraf
750
\ifconditional
\headshownumber
751
\strut
752
\headnumbercontent
753
\par
754
\else
755
\fakeheadnumbercontent
756
\fi
757
\begstrut
758
\headtextcontent
759
\endstrut
760
}
761
\stopsetups
762 763
\defineheadalternative
764
[
\v!text
]
765
[
\c!alternative
=
\v!horizontal
,
766
\c!renderingsetup
=
\??headrenderings
:
\v!text
]
767 768
\startsetups
[
\??headrenderings
:
\v!text
]
769
\begingroup
770
\headsetupspacing
% no stretch in distance
771
\ifconditional
\headshownumber
772
\headnumbercontent
773
\kern
\headnumberdistance
774
\fi
775
\begstrut
776
\headtextcontent
777
\endstrut
778
\endgroup
779
\stopsetups
780 781
% onder/boven lijnt het nummer op de onderste/bovenste regel uit van een meerregelige kop
782 783
\defineheadalternative
784
[
\v!bottom
]
785
[
\c!alternative
=
\v!vertical
,
786
\c!renderingsetup
=
\??headrenderings
:
\v!bottom
]
787 788
\startsetups
[
\??headrenderings
:
\v!bottom
]
789
\ifconditional
\headshownumber
790
\setbox
\scratchboxone
\hbox
{
791
\headnumbercontent
792
}
793
\setbox
\scratchboxtwo
\vbox
{
794
\headsetupspacing
795
\advance\hsize
-
\wd
\scratchboxone
\relax
796
\headtextcontent
797
}
798
\hpack
{
799
\box
\scratchboxone
800
\hskip
\headnumberdistance
801
\box
\scratchboxtwo
802
}
803
\else
804
\vbox
{
805
\headsetupspacing
806
\noindent
807
\headtextcontent
808
}
809
\fi
810
\stopsetups
811 812
\defineheadalternative
813
[
\v!top
]
814
[
\c!alternative
=
\v!vertical
,
815
\c!renderingsetup
=
\??headrenderings
:
\v!top
]
816 817
\startsetups
[
\??headrenderings
:
\v!top
]
818
\ifconditional
\headshownumber
819
\setbox
\scratchboxone
\hbox
{
820
\headnumbercontent
821
}
822
\setbox
\scratchboxtwo
\vtop
{
823
\headsetupspacing
824
\advance\hsize
-
\wd
\scratchboxone
\relax
825
\headtextcontent
826
}
827
\hpack
{
828
\box
\scratchboxone
829
\hskip
\headnumberdistance
830
\box
\scratchboxtwo
831
}
832
\else
833
\vtop
{
834
\headsetupspacing
835
\noindent
836
\headtextcontent
837
}
838
\fi
839
\stopsetups
840 841
% see typo-mar.mkiv:
842
%
843
% \defineheadalternative
844
% [\v!margintext]
845 846
\protect
\endinput
847