strc-sec.mkiv /size: 48 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=strc-sec,
3
%D version=2008.10.20,
4
%D title=\CONTEXT\ Structure Macros,
5
%D subtitle=Sectioning,
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
%D In retrospect I should have gone futher and move more to the
15
%D \LUA\ end but here we are now. Maybe some day.
16 17
\writestatus
{
loading
}{
ConTeXt
Structure
Macros
/
Sectioning
}
18 19
\unprotect
20 21
\startcontextdefinitioncode
22 23
\installcorenamespace
{
structure
}
24 25
\installdirectcommandhandler
\??structure
{
structure
}
% unchecked, so we need to initialize used parameters
26 27
\setupstructure
% not a user command so we might need to change the name
28
[
\c!number
=
,
29
\c!level
=
,
30
\c!name
=
,
31
\c!title
=
,
32
\c!bookmark
=
,
33
\c!marking
=
,
34
\c!list
=
,
35
\c!label
=
,
36
\c!coupling
=
,
37
\c!ownnumber
=
,
38
% \c!interaction=\v!list,
39
\c!sectionseparatorset
=
\s!default
,
40
\c!sectionconversionset
=
\s!default
,
41
\c!sectionstopper
=
,
42
\c!sectionstarter
=
,
43
\c!sectionsegments
=
,
44
\c!sectionresetset
=
,
45
\c!reference
=
,
46
\c!backreference
=
,
47
\c!expansion
=
\v!no
,
48
\c!xmlsetup
=
,
49
\s!catcodes
=
,
50
\c!saveinlist
=
\v!yes
]
51 52
% maybe flags for list, bm, mark
53 54
\def
\m_strc_references_prefix_yes
{
+
}
55
\def
\m_strc_references_prefix_nop
{
-
}
56 57
\let
\currentstructurereferenceprefix
\empty
58 59
\installglobalmacrostack
\currentstructurereferenceprefix
60 61
\def
\strc_sectioning_set_reference_prefix
62
{
\ifx
\currentstructurereferenceprefix
\empty
63
% nothing
64
\else\ifx
\currentstructurereferenceprefix
\m_strc_references_prefix_yes
65
\global\advance
\prefixcounter
\plusone
% temp here
66
\setupglobalreferenceprefix
[
\the
\prefixcounter
]
%
67
\else\ifx
\currentstructurereferenceprefix
\m_strc_references_prefix_nop
68
\setupglobalreferenceprefix
[]
%
69
\else
70
\setupglobalreferenceprefix
[
\currentstructurereferenceprefix
]
%
71
\fi\fi\fi
72
\glet
\currentstructurereferenceprefix
\referenceprefix
}
73 74
% why xdef ?
75 76
\setupstructure
77
[
\c!label
=
{
\headparameter
{
\currentsectionblock
\c!label
}}
,
78
\c!incrementnumber
=
\ifconditional
\c_strc_sectioning_increment
\v!yes
\else
\v!no
\fi
,
% not that needed
79
\c!saveinlist
=
\ifconditional
\c_strc_sectioning_to_list
\v!yes
\else
\v!no
\fi
,
80
\c!level
=
\currentheadlevel
,
81
\c!number
=
\ifconditional
\c_strc_sectioning_increment
\ifconditional
\headshownumber
\v!yes
\else
\v!no
\fi\else
\v!no
\fi
,
82
\c!expansion
=
\headparameter
\c!expansion
,
83
\c!xmlsetup
=
\headparameter
\c!xmlsetup
,
84
\s!catcodes
=
\headparameter
\s!catcodes
,
85
\c!sectionresetset
=
\headparameter
\c!sectionresetset
,
86
\c!sectionseparatorset
=
\headparameter
\c!sectionseparatorset
,
87
\c!sectionconversionset
=
\headparameter
\c!sectionconversionset
,
88
\c!sectionconversion
=
\headparameter
\c!conversion
,
% just for compatibility
89
\c!sectionstarter
=
\headparameter
\c!sectionstarter
,
90
\c!sectionstopper
=
\headparameter
\c!sectionstopper
,
91
\c!sectionset
=
\headparameter
\c!sectionset
,
92
\c!sectionsegments
=
\headparameter
\c!sectionsegments
,
93
\c!reference
=
\headparameter
\c!reference
,
94
\c!referenceprefix
=
\headparameter
\c!referenceprefix
,
95
\c!criterium
=
\headparameter
\c!criterium
]
96 97
% see lists/neat-001.tex for usage of:
98 99
\def
\namedstructureheadlocation
#
1
% expandable, maybe [#1]
100
{
\csname
\??savedinternalreference
\ifcsname
\??savedinternalreference
#
1
\endcsname
#
1
\else
\s!default
\fi\endcsname
}
101 102
% The next directive only makes sense when we have sort of garanteed outcome (math is not so
103
% nice for instance).
104
%
105
% \enabledirectives[references.bookmarks.preroll]
106 107
\newconditional
\c_strc_bookmarks_preroll
108 109
\installtexdirective
110
{
references
.
bookmarks
.
preroll
}
111
{
\settrue
\c_strc_bookmarks_preroll
}
112
{
\setfalse
\c_strc_bookmarks_preroll
}
113 114
\def
\strc_sectioning_autobookmark
#
1
%
115
{
\begingroup
116
% \settrialtypesetting
117
\the
\everypreroll
118
\nodestostring
\tempstring
{
#
1
}
%
119
\glet
\currentstructurebookmark
\tempstring
120
\endgroup
}
121 122
% zeros:
123
%
124
% \setuphead[subsection][criterium=all]
125
%
126
% \dorecurse{3} {
127
% \chapter{Blabla} \subsection{bla 1 1} \subsection{bla 1 2}
128
% \section{bla 2} \subsection{bla 2 1} \subsection{bla 2 2}
129
% }
130 131
\unexpanded
\def
\strc_sectioning_register
#
1
#
2
#
3
% #1=interfaced-settings, #2=optional user data (not yet supported)
132
{
\begingroup
133
\setupstructure
[
\c!name
=
{
#
1
}
,
#
2
]
%
134
\xdef
\currentstructurename
{
\structureparameter
\c!name
}
%
135
\xdef
\currentstructurecoupling
{
\structureparameter
\c!coupling
}
%
136
\xdef
\currentstructureownnumber
{
\structureparameter
\c!ownnumber
}
% optional own number
137
\xdef
\currentstructurelevel
{
\structureparameter
\c!level
}
%
138
\edef
\currentstructureexpansion
{
\structureparameter
\c!expansion
}
%
139
\xdef
\currentstructurexmlsetup
{
\structureparameter
\c!xmlsetup
}
%
140
\xdef
\currentstructurecatcodes
{
\structureparameter
\s!catcodes
}
%
141
\xdef
\currentstructurelabel
{
\structureparameter
\c!label
}
%
142
\xdef
\currentstructurereference
{
\structureparameter
\c!reference
}
%
143
\xdef
\currentstructurereferenceprefix
{
\structureparameter
\c!referenceprefix
}
%
144
\xdef
\currentstructurebackreference
{
\structureparameter
\c!backreference
}
%
145
\xdef
\currentstructureshownumber
{
\structureparameter
\c!number
}
%
146
\xdef
\currentstructuresaveinlist
{
\structureparameter
\c!saveinlist
}
%
147
\xdef
\currentstructureincrementnumber
{
\structureparameter
\c!incrementnumber
}
%
148
\ifx
\currentstructureexpansion
\s!xml
149
\xmlstartraw
150
\xdef
\currentstructuretitle
{
\structureparameter
\c!title
}
%
151
\xdef
\currentstructurebookmark
{
\structureparameter
\c!bookmark
}
%
152
\xdef
\currentstructuremarking
{
\structureparameter
\c!marking
}
%
153
\xdef
\currentstructurelist
{
\structureparameter
\c!list
}
%
154
\xmlstopraw
155
\iflocation
\ifx
\currentstructurebookmark
\empty
\ifconditional
\c_strc_bookmarks_preroll
156
\strc_sectioning_autobookmark
\currentstructuretitle
157
\fi
\fi
\fi
158
\ifx
\currentstructurelist
\empty
159
\glet
\currentstructurelist
\currentstructuretitle
160
\fi
161
\glet
\currentstructurecoding
\s!xml
162
\else
163
\ifx
\currentstructureexpansion
\v!yes
164
\xdef
\currentstructuretitle
{
\structureparameter
\c!title
}
%
165
\xdef
\currentstructurebookmark
{
\structureparameter
\c!bookmark
}
%
166
\xdef
\currentstructuremarking
{
\structureparameter
\c!marking
}
%
167
\xdef
\currentstructurelist
{
\structureparameter
\c!list
}
%
168
\iflocation
\ifx
\currentstructurebookmark
\empty
\ifconditional
\c_strc_bookmarks_preroll
169
\strc_sectioning_autobookmark
\currentstructuretitle
170
\fi
\fi
\fi
171
\else
172
\xdef
\currentstructuretitle
{
\detokenizedstructureparameter
\c!title
}
%
173
\xdef
\currentstructurebookmark
{
\detokenizedstructureparameter
\c!bookmark
}
%
174
\xdef
\currentstructuremarking
{
\detokenizedstructureparameter
\c!marking
}
%
175
\xdef
\currentstructurelist
{
\detokenizedstructureparameter
\c!list
}
%
176
\iflocation
\ifx
\currentstructurebookmark
\empty
177
\ifconditional
\c_strc_bookmarks_preroll
178
\strc_sectioning_autobookmark
{
\structureparameter
\c!title
}
%
179
\else
180
\begingroup
181
\simplifycommands
182
\xdef
\currentstructurebookmark
{
\detokenize\expandafter
{
\normalexpanded
{
\structureparameter
\c!title
}}}
%
183
\endgroup
184
\fi
185
\fi
\fi
186
\fi
187
\ifx
\currentstructurelist
\empty
188
\glet
\currentstructurelist
\currentstructuretitle
189
\fi
190
\glet
\currentstructurecoding
\s!tex
191
\fi
192
\setnextinternalreference
193
\storeinternalreference
\currentstructurename
{
\the
\locationcount
}
%
194
\strc_sectioning_set_reference_prefix
195
\clf_setsectionentry
196
references
{
197
internal
\locationcount
198
% block {\currentsectionblock}
199
prefix
{
\currentstructurereferenceprefix
}
200
reference
{
\currentstructurereference
}
201
backreference
{
\currentstructurebackreference
}
202
}
203
directives
{
204
resetset
{
\structureparameter
\c!sectionresetset
}
205
}
206
metadata
{
207
kind
{
section
}
208
name
{
\currentstructurename
}
209
catcodes
\ifx
\currentstructurecatcodes
\empty
\catcodetable\else\csname
\currentstructurecatcodes
\endcsname\fi
\space
210
coding
{
\currentstructurecoding
}
211
\ifx
\currentstructurecoding
\s!xml
212
xmlroot
{
\xmldocument
}
213
\fi
214
\ifx
\currentstructurexmlsetup
\empty
\else
215
xmlsetup
{
\currentstructurexmlsetup
}
216
\fi
217
\ifx
\currentstructuresaveinlist
\v!no
218
nolist
\space
true
\space
219
\fi
220
\ifx
\currentstructureincrementnumber
\v!yes
221
increment
{
\currentstructureincrementnumber
}
222
\fi
223
}
224
titledata
{
225
label
{
\detokenize\expandafter
{
\currentstructurelabel
}}
226
title
{
\detokenize\expandafter
{
\currentstructuretitle
}}
227
\ifx
\currentstructurebookmark
\currentstructuretitle
\else
228
bookmark
{
\detokenize\expandafter
{
\currentstructurebookmark
}}
229
\fi
230
\ifx
\currentstructuremarking
\currentstructuretitle
\else
231
marking
{
\detokenize\expandafter
{
\currentstructuremarking
}}
232
\fi
233
\ifx
\currentstructuresaveinlist
\v!no
\else
234
\ifx
\currentstructurelist
\currentstructuretitle
\else
235
list
{
\detokenize\expandafter
{
\currentstructurelist
}}
236
\fi
237
\fi
238
}
239
numberdata
{
240
% block {\currentsectionblock}
241
\ifx
\currentstructureshownumber
\v!no
242
hidenumber
\space
true
\space
% space needed for parser
243
\fi
244
separatorset
{
\structureparameter
\c!sectionseparatorset
}
245
conversionset
{
\structureparameter
\c!sectionconversionset
}
246
conversion
{
\structureparameter
\c!sectionconversion
}
247
starter
{
\structureparameter
\c!sectionstarter
}
248
stopper
{
\structureparameter
\c!sectionstopper
}
249
set
{
\structureparameter
\c!sectionset
}
250
segments
{
\structureparameter
\c!sectionsegments
}
251
ownnumber
{
\currentstructureownnumber
}
252
language
{
\currentlanguage
}
% for the moment, needed for bookmarks conversion
253
criterium
{
\structureparameter
\c!criterium
}
254
}
255
userdata
{
\detokenize
{
#
3
}}
% will be converted to table at the lua end
256
\relax
257
\xdef
\currentstructurelistnumber
{
\clf_currentsectiontolist
}
%
258
% \currentstructuresynchronize has to be called someplace, since it introduces a node
259
\setstructuresynchronization
\currentstructurelistnumber
260
\endgroup
}
261 262
\let
\currentsectioncountervalue
\!!zerocount
% redefined later
263
\let
\previoussectioncountervalue
\!!zerocount
% redefined later
264 265
% We can access the (stored) data with the following macros.
266
%
267
% \def\MyHeadCommand #1#2{\framed{#1}\framed{#2 / \structureuservariable{subtitle}}}
268
% \def\MyListCommand#1#2#3{\externalfigure[\structurelistuservariable{figure}][height=5mm]#2}
269
%
270
% \setuphead[chapter][command=\MyHeadCommand]
271
% \setuplist[chapter][alternative=command,command=\MyListCommand]
272
%
273
% \starttext
274
% \setupheadertexts[chapter]
275
% \setupinteraction[state=start]
276
% \placebookmarks[chapter]
277
% \placelist[chapter]
278
% \startchapter[ownnumber=10,title=Ton,list=Hans,marking=Kees,bookmark=Bram][figure=cow.pdf,subtitle=oeps]
279
% \stopchapter
280
% \stoptext
281 282
% todo: #1 => "#1" ... adapt lua code for name and number
283 284
\def
\structurenumber
{
\clf_structurenumber
}
285
\def
\structuretitle
{
\clf_structuretitle
}
286
\def
\structurevariable
#
1
{
\clf_structurevariable
{
#
1
}}
287
\def
\structureuservariable
#
1
{
\clf_structureuservariable
{
#
1
}}
288
\def
\structurecatcodedget
#
1
{
\clf_structurecatcodedget
{
#
1
}}
% bad name
289
\def
\structuregivencatcodedget
#
1
#
2
{
\clf_structuregivencatcodedget
{
#
1
}
#
2
}
% bad name
290
\def
\structureautocatcodedget
#
1
#
2
{
\clf_structureautocatcodedget
{
#
1
}{
#
2
}}
291
\def
\namedstructurevariable
#
1
#
2
{
\clf_namedstructurevariable
{
#
1
}{
#
2
}}
292
\def
\namedstructureuservariable
#
1
#
2
{
\clf_namedstructureuservariable
{
#
1
}{
#
2
}}
293 294
% compatibility issue:
295
%
296
% \def\setfullsectionnumber #1{}
297
% \def\preparefullnumber #1{}
298
% \def\fullsectionnumber {1--1--1}
299
% \def\makesectionnumber [#1]{}
300
% \def\makesectionformat {}
301
% \def\sectionformat {1--1-1-1-1-1-1}
302
% \def\composedsectionnumber{}
303
% \def\@@kolist{}
304 305
% \setuphead[section] [separator=\separatorlist{?,!,*}]
306
% \setuphead[subsection][separator=\separatorlist{??,!!,**}]
307
%
308
% \let\spr\separatorlist % this will enable this feature
309
%
310
% \setuphead[section] [separator={?,!,*}]
311
% \setuphead[subsection][separator={??,!!,**}]
312
%
313
% \setupheads[separator={A,B,C,D,E,F}]
314
% \chapter{test}
315
% \section{test} \subsection{test} \subsection{test}
316
% \section{test} \subsection{test} \subsection{test}
317 318
% lua interface / names and interface might change
319 320
% \newconditional\c_strc_rendering_continuous % not used (mkii ?)
321 322
\def
\setstructurelevel
#
1
#
2
{
\clf_setstructurelevel
{
#
1
}{
#
2
}}
% name, level|parent
323
\def
\getstructurelevel
#
1
{
\clf_getstructurelevel
{
#
1
}}
% name
324
\def
\setstructurenumber
#
1
#
2
{
\clf_setstructurenumber
#
1
{
#
2
}}
% level, number (+/-)
325
\def
\getstructurenumber
#
1
{
\clf_getstructurenumber
\numexpr
#
1
\relax
}
% level
326
\def
\getsomestructurenumber
#
1
#
2
{
\clf_getsomestructurenumber
#
1
{
#
2
}}
% level, what
327
\def
\getfullstructurenumber
#
1
{
\clf_getfullstructurenumber
\numexpr
#
1
\relax
}
% level
328
\def
\getsomefullstructurenumber
#
1
#
2
{
\clf_getsomefullstructurenumber
#
1
{
#
2
}}
% level, what
329
\def
\getspecificstructuretitle
#
1
{
\clf_getspecificstructuretitle
{
#
1
}{
\headparameter
\s!catcodes
}}
330 331
% structure heads (like \startchapter)
332 333
% \c!deeptextcommand, \c!deepnumbercommand: undefined !
334
% \c!before \c!after \c!distance
335
% \c!page \c!header \c!text \c!footer=,
336
% \c!numbercommand \c!textcommand \c!ownnumber \c!number
337
% \c!file \c!grid \c!margintext
338
% \c!expansion \c!xmlsetup \s!catcode
339 340
\installcorenamespace
{
head
}
341
\installcorenamespace
{
headlevel
}
342
\installcorenamespace
{
headincrement
}
343
\installcorenamespace
{
headplace
}
344
\installcorenamespace
{
headmarkyes
}
345
\installcorenamespace
{
headmarknop
}
346 347
\installcommandhandler
\??head
{
head
}
\??head
348 349
\installmacrostack
\currenthead
350
\installmacrostack
\currentheadparent
351 352
\setuphead
[
%
353
%\c!after=,
354
%\c!align=,
355
%\c!aligntitle=,
356
\c!alternative
=
\v!normal
,
357
%\c!before=,
358
%\c!color=,
359
%\c!command=,
360
\c!continue
=
\v!yes
,
361
%\c!coupling=,
362
%\c!deepnumbercommand=,
363
%\c!deeptextcommand=,
364
%\c!default=,
365
\c!distance
=
\zeropoint
,
366
\c!textdistance
=
\zeropoint
,
367
\c!textwidth
=
\zeropoint
,
% signal too
368
\c!numberwidth
=
\zeropoint
,
% signal too
369
\c!width
=
\zeropoint
,
% signal too
370
\c!expansion
=
\v!no
,
371
%\c!file=,
372
%\c!footer=,
373
%\c!grid=,
374
\c!hang
=
\v!none
,
375
%\c!header=,
376
\c!incrementnumber
=
\v!yes
,
377
\c!indentnext
=
\v!no
,
378
%\c!label=,
379
%\c!limittext=\languageparameter\c!limittext,
380
\c!margin
=
\zeropoint
,
381
%\c!margintext=,
382
\c!number
=
\v!yes
,
383
\c!numbercolor
=
\headparameter
\c!color
,
384
\c!textcolor
=
\headparameter
\c!color
,
385
\c!numberstyle
=
\headparameter
\c!style
,
386
\c!textstyle
=
\headparameter
\c!style
,
387
%\c!numbercommand=,
388
%\c!textcommand=,
389
\c!ownnumber
=
\v!no
,
390
%\c!page=,
391
\c!placehead
=
\v!yes
,
392
\c!sectionconversionset
=
\s!default
,
393
\c!sectionnumber
=
\v!yes
,
394
%\c!sectionsegments=,
395
\c!sectionseparatorset
=
\s!default
,
396
\c!sectionset
=
\v!all
,
397
\c!interlinespace
=
,
398
%\c!sectionstopper=,
399
%\c!sectionstarter=,
400
%\c!strut=,
401
%\c!style=,
402
%\c!text=,
403
%\c!tolerance=,
404
%\c!beforesection=\directsetup{document:\currenthead:start}, % these might become defaults i.e. acpect document: namespace
405
%\c!insidesection=\directsetup{document:\currenthead:inside}, % these might become defaults i.e. acpect document: namespace
406
%\c!aftersection=\directsetup{document:\currenthead:stop}, % these might become defaults i.e. acpect document: namespace
407
]
408 409
\let
\setupheads\setuphead
% will go
410 411
\appendtoks
412
\ifx
\currentheadparent
\empty
413
\edef
\currentheaddefault
{
\headparameter
\c!default
}
%
414
\edef
\currentheadsection
{
\headparameter
\c!section
}
%
415
\ifx
\currenthead
\currentheaddefault
416
\let
\currentheadparent
\currentheadsection
417
\else\ifx
\currentheaddefault
\empty
418
\let
\currentheadparent
\currentheadsection
419
\else
420
\let
\currentheadparent
\currentheaddefault
421
\fi\fi
422
\normalexpanded
{
%
423
\setheadparameter
{
\c!label
}{
\currenthead
}
%
424
\setheadparameter
{
\c!coupling
}{
\currenthead
}
%
425
\setheadparameter
{
\s!parent
}{
\??head
\currentheadparent
}
%
426
\definemarking
[
\currenthead
]
[
\currentheadsection
]
%
427
\definemarking
[
\currenthead
\v!number
][
\currentheadsection
]
%
428
\setupmarking
[
\currenthead
]
[
\c!filtercommand
=
\noexpand
\sectionheadmarkingtitle
{
\currenthead
}
]
%
429
\setupmarking
[
\currenthead
\v!number
][
\c!filtercommand
=
\noexpand
\sectionheadmarkingnumber
{
\currenthead
}
]
%
430
}
%
431
\doifelselist
\currenthead
\donothing
432
{
\definelist
[
\currenthead
][
\c!prefix
=
\v!no
]
}
%
433
% we can't do this now for backward compatibility reasons
434
% \doifelselist\currenthead\donothing
435
% {\normalexpanded{\definelist[\currenthead][\currentheadparent][\c!prefix=\v!no]}}%
436
\else
437
\normalexpanded
{
%
438
\setheadparameter
{
\c!label
}{
\currenthead
}
%
439
\setheadparameter
{
\c!coupling
}{
\currentheadparent
}
%
440
\definemarking
[
\currenthead
]
[
\currentheadparent
]
%
441
\definemarking
[
\currenthead
\v!number
][
\currentheadparent
\c!number
]
%
442
}
%
443
\doifelselist
\currenthead
\donothing
444
{
\normalexpanded
{
\definelist
[
\currenthead
][
\currentheadparent
][
\c!prefix
=
\v!no
]
}}
%
445
\fi
446
\presetlabeltext
[
\currenthead
=]
%
447
\the
\everysetuphead
448
\to
\everydefinehead
449 450
\newtoks
\everyredefinehead
451 452
\appendtoks
453
\the
\everyredefinehead
454
\to
\everydefinehead
455 456
\appendtoks
457
\setstructurelevel
\currenthead
{
\thenamedheadlevel
\currenthead
}
%
458
\to
\everyredefinehead
459 460
\appendtoks
461
% beware, this is a global register
462
\begingroup
463
\edef
\currentsectionheadcoupling
{
\sectionheadcoupling
\currenthead
}
%
464
\edef
\currentsectionheadsection
{
\sectionheadsection
\currentsectionheadcoupling
}
%
465
\edef
\currentsectionlevel
{
\sectionlevel
\currentsectionheadsection
}
%
466
\clf_registersection
{
\currenthead
}
{
467
coupling
{
\currentsectionheadcoupling
}
468
section
{
\currentsectionheadsection
}
469
level
\space
\currentsectionlevel
\space
% space needed for parser
470
parent
{
\currentheadparent
}
471
}
%
472
\endgroup
473
\to
\everyredefinehead
474 475
\appendtoks
476
% \setevalue{\e!next \currenthead}{\donexthead [\currenthead]}%
477
\setuevalue
{
\e!start
\currenthead
}{
\strc_sectioning_start
[
\currenthead
]
}
%
478
\setuevalue
{
\e!stop
\currenthead
}{
\strc_sectioning_stop
[
\currenthead
]
}
%
479
\to
\everydefinehead
480 481
% so \subject as well as \section will need two commands when ownnumber
482
% is used (one can disable it anyway for subject) .. this is not downward
483
% compatible but better
484 485
\appendtoks
486
\ifx
\currenthead
\empty
\else
487
\doifelse
{
\headparameter
\c!ownnumber
}
\v!yes
488
{
\setuevalue
\currenthead
{
\strc_sectioning_handle_own
[
\currenthead
]
}}
489
{
\setuevalue
\currenthead
{
\strc_sectioning_handle_nop
[
\currenthead
]
}}
%
490
\fi
491
\to
\everysetuphead
492 493
\unexpanded
\def
\doredefinehead
#
1
#
2
% called at lua end
494
{
\push_macro_currenthead
495
\push_macro_currentheadparent
496
\edef
\currenthead
{
#
1
}
%
497
\edef
\currentheadparent
{
#
2
}
%
498
\the
\everyredefinehead
\relax
499
\pop_macro_currentheadparent
500
\pop_macro_currenthead
}
501 502
\let
\currentnamedsection
\empty
503 504
\installmacrostack
\currentnamedsection
505 506
\unexpanded
\def
\startnamedsection
507
{
\dotripleempty
\strc_sectioning_start_named_section
}
508 509
% todo: add grouping but where: before/after trickery .. probably inside because one can always add
510
% grouping to the before/after settings
511 512
\unexpanded
\def
\stopnamedsection
513
{
\normalexpanded
{
\strc_sectioning_stop
[
\currentnamedsection
]
}}
514 515
% structure sections (the parents of chapter etc)
516 517
\let
\firstsectionname
\empty
518
\let
\lastsectionname
\empty
519 520
\let
\resetallstructuremarks
\relax
521
\let
\resetcurrentstructuremarks
\relax
522
\let
\resetcurrentstructuremarkswithpage
\relax
523 524
\def
\resetallstructuremarks
{
\resetmarking
[
\firstsectionname
]
}
% will become option (was \v!section-1)
525
\def
\resetcurrentstructuremarks
{
\resetmarking
[
\lastsectionname
]
}
% will become option
526
%def\resetcurrentstructuremarkswithpage{\resetmarking[\lastsectionname]} % will become option
527 528
% We could use a commandhandler here but sections are somewhat special in the
529
% sense that we have two ways of chaining: the main section (levels) as well
530
% as rendering (head).
531 532
% -2 = text
533
% -1 = manual
534
% 0 = block
535
% +1 = structurelevel 1 .. n
536 537
\newcount
\maxstructuredepth
538 539
\def
\sectionlevel
#
1
%
540
{
\csname
\??headlevel
\ifcsname
\??headlevel
#
1
\endcsname
#
1
\else
\v!none
\fi\endcsname
}
541 542
\def
\namedsectionlevel
#
1
#
2
% direct indirect
543
{
\csname
\??headlevel
544
\ifcsname
\??headlevel
#
1
\endcsname
545
#
1
%
546
\else\ifcsname
\??headlevel
#
2
\endcsname
547
#
2
%
548
\else
549
\v!none
550
\fi\fi
551
\endcsname
}
552 553
\def
\xthenamedheadlevel
#
1
%
554
{
\namedsectionlevel
{
#
1
}{
\sectionheadsection
{
\sectionheadcoupling
{
#
1
}}}}
555 556
\setvalue
{
\??headlevel\v!block
}{
0
}
557
\setvalue
{
\??headlevel\v!none
}{
-
1
}
558
\setvalue
{
\??headlevel\v!text
}{
-
2
}
559
\setvalue
{
\??headlevel\v!head
}{
-
3
}
560 561
\newtoks
\everydefinesection
562 563
\unexpanded
\def
\definesection
[#
1
]
%
564
{
\ifcsname
\??headlevel
#
1
\endcsname
\else
565
\edef
\currentsection
{
#
1
}
% not used, will go
566
\edef
\currenthead
{
#
1
}
%
567
\global\advance
\maxstructuredepth
\plusone
568
\setevalue
{
\??headlevel
#
1
}{
\the
\maxstructuredepth
}
%
569
\setstructurelevel
{
#
1
}{
\sectionlevel
{
#
1
}}
%
570
\normalexpanded
{
\setheadparameter
{
\s!parent
}{
\??head
\lastsectionname
}}
% TO BE CHECKED, WE HAVE A HELPER
571
\the
\everydefinesection
572
% so far for these default inheritances
573
\definemarking
[#
1
]
%
574
\ifnum
\maxstructuredepth
>
\plusone
575
\normalexpanded
{
\relatemarking
[#
1
][
\lastsectionname
]
}
% so, the parent will reset the child
576
\fi
577
\xdef
\lastsectionname
{
#
1
}
%
578
\ifx
\firstsectionname
\empty
579
\glet
\firstsectionname
\lastsectionname
580
\fi
581
\fi
}
582 583
\unexpanded
\def
\setupsection
584
{
\dotripleempty
\strc_sectioning_setup
}
585 586
\def
\strc_sectioning_setup
[#
1
][#
2
][#
3
]
%
587
{
\ifcsname
\??headlevel
#
1
\endcsname
588
\strc_sectioning_setup_indeed
[#
1
][#
2
][#
3
]
%
589
\else
590
\strc_sectioning_setup_indeed
[
\sectionheadsection
{
#
1
}
][#
2
][#
3
]
%
591
\fi
}
592 593
\def
\strc_sectioning_setup_indeed
[#
1
][#
2
][#
3
]
%
594
{
\push_macro_currenthead
595
\ifthirdargument
596
\edef
\currenthead
{
#
1
#
2
}
% % not used at any more in mkiv (sets now)
597
\setupcurrenthead
[#
3
]
%
598
\else
599
\edef
\currenthead
{
#
1
}
%
600
\setupcurrenthead
[#
2
]
%
601
\fi
602
\pop_macro_currenthead
}
603 604
% we share the parameters as sections are roots of heads so eventually we can
605
% consider \definesection -> \definehead with one argument
606 607
\appendtoks
608
% This is a rather practical default that we don't want to
609
% be part of the parent chain lookup mechanism; it's also
610
% mkii compatible. Somewhat weird that it's part of the
611
% top level structure but it will be flattened anyway.
612
\let
\currenthead
\currentsection
%
613
\setheadparameter
\c!textstyle
{
\directheadparameter
\c!style
}
%
614
\setheadparameter
\c!textcolor
{
\directheadparameter
\c!color
}
%
615
\setheadparameter
\c!numberstyle
{
\directheadparameter
\c!style
}
%
616
\setheadparameter
\c!numbercolor
{
\directheadparameter
\c!color
}
%
617
\to
\everydefinesection
618 619
% head -> head
620 621
\def
\sectionheadmarkingtitle
#
1
#
2
{
\clf_markingtitle
{
#
1
}{
#
2
}}
622
\def
\sectionheadmarkingnumber
#
1
#
2
{
\clf_markingnumber
{
#
1
}{
#
2
}}
623 624
\def
\sectionheadcoupling
#
1
{
\namedheadparameter
{
#
1
}
\c!coupling
}
625
\def
\sectionheadsection
#
1
{
\namedheadparameter
{
#
1
}
\c!section
}
626 627
% head construction
628 629
\unexpanded
\def
\strc_sectioning_handle_own
{
\dodoubleempty
\strc_sectioning_handle_own_indeed
}
% [ref] {nr} {title}
630
\unexpanded
\def
\strc_sectioning_handle_nop
{
\dodoubleempty
\strc_sectioning_handle_nop_indeed
}
% [ref] {title}
631
\unexpanded
\def
\strc_sectioning_start
{
\dotripleempty
\strc_sectioning_start_named_section
}
% [settings] [userdata] !!! also used at lua end
632 633
\newconditional
\currentstructureown
634 635
\newtoks
\everybeforehead
% hook, todo: before/after keys
636
\newtoks
\everyafterhead
% hook, todo: before/after keys
637 638
\unexpanded
\def
\strc_sectioning_handle_own_indeed
[#
1
][#
2
]#
3
#
4
%
639
{
\settrue
\currentstructureown
640
\triggerautostructurelevel
641
\strc_sectioning_handle
{
#
1
}{
\c!reference
=
{
#
2
}
,
\c!ownnumber
=
{
#
3
}
,
\c!title
=
{
#
4
}}{}}
% name ref nr title --
642 643
% \unexpanded\def\strc_sectioning_handle_nop_indeed[#1][#2]% for taco: [key=value] variant
644
% {\setfalse\currentstructureown
645
% \triggerautostructurelevel
646
% \doifelseassignment{#2}\strc_sectioning_handle_nop_indeed_yes\strc_sectioning_handle_nop_indeed_nop{#1}{#2}}
647 648
\unexpanded
\def
\strc_sectioning_handle_nop_indeed
[#
1
][#
2
]
% for taco: [key=value] variant
649
{
\setfalse
\currentstructureown
650
\triggerautostructurelevel
651
\ifcondition
\validassignment
{
#
2
}
%
652
\expandafter
\strc_sectioning_handle_nop_indeed_yes
653
\else
654
\expandafter
\strc_sectioning_handle_nop_indeed_nop
655
\fi
656
{
#
1
}{
#
2
}}
657 658
\unexpanded
\def
\strc_sectioning_handle_nop_indeed_yes
#
1
#
2
%
659
{
\strc_sectioning_handle
{
#
1
}{
#
2
}{}}
660 661
\unexpanded
\def
\strc_sectioning_handle_nop_indeed_nop
#
1
#
2
#
3
%
662
{
\strc_sectioning_handle
{
#
1
}{
\c!reference
=
{
#
2
}
,
\c!title
=
{
#
3
}}{}}
% name ref nr title --
663 664
\unexpanded
\def
\strc_sectioning_start_named_section
[#
1
][#
2
][#
3
]
% for the moment no grouping, too annoying with page breaks
665
{
\push_macro_currentnamedsection
666
\push_macro_currentstructurereferenceprefix
667
\edef
\currentnamedsection
{
#
1
}
%
668
\setfalse
\currentstructureown
669
%\globalpushmacro\currenthead % this does not work out well
670
\xdef
\currenthead
{
#
1
}
%
671
\setsystemmode
\currenthead
% new, also here now
672
\headparameter
\c!beforesection
% beware, no users vars set yet
673
\the
\everybeforehead
674
\strc_sectioning_handle
{
#
1
}{
#
2
}{
#
3
}
% name -- -- -- userdata (we might move the tagged to here)
675
% potential: \bgroup (can be optional: grouped = yes)
676
\headparameter
\c!insidesection
}
677 678
\unexpanded
\def
\strc_sectioning_stop
[#
1
]
% !!! also used at lua end
679
{
\dostoptagged
680
\dostoptagged
681
% potential: \egroup
682
%\globalpopmacro\currenthead % so we do a hard recover
683
\xdef
\currenthead
{
#
1
}
% recover
684
\headparameter
\c!aftersection
685
\the
\everyafterhead
686
\resetsystemmode
\currenthead
687
\pop_macro_currentstructurereferenceprefix
688
\pop_macro_currentnamedsection
}
% new, also here now
689 690
\let
\dostarthead
\strc_sectioning_start
% used at lua end
691
\let
\dostophead
\strc_sectioning_stop
% used at lua end
692 693
% \newconditional\structurereversesectionnumbers % todo: key/val
694 695
\newconditional
\c_strc_sectioning_to_list
696
\newconditional
\c_strc_sectioning_increment
697
\newconditional
\c_strc_sectioning_place
698
\newconditional
\c_strc_sectioning_empty
699
\newconditional
\c_strc_sectioning_hidden
700
\newconditional
\c_strc_sectioning_section
701 702
\newconditional
\headshownumber
% public
703
\newconditional
\headisdisplay
% public
704
\newconditional
\headissomewhere
% public
705 706
\setvalue
{
\??headincrement\v!yes
}{
\settrue
\c_strc_sectioning_increment
\settrue
\c_strc_sectioning_to_list
}
707
\setvalue
{
\??headincrement\v!no
}{
\setfalse
\c_strc_sectioning_increment
\setfalse
\c_strc_sectioning_to_list
}
708
\setvalue
{
\??headincrement\v!list
}{
\setfalse
\c_strc_sectioning_increment
\settrue
\c_strc_sectioning_to_list
}
709
\setvalue
{
\??headincrement\s!empty
}{
\settrue
\c_strc_sectioning_increment
\settrue
\c_strc_sectioning_to_list
}
710 711
\unexpanded
\def
\strc_sectioning_initialize_increment
712
{
\edef
\currentheadincrement
{
\headparameter
\c!incrementnumber
}
%
713
\ifcsname
\??headincrement
\currentheadincrement
\endcsname
714
\lastnamedcs
715
\else
716
\settrue
\c_strc_sectioning_increment
\settrue
\c_strc_sectioning_to_list
717
% \filterheadnumber
718
\fi
}
719 720
\def
\filterheadnumber
721
{
\settrue
\c_strc_sectioning_increment
722
\settrue
\c_strc_sectioning_to_list
723
\ifx
\currentproduct
\empty
724
% todo : filter from other toc (number, file, title)
725
% use : \currentheadincrement as spec
726
\fi
}
727 728
\setvalue
{
\??headplace\v!yes
}
%
729
{
\setfalse
\c_strc_sectioning_empty
730
\settrue
\c_strc_sectioning_place
731
\setfalse
\c_strc_sectioning_hidden
732
\setfalse
\c_strc_sectioning_section
}
733 734
\setvalue
{
\??headplace\v!empty
}
%
735
{
\settrue
\c_strc_sectioning_empty
736
\settrue
\c_strc_sectioning_place
737
\setfalse
\c_strc_sectioning_hidden
738
\setfalse
\c_strc_sectioning_section
}
739 740
\setvalue
{
\??headplace\v!no
}
%
741
{
\settrue
\c_strc_sectioning_empty
742
\setfalse
\c_strc_sectioning_place
743
\setfalse
\c_strc_sectioning_hidden
744
\setfalse
\c_strc_sectioning_section
}
745 746
\setvalue
{
\??headplace\v!hidden
}
%
747
{
\settrue
\c_strc_sectioning_empty
748
\setfalse
\c_strc_sectioning_place
749
\settrue
\c_strc_sectioning_hidden
750
\setfalse
\c_strc_sectioning_section
}
751 752
\setvalue
{
\??headplace\v!section
}
%
753
{
\settrue
\c_strc_sectioning_empty
754
\setfalse
\c_strc_sectioning_place
755
\settrue
\c_strc_sectioning_hidden
756
\settrue
\c_strc_sectioning_section
}
757 758
\unexpanded
\def
\strc_sectioning_initialize_placement
759
{
\expandnamespaceparameter
\??headplace
\headparameter
\c!placehead\v!yes
}
760 761
\newmode
\v!sectionnumber
762 763
\def
\dosetstructureheadnumbercontent
764
{
\setsystemmode
\v!sectionnumber
765
\settrue
\headshownumber
}
% why ?
766 767
\def
\doresetstructureheadnumbercontent
768
{
\resetsystemmode
\v!sectionnumber
769
\setfalse
\headshownumber
}
% why ?
770 771
\unexpanded
\def
\strc_sectioning_initialize_number
772
{
\edef
\p_number
{
\sectionblockparameter
\c!number
}
%
773
\ifx
\p_number
\v!yes
774
\edef
\p_number
{
\headparameter
\c!number
}
%
775
\ifx
\p_number
\v!yes
776
\settrue
\headshownumber
777
\else
778
\setfalse
\headshownumber
779
\fi
780
\else
781
\setfalse
\headshownumber
782
\fi
}
783 784
% Beware, we do need some node for anchoring marks and normally a zwnj will
785
% do but it interferes so we deal with it at the \LUA\ end.
786 787
\newtoks
\everyheadsynchronization
788 789
% \appendtoks
790
% \currentstructuresynchronize
791
% \to \everyheadsynchronization
792 793
\let
\currentstructuresynchronize
\donothing
794 795
\appendtoks
796
\currentstructuresynchronize
797
\glet
\currentstructuresynchronize
\donothing
798
\to
\everyheadsynchronization
799 800
\unexpanded
\def
\theheadsynchonization
801
{
% no, interferes: \signalcharacter
802
\the
\everyheadsynchronization
}
803 804
% BEWARE: \marking[section]{my text} does not work as we use list indices instead
805
% so we need a 'keep track of raw set option' (or maybe a funny internal prefix)
806 807
\unexpanded
\def
\setheadmarking
% li:: so that we can use \marking[section]{Taco needed this}
808
{
\strc_sectioning_delayed_flush
809
\normalexpanded
{
\setmarking
[
\currenthead
]
{
li
:
:
\currentstructurelistnumber
}}}
810 811
\let
\deepstructurenumbercommand
\relax
812
\let
\deepstructuretitlecommand
\relax
813 814
\unexpanded
\def
\fullheadnumber
815
{
\edef
\currentheadlabeltag
{
\currentsectionblock
\c!label
}
%
816
\dostarttagged
\t!sectionnumber
\empty
817
\labeltexts
818
{
\headparameter
\currentheadlabeltag
}
819
{
\ifx
\deepstructurenumbercommand
\relax
820
\structurenumber
821
\else
822
\normalexpanded
{
\noexpand
\deepstructurenumbercommand
{
\structurenumber
}}
%
823
\fi
}
%
824
\dostoptagged
}
825 826
\unexpanded
\def
\fullheadtitle
827
{
\dostarttagged
\t!sectiontitle
\empty
828
\ifx
\deepstructuretitlecommand
\relax
829
\structuretitle
830
\else
831
\normalexpanded
{
\noexpand
\deepstructuretitlecommand
{
\structuretitle
}}
%
832
\fi
833
\dostoptagged
}
834 835
\let
\currenthead
\empty
836
\let
\currentheadcoupling
\empty
837
\let
\currentheadsection
\empty
838
\let
\currentheadlevel
\!!zerocount
839
\let
\currentheadcounter
\!!zerocount
840 841
\let
\strc_show_used
\relax
842 843
\installtextracker
844
{
structures
.
showused
}
845
{
\let
\strc_show_used
\clf_showstructure
}
846
{
\let
\strc_show_used
\relax
}
847 848
\appendtoks
849
\strc_show_used
850
\to
\everystoptext
851 852
\unexpanded
\def
\placeheadtext
{
\dosingleempty
\strc_sectioning_place_head_text
}
% use with care
853
\unexpanded
\def
\placeheadnumber
{
\dosingleempty
\strc_sectioning_place_head_number
}
% use with care
854 855
\unexpanded
\def
\strc_sectioning_report
{
\clf_reportstructure
}
856 857
\ifdefined
\strc_rendering_initialize_style_and_color
\else
858 859
\unexpanded
\def
\strc_rendering_initialize_style_and_color
#
1
#
2
%
860
{
\dontconvertfont
861
\useheadstyleandcolor
\c!style\c!color
862
\useheadstyleandcolor
#
1
#
2
%
863
\setupinterlinespace
}
864 865
\fi
866 867
\def
\strc_sectioning_place_head_text
[#
1
]
%
868
{
\dontleavehmode
869
\begingroup
870
\unexpanded
\def
\\
{
\space
}
% messy here, but the default (and needs to be grouped)
871
\global
\settrue
\headisdisplay
% triggers interlinespace checking
872
\edef
\currenthead
{
#
1
}
%
873
\strc_rendering_initialize_style_and_color
\c!textstyle\c!textcolor
874
\relax
875
\getspecificstructuretitle
{
\thenamedheadlevel
{
#
1
}}
%
876
\endgraf
877
\endgroup
}
878 879
\def
\strc_sectioning_place_head_number
[#
1
]
%
880
{
\dontleavehmode
881
\begingroup
882
\global
\settrue
\headisdisplay
% triggers interlinespace checking
883
\edef
\currenthead
{
#
1
}
%
884
\strc_rendering_initialize_style_and_color
\c!numberstyle\c!numbercolor
885
\relax
886
\getfullstructurenumber
{
\thenamedheadlevel
{
#
1
}}
%
887
\endgraf
888
\endgroup
}
889 890
\ifdefined
\triggerautostructurelevel
\else
\let
\triggerautostructurelevel
\relax
\fi
891 892
\newtoks
\everybeforesectionheadhandle
893
\newtoks
\everyaftersectionheadhandle
894 895
\def
\strc_sectioning_handle
#
1
#
2
#
3
% name data userdata (we can move #1 to the caller)
896
{
\xdef
\currenthead
{
#
1
}
%
897
\xdef
\currentheadcoupling
{
\sectionheadcoupling
\currenthead
}
%
898
\xdef
\currentheadsection
{
\sectionheadsection
\currentheadcoupling
}
%
899
\xdef
\currentheadlevel
{
\sectionlevel
\currentheadsection
}
%
900
%
901
%\writestatus\m!system{setup: \currenthead,\currentheadcoupling,\currentheadsection,\currentheadlevel}%
902
%
903
\strc_sectioning_initialize_autolevel
904
\strc_sectioning_initialize_increment
905
\strc_sectioning_initialize_placement
906
\strc_sectioning_initialize_number
907
%
908
\the
\everybeforesectionheadhandle
909
%
910
% todo: also mark (for header)
911
%
912
% we might remove the lower level
913
%
914
% not here, after optional \page: \strc_sectioning_register{#1}{#2}{#3}%
915
%
916
% \xdef\currentheadcounter{\currentsectioncountervalue}% lua call
917
%
918
% \currentstructuresynchronize % will move
919
%
920
\let
\getheadnumber
\empty
921
\let
\getheadtitle
\empty
922
\let
\getheadsyncs
\empty
923
\ifconditional
\c_strc_sectioning_increment
924
\ifconditional
\c_strc_sectioning_place
925
\strc_sectioning_before_yes
926
\strc_sectioning_register
{
#
1
}{
#
2
}{
#
3
}
% after optional \page
927
\strc_sectioning_report
928
\dostarttagged
\t!sectioncaption
\empty
929
\let
\getheadsyncs
\theheadsynchonization
930
\let
\getheadtitle
\fullheadtitle
931
\ifconditional
\headshownumber
932
\let
\getheadnumber
\fullheadnumber
933
\strc_rendering_place_head_number_and_text
934
\else
935
\strc_rendering_place_head_text
936
\fi
937
\dostoptagged
938
\strc_sectioning_after_yes
939
\else
\ifconditional
\c_strc_sectioning_hidden
940
\strc_sectioning_register
{
#
1
}{
#
2
}{
#
3
}
% after optional \page
941
\strc_sectioning_report
942
\dostarttagged
\t!sectioncaption
\empty
943
\let
\getheadsyncs
\theheadsynchonization
944
\ifconditional
\c_strc_sectioning_section
945
\strc_rendering_place_head_section
946
\else
947
\strc_rendering_place_head_hidden
% only something when tracing
948
\fi
949
\dostoptagged
950
\else
951
\strc_sectioning_before_nop
% toegevoegd ivm subpaginanr / tug sheets
952
\strc_sectioning_register
{
#
1
}{
#
2
}{
#
3
}
% after optional \page
953
\strc_sectioning_report
954
\dostarttagged
\t!sectioncaption
\empty
955
\let
\getheadsyncs
\theheadsynchonization
956
\strc_rendering_place_head_empty
% just flush 'm
957
\dostoptagged
958
\strc_sectioning_after_nop
959
\fi\fi
960
\else
961
\ifconditional
\c_strc_sectioning_place
962
\strc_sectioning_before_yes
963
\strc_sectioning_register
{
#
1
}{
#
2
}{
#
3
}
% after optional \page
964
\strc_sectioning_report
965
\dostarttagged
\t!sectioncaption
\empty
966
\let
\getheadsyncs
\theheadsynchonization
967
\let
\getheadtitle
\fullheadtitle
968
\strc_rendering_place_head_text
969
\dostoptagged
970
\strc_sectioning_after_yes
971
\else
\ifconditional
\c_strc_sectioning_hidden
972
\strc_sectioning_register
{
#
1
}{
#
2
}{
#
3
}
% after optional \page
973
\strc_sectioning_report
974
\let
\getheadsyncs
\theheadsynchonization
975
\dostarttagged
\t!sectioncaption
\empty
976
\ifconditional
\c_strc_sectioning_section
977
\strc_rendering_place_head_section
978
\else
979
\strc_rendering_place_head_hidden
% only something when tracing
980
\fi
981
\dostoptagged
982
\else
983
% do nothing / should be vbox to 0pt
984
\strc_sectioning_before_nop
985
\strc_sectioning_register
{
#
1
}{
#
2
}{
#
3
}
% after optional \page
986
\strc_sectioning_report
987
\dostarttagged
\t!sectioncaption
\empty
988
\let
\getheadsyncs
\theheadsynchonization
989
\strc_rendering_place_head_empty
% just flush 'm
990
\dostoptagged
991
\strc_sectioning_after_nop
992
\fi\fi
993
\fi
994
%
995
\the
\everyaftersectionheadhandle
996
%
997
\setfalse
\c_strc_sectioning_ignore_page
998
% ignorespaces prevents spaces creeping in when after=\dontleavehmode
999
\dostarttagged
\t!sectioncontent
\empty
1000
\ifconditional
\headisdisplay
1001
\expandafter\ignorespaces
1002
\else
1003
\expandafter\ignorepars
1004
\fi
}
1005 1006
% typesetting (the getters are public)
1007 1008
\unexpanded
\def
\strc_rendering_place_head_number_and_text
1009
{
\setheadmarking
1010
\getheadnumber
/
\getheadtitle
1011
\getheadsyncs
}
1012 1013
\unexpanded
\def
\strc_rendering_place_head_text
1014
{
\setheadmarking
1015
\getheadtitle
1016
\getheadsyncs
}
1017 1018
\unexpanded
\def
\strc_rendering_place_head_empty
1019
{
\setheadmarking
1020
\getheadsyncs
}
1021 1022
\installcorenamespace
{
hiddenheadattr
}
1023
\installcorenamespace
{
hiddenheadsync
}
1024 1025
% todo: when in the page builder we need to resolve the marking immediately
1026
% because otherwise we have an async
1027 1028
\newbox
\b_sectioning_delayed
1029 1030
\def
\strc_sectioning_delayed_flush
1031
{
\ifvoid
\b_sectioning_delayed
\else
1032
\smashboxed
\b_sectioning_delayed
1033
\fi
}
1034 1035
\unexpanded
\def
\strc_rendering_place_head_section
% see hidden below
1036
{
\global\setbox
\b_sectioning_delayed
\hpack
\bgroup
1037
\setmarking
[
\currentheadcoupling
]
{
li
:
:
\currentstructurelistnumber
}
%
1038
\hpack
\headreferenceattributes
{}
% also does the mark
1039
\theheadsynchonization
1040
\egroup
}
1041 1042
\unexpanded
\def
\strc_rendering_place_head_hidden
% maybe trialtypesetting check
1043
{
\setxvalue
{
\??hiddenheadattr
\currenthead
}
%
1044
{
\headreferenceattributes
}
% can be used when making a box
1045
\setxvalue
{
\??hiddenheadsync
\currenthead
}
%
1046
{
\noexpand
\letgvalue
{
\??hiddenheadsync
\currenthead
}
\relax
1047
\noexpand
\setmarking
[
\currentheadcoupling
]
{
li
:
:
\currentstructurelistnumber
}
%
1048
\hpack
\headreferenceattributes
{}
% otherwise no destination ... maybe tag ref as hidden and fall back on page reference
1049
\theheadsynchonization
}}
% and it's a node anyway
1050 1051
\def
\synchronizehead
#
1
{
\csname
\??hiddenheadsync
#
1
\endcsname
}
1052
\def
\theheadreferenceattributes
#
1
{
\csname
\??hiddenheadattr
#
1
\endcsname
}
1053 1054
\unexpanded
\def
\placerawheaddata
[#
1
]
{
\synchronizehead
{
#
1
}}
1055
\unexpanded
\def
\placerawheadtext
[#
1
]
{
\getspecificstructuretitle
{
\thenamedheadlevel
{
#
1
}}}
1056
\unexpanded
\def
\placerawheadnumber
[#
1
]
{
\getfullstructurenumber
{
\thenamedheadlevel
{
#
1
}}}
1057 1058
\unexpanded
\def
\repeathead
[#
1
]
%
1059
{
\begingroup
1060
\setupinteraction
[
\c!state
=
\v!stop
]
%
1061
\def
\currenthead
{
#
1
}
1062
\strc_sectioning_initialize_placement
1063
\strc_sectioning_initialize_number
1064
\dostarttagged
\t!sectioncaption
\empty
1065
\let
\getheadsyncs
\relax
1066
\def
\getheadtitle
{
\getmarking
[#
1
]
}
1067
\def
\getheadnumber
{
\getmarking
[#
1
\v!number
]
}
1068
\strc_sectioning_before_yes
1069
\ifconditional
\headshownumber
1070
\strc_rendering_place_head_number_and_text
1071
\else
1072
\strc_rendering_place_head_text
1073
\fi
1074
\dostoptagged
1075
\strc_sectioning_after_yes
1076
\endgroup
}
1077 1078
% \setuphead[chapter][placehead=hidden]
1079
% \chapter {test}
1080
%
1081
% %(\synchronizehead{chapter}) % \getheadsyncs
1082
% %(\getfullstructurenumber{\thenamedheadlevel{chapter}})
1083
% %(\getspecificstructuretitle{\thenamedheadlevel{chapter}})
1084
%
1085
% (\placerawheaddata [chapter])
1086
% (\placerawheadnumber[chapter])
1087
% (\placerawheadtext [chapter])
1088 1089
% pagebreaks
1090 1091
\letvalue
{
\??headmarknop\v!page
}
\donothing
1092
\setvalue
{
\??headmarknop\v!reset
}{
\resetcurrentstructuremarks
}
1093
\letvalue
{
\??headmarknop\s!unknown
}
\donothing
1094 1095
\letvalue
{
\??headmarkyes\v!page
}
\donothing
% to be checked: {\resetcurrentstructuremarks}
1096
\setvalue
{
\??headmarkyes\v!reset
}{
\resetcurrentstructuremarks
}
1097
\letvalue
{
\??headmarkyes\s!unknown
}
\donothing
1098 1099
\def
\strc_sectioning_check_layout
1100
{
\edef
\p_page
{
\headparameter
\c!page
}
%
1101
\ifx
\p_page
\empty
1102
\strc_sectioning_check_layout_nop
1103
\else
1104
\strc_sectioning_check_layout_yes
1105
\fi
}
1106 1107
\def
\strc_sectioning_check_layout_nop
1108
{
\expandnamespaceparameter
\??headmarknop
\headparameter
\c!marking\s!unknown
}
1109 1110
\def
\strc_sectioning_check_layout_yes
1111
{
\page
[
\p_page
]
%
1112
\expandnamespaceparameter
\??headmarkyes
\headparameter
\c!marking\s!unknown
1113
\edef
\p_header
{
\headparameter
\c!header
}
%
1114
\ifx
\p_header
\empty
\else
1115
\doifelselayouttextline
\v!header
{
\normalexpanded
{
\setuplayouttext
[
\v!header
][
\c!state
=
\p_header
]
}}
\donothing
1116
\fi
1117
\edef
\p_text
{
\headparameter
\c!text
}
%
1118
\ifx
\p_text
\empty
\else
1119
\doifelselayouttextline
\v!text
{
\normalexpanded
{
\setuplayouttext
[
\v!text
][
\c!state
=
\p_text
]
}}
\donothing
1120
\fi
1121
\edef
\p_footer
{
\headparameter
\c!footer
}
%
1122
\ifx
\p_footer
\empty
\else
1123
\doifelselayouttextline
\v!footer
{
\normalexpanded
{
\setuplayouttext
[
\v!footer
][
\c!state
=
\p_footer
]
}}
\donothing
1124
\fi
}
1125 1126
\newcount
\c_strc_sectioning_preceding_level
\c_strc_sectioning_preceding_level
\plusone
1127
\newconditional
\c_strc_sectioning_auto_break
\settrue
\c_strc_sectioning_auto_break
1128
\newconditional
\c_strc_sectioning_ignore_page
1129
\newsignal
\s_strc_sectioning_continuous_signal
1130 1131
\unexpanded
\def
\strc_sectioning_inject_continuous_signal
1132
{
\ifhmode
1133
\hskip
\s_strc_sectioning_continuous_signal
\relax
1134
\fi
}
1135 1136
% \let\dotagsectionlevel\relax
1137 1138
\def
\strc_sectioning_before_yes
1139
{
\strc_sectioning_check_before
\strc_sectioning_handle_page_yes
1140
\headparameter
\c!inbetween
1141
\dostarttaggedchained
\t!section
\currenthead
\??head
1142
% \dotagsectionlevel
1143
}
1144 1145
\def
\strc_sectioning_before_nop
1146
{
\strc_sectioning_check_before
\strc_sectioning_handle_page_nop
1147
\headparameter
\c!inbetween
1148
\dostarttagged
\currenthead
\empty
}
% this is a weird one .. needs checking
1149 1150
\def
\strc_sectioning_empty_correction
1151
{
\ifconditional
\c_strc_sectioning_empty
1152
% this needs checking
1153
\penalty
\plustenthousand
1154
\vskip
-
\lineheight
1155
\kern
\zeropoint
1156
\prevdepth
\strutdepth
1157
\fi
}
1158 1159
\def
\strc_sectioning_after_nop
1160
{}
1161 1162
\def
\strc_sectioning_check_before
#
1
%
1163
{
\ifhmode
1164
\scratchcounter
\lastpenalty
1165
\unpenalty
% no beauty in this
1166
\ifdim
\lastskip
=
\s_strc_sectioning_continuous_signal
1167
% no page break
1168
\ifconditional
\c_strc_sectioning_ignore_page
1169
\setfalse
\c_strc_sectioning_ignore_page
1170
\else
1171
\global
\c_strc_sectioning_preceding_level
\currentheadlevel
1172
\nobreak
1173
\fi
1174
% \global\settrue\c_strc_rendering_continuous
1175
\else
1176
\penalty
\scratchcounter
1177
% \global\setfalse\c_strc_rendering_continuous
1178
#
1
%
1179
\fi
1180
\else
1181
% \global\setfalse\c_strc_rendering_continuous
1182
#
1
%
1183
\fi
}
1184 1185
\def
\currentsectioncountervalue
{
\clf_depthnumber
\numexpr
\thenamedheadlevel
\currenthead
\relax
}
1186
\def
\previoussectioncountervalue
{
\clf_depthnumber
\numexpr
\thenamedheadlevel
\currenthead
+
\minusone
\relax
}
1187 1188
% \def\strc_sectioning_handle_page_nop
1189
% {\edef\p_continue{\headparameter\c!continue}%
1190
% \ifx\p_continue\v!yes
1191
% \ifnum\previoussectioncountervalue=\zerocount
1192
% \strc_sectioning_check_layout
1193
% \else\ifnum\currentsectioncountervalue>\zerocount
1194
% \strc_sectioning_check_layout
1195
% \fi\fi
1196
% \else
1197
% \strc_sectioning_check_layout
1198
% \fi}
1199 1200
\def
\currentsectioncountervalue
{
\clf_depthnumber
\numexpr
\thenamedheadlevel
\currenthead
\relax
}
1201
%def\previoussectioncountervalue{\clf_depthnumber\numexpr\thenamedheadlevel\currenthead+\minusone\relax}
1202
\def
\previoussectioncountervalue
{
\clf_depthnumber
\numexpr
\thenamedheadlevel
\previoushead
\relax
}
1203 1204
\let
\previoushead
\empty
1205 1206
\def
\strc_sectioning_handle_page_nop
1207
{
\edef
\p_continue
{
\headparameter
\c!continue
}
%
1208
\ifx
\p_continue
\v!yes
1209
\ifx
\currenthead
\previoushead
% not really needed
1210
\strc_sectioning_check_layout
1211
\else\ifnum
\previoussectioncountervalue
=
\zerocount
1212
\strc_sectioning_check_layout
1213
\else\ifnum
\currentsectioncountervalue
>
\zerocount
1214
\strc_sectioning_check_layout
1215
\fi\fi\fi
1216
\else
1217
\strc_sectioning_check_layout
1218
\fi
1219
\glet
\previoushead
\currenthead
}
1220 1221
% \def\strc_sectioning_handle_page_yes
1222
% {\ifconditional\c_strc_sectioning_ignore_page
1223
% \setfalse\c_strc_sectioning_ignore_page
1224
% \else
1225
% % beware, these numbers are not yet know here
1226
% \strc_sectioning_handle_page_nop
1227
% \edef\p_aligntitle{\headparameter\c!aligntitle}%
1228
% \ifx\p_aligntitle\v!float
1229
% \ifconditional\c_strc_sectioning_auto_break
1230
% \vspacing[\v!samepage-\currentheadlevel]%
1231
% \fi
1232
% \headparameter\c!before\relax
1233
% \indent
1234
% \else
1235
% \page_otr_command_flush_side_floats
1236
% \ifconditional\c_strc_sectioning_auto_break
1237
% \vspacing[\v!samepage-\currentheadlevel]%
1238
% \fi
1239
% \headparameter\c!before\relax
1240
% \fi
1241
% \global\c_strc_sectioning_preceding_level\currentheadlevel
1242
% \fi
1243
% \glet\previoushead\currenthead}
1244
%
1245
% \unexpanded\def\strc_sectioning_prevent_page_break% see strc-con
1246
% {\ifconditional\c_strc_sectioning_auto_break
1247
% \vspacing[\v!samepage-\the\numexpr\currentheadlevel+\plusone\relax]%
1248
% \fi}
1249
%
1250
% \def\strc_sectioning_after_yes
1251
% {\ifconditional\headisdisplay
1252
% \ifconditional\c_strc_sectioning_auto_break
1253
% % \vspacing[\v!samepage-\currentheadlevel]%
1254
% \vspacing[\v!samepage]%
1255
% \fi
1256
% \strc_sectioning_empty_correction
1257
% \headparameter\c!after
1258
% \fi}
1259 1260
% This works better in columns ... but also elsewhere?
1261 1262
\def
\strc_sectioning_handle_page_yes
1263
{
\ifconditional
\c_strc_sectioning_ignore_page
1264
\setfalse
\c_strc_sectioning_ignore_page
1265
\else
1266
% beware, these numbers are not yet know here
1267
\strc_sectioning_handle_page_nop
1268
\edef
\p_aligntitle
{
\headparameter
\c!aligntitle
}
%
1269
\ifx
\p_aligntitle
\v!float
1270
\ifconditional
\c_strc_sectioning_auto_break
1271
\spac_vspacing_same_page
\currentheadlevel
\zerocount
1272
\fi
1273
\headparameter
\c!before
\relax
1274
\indent
1275
\else
1276
\page_otr_command_flush_side_floats
1277
\ifconditional
\c_strc_sectioning_auto_break
1278
\spac_vspacing_same_page
\currentheadlevel
\zerocount
1279
\fi
1280
\headparameter
\c!before
\relax
1281
\fi
1282
\global
\c_strc_sectioning_preceding_level
\currentheadlevel
1283
\fi
1284
\glet
\previoushead
\currenthead
}
1285 1286
\def
\strc_sectioning_after_yes
1287
{
\ifconditional
\headisdisplay
1288
\ifconditional
\c_strc_sectioning_auto_break
1289
\spac_vspacing_same_page
\currentheadlevel
\plusone
1290
\fi
1291
\strc_sectioning_empty_correction
1292
\headparameter
\c!after
1293
\fi
}
1294 1295
\unexpanded
\def
\strc_sectioning_prevent_page_break
% see strc-con
1296
{
\ifconditional
\c_strc_sectioning_auto_break
1297
\spac_vspacing_same_page
\currentheadlevel
\plustwo
1298
\fi
}
1299 1300 1301
% We do support negative numbers but it can have side effects that we won't catch:
1302
%
1303
% \chapter{some} \setupheadnumber[chapter][3] \chapter{more}
1304
% \setupheadnumber[section][8] \section{b} \section{c} \setupheadnumber[section][-1] \section{d}
1305 1306
\def
\thenamedheadlevel
#
1
%
1307
{
\sectionlevel
{
\sectionheadsection
{
\sectionheadcoupling
{
#
1
}}}}
1308 1309
\unexpanded
\def
\setupheadnumber
1310
{
\dodoubleargument
\strc_sectioning_setup_number
}
1311 1312
\def
\strc_sectioning_setup_number
[#
1
][#
2
]
% todo: reset if at other level
1313
{
\setstructurenumber
{
\thenamedheadlevel
{
#
1
}}{
\number
#
2
}}
1314 1315
\def
\currentheadnumber
{
0
}
% ==> \currentheadnumber
1316 1317
\unexpanded
\def
\determineheadnumber
[#
1
]
%
1318
{
\xdef
\currentheadnumber
{
\getstructurenumber
{
\thenamedheadlevel
{
#
1
}}}}
1319 1320
% The previous macro is been replaced by the expandable:
1321 1322
\def
\namedheadnumber
#
1
{
\getstructurenumber
{
\thenamedheadlevel
{
#
1
}}}
1323
\def
\somenamedheadnumber
#
1
#
2
{
\getsomestructurenumber
{
\thenamedheadlevel
{
#
1
}}{
#
2
}}
1324 1325
\unexpanded
\def
\headnumber
1326
{
\dodoubleempty
\strc_sectioning_number
}
1327 1328
\def
\strc_sectioning_number
[#
1
][#
2
]
% simple case is just a number
1329
{
\getsomefullstructurenumber
{
\iffirstargument
\thenamedheadlevel
{
#
1
}
\fi
}{
#
2
}}
1330 1331
\unexpanded
\def
\someheadnumber
1332
{
\dodoubleempty
\strc_sectioning_number_some
}
1333 1334
\def
\strc_sectioning_number_some
[#
1
][#
2
]
%
1335
{
\dontleavehmode
1336
\begingroup
1337
\edef
\currenthead
{
#
1
}
%
1338
\getsomefullstructurenumber
{
\thenamedheadlevel
{
#
1
}}{
#
2
}
%
1339
\endgroup
}
1340 1341
\let
\sectioncountervalue
\structurevalue
1342 1343
\def
\currentheadtext
{
obsolete
,
\space
use
marks
}
1344 1345
% list references, will be redone in lua when we need it
1346 1347
\let
\startlistreferences
\relax
1348
\let
\stoplistreferences
\relax
1349 1350
% experimental
1351 1352
\newconditional
\c_strc_sectioning_auto_levels
1353 1354
\appendtoks
1355
\settrue
\c_strc_sectioning_auto_levels
1356
\to
\everyenableelements
1357 1358
\unexpanded
\def
\strc_sectioning_initialize_autolevel
1359
{
\ifconditional
\c_strc_sectioning_auto_levels
1360
\clf_autonextstructurelevel
\currentheadlevel
\relax
1361
\global
\setfalse
\c_strc_sectioning_auto_levels
1362
\fi
}
1363 1364
\unexpanded
\def
\triggerautostructurelevel
1365
{
\global
\settrue
\c_strc_sectioning_auto_levels
}
1366 1367
\unexpanded
\def
\finalizeautostructurelevels
1368
{
\clf_autofinishstructurelevels
}
1369 1370
\unexpanded
\def
\finalizeautostructurelevel
1371
{
\dostoptagged
1372
\dostoptagged
}
1373 1374
\appendtoks
1375
\finalizeautostructurelevels
1376
\to
\everystoptext
1377 1378
\stopcontextdefinitioncode
1379 1380
\protect
\endinput
1381