1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17\writestatus{loading}{ConTeXt Structure Macros Sectioning}
18
19\unprotect
20
21\startcontextdefinitioncode
22
23\installcorenamespace{structure}
24
25\installdirectcommandhandler \??structure {structure}
26
27\setupstructure
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
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
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
64 \else\ifx\currentstructurereferenceprefix\m_strc_references_prefix_yes
65 \global\advance\prefixcounter \plusone
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
75
76\setupstructure
77 [\c!label={\headparameter{\currentsectionblock\c!label}},
78 \c!incrementnumber=\ifconditional\c_strc_sectioning_increment\v!yes\else\v!no\fi,
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,
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
98
99\def\namedstructureheadlocation#1
100 {\csname\??savedinternalreference\ifcsname\??savedinternalreference#1\endcsname#1\else\s!default\fi\endcsname}
101
102
103
104
105
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
117 \the\everypreroll
118 \nodestostring\tempstring{#1}
119 \glet\currentstructurebookmark\tempstring
120 \endgroup}
121
122
123
124
125
126
127
128
129
130
131\unexpanded\def\strc_sectioning_register#1#2#3
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}
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 \xdef\currentstructureplaceholder {\structureparameter\c!placeholder}
149 \ifx\currentstructureexpansion\s!xml
150 \xmlstartraw
151 \xdef\currentstructuretitle {\structureparameter\c!title}
152 \xdef\currentstructurebookmark{\structureparameter\c!bookmark}
153 \xdef\currentstructuremarking {\structureparameter\c!marking}
154 \xdef\currentstructurelist {\structureparameter\c!list}
155 \xmlstopraw
156 \iflocation \ifx\currentstructurebookmark\empty \ifconditional\c_strc_bookmarks_preroll
157 \strc_sectioning_autobookmark\currentstructuretitle
158 \fi \fi \fi
159 \ifx\currentstructurelist\empty
160 \glet\currentstructurelist\currentstructuretitle
161 \fi
162 \glet\currentstructurecoding\s!xml
163 \else
164 \ifx\currentstructureexpansion\v!yes
165 \xdef\currentstructuretitle {\structureparameter\c!title}
166 \xdef\currentstructurebookmark{\structureparameter\c!bookmark}
167 \xdef\currentstructuremarking {\structureparameter\c!marking}
168 \xdef\currentstructurelist {\structureparameter\c!list}
169 \iflocation \ifx\currentstructurebookmark\empty \ifconditional\c_strc_bookmarks_preroll
170 \strc_sectioning_autobookmark\currentstructuretitle
171 \fi \fi \fi
172 \else
173 \xdef\currentstructuretitle {\detokenizedstructureparameter\c!title}
174 \xdef\currentstructurebookmark{\detokenizedstructureparameter\c!bookmark}
175 \xdef\currentstructuremarking {\detokenizedstructureparameter\c!marking}
176 \xdef\currentstructurelist {\detokenizedstructureparameter\c!list}
177 \iflocation \ifx\currentstructurebookmark\empty
178 \ifconditional\c_strc_bookmarks_preroll
179 \strc_sectioning_autobookmark{\structureparameter\c!title}
180 \else
181 \begingroup
182 \simplifycommands
183 \xdef\currentstructurebookmark{\detokenize\expandafter{\normalexpanded{\structureparameter\c!title}}}
184 \endgroup
185 \fi
186 \fi \fi
187 \fi
188 \ifx\currentstructurelist\empty
189 \glet\currentstructurelist\currentstructuretitle
190 \fi
191 \glet\currentstructurecoding\s!tex
192 \fi
193 \setnextinternalreference
194 \storeinternalreference\currentstructurename{\the\locationcount}
195 \strc_sectioning_set_reference_prefix
196 \clf_setsectionentry
197 references {
198 internal \locationcount
199
200 prefix {\currentstructurereferenceprefix}
201 reference {\currentstructurereference}
202 backreference {\currentstructurebackreference}
203 }
204 directives {
205 resetset {\structureparameter\c!sectionresetset}
206 }
207 metadata {
208 kind {section}
209 name {\currentstructurename}
210 catcodes \ifx\currentstructurecatcodes\empty\catcodetable\else\csname\currentstructurecatcodes\endcsname\fi\space
211 coding {\currentstructurecoding}
212 \ifx\currentstructurecoding\s!xml
213 xmlroot {\xmldocument}
214 \fi
215 \ifx\currentstructurexmlsetup\empty \else
216 xmlsetup {\currentstructurexmlsetup}
217 \fi
218 \ifx\currentstructuresaveinlist\v!no
219 nolist \space true\space
220 \fi
221 \ifx\currentstructureincrementnumber\v!yes
222 increment {\currentstructureincrementnumber}
223 \fi
224 }
225 titledata {
226 label {\detokenize\expandafter{\currentstructurelabel}}
227 title {\detokenize\expandafter{\currentstructuretitle}}
228 \ifx\currentstructurebookmark\currentstructuretitle \else
229 bookmark {\detokenize\expandafter{\currentstructurebookmark}}
230 \fi
231 \ifx\currentstructuremarking\currentstructuretitle \else
232 marking {\detokenize\expandafter{\currentstructuremarking}}
233 \fi
234 \ifx\currentstructuresaveinlist\v!no \else
235 \ifx\currentstructurelist\currentstructuretitle \else
236 list {\detokenize\expandafter{\currentstructurelist}}
237 \fi
238 \fi
239 }
240 numberdata {
241
242 \ifx\currentstructureshownumber\v!no
243 hidenumber \space true\space
244 \fi
245 separatorset {\structureparameter\c!sectionseparatorset}
246 conversionset {\structureparameter\c!sectionconversionset}
247 conversion {\structureparameter\c!sectionconversion}
248 starter {\structureparameter\c!sectionstarter}
249 stopper {\structureparameter\c!sectionstopper}
250 set {\structureparameter\c!sectionset}
251 segments {\structureparameter\c!sectionsegments}
252 ownnumber {\currentstructureownnumber}
253 language {\currentlanguage}
254 criterium {\structureparameter\c!criterium}
255 }
256 userdata {\detokenize{#3}}
257 \relax
258 \xdef\currentstructurelistnumber{\clf_currentsectiontolist}
259
260 \setstructuresynchronization\currentstructurelistnumber
261 \endgroup}
262
263\let\currentsectioncountervalue \!!zerocount
264\let\previoussectioncountervalue\!!zerocount
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285\def\structurenumber {\clf_structurenumber}
286\def\structuretitle {\clf_structuretitle}
287\def\structurevariable #1{\clf_structurevariable {#1}}
288\def\structureuservariable #1{\clf_structureuservariable {#1}}
289\def\structurecatcodedget #1{\clf_structurecatcodedget {#1}}
290\def\structuregivencatcodedget #1#2{\clf_structuregivencatcodedget {#1}#2 }
291\def\structureautocatcodedget #1#2{\clf_structureautocatcodedget {#1}{#2}}
292\def\namedstructurevariable #1#2{\clf_namedstructurevariable {#1}{#2}}
293\def\namedstructureuservariable#1#2{\clf_namedstructureuservariable{#1}{#2}}
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323\def\setstructurelevel #1#2{\clf_setstructurelevel {#1}{#2}}
324\def\getstructurelevel #1{\clf_getstructurelevel {#1}}
325\def\setstructurenumber #1#2{\clf_setstructurenumber #1{#2}}
326\def\getstructurenumber #1{\clf_getstructurenumber \numexpr#1\relax}
327\def\getsomestructurenumber #1#2{\clf_getsomestructurenumber #1{#2}}
328\def\getfullstructurenumber #1{\clf_getfullstructurenumber \numexpr#1\relax}
329\def\getsomefullstructurenumber#1#2{\clf_getsomefullstructurenumber #1{#2}}
330\def\getspecificstructuretitle #1{\clf_getspecificstructuretitle {#1}{\headparameter\s!catcodes}}
331
332
333
334
335
336
337
338
339
340
341\installcorenamespace{head}
342\installcorenamespace{headlevel}
343\installcorenamespace{headincrement}
344\installcorenamespace{headplace}
345\installcorenamespace{headmarkyes}
346\installcorenamespace{headmarknop}
347
348\installcommandhandler \??head {head} \??head
349
350\installmacrostack\currenthead
351\installmacrostack\currentheadparent
352
353\setuphead [
354
355
356
357 \c!alternative=\v!normal,
358
359
360
361 \c!continue=\v!yes,
362
363
364
365
366 \c!distance=\zeropoint,
367 \c!textdistance=\zeropoint,
368 \c!textwidth=\zeropoint,
369 \c!numberwidth=\zeropoint,
370 \c!width=\zeropoint,
371 \c!expansion=\v!no,
372
373
374
375 \c!hang=\v!none,
376
377 \c!incrementnumber=\v!yes,
378 \c!indentnext=\v!no,
379
380
381 \c!margin=\zeropoint,
382
383 \c!number=\v!yes,
384 \c!numbercolor=\headparameter\c!color,
385 \c!textcolor=\headparameter\c!color,
386 \c!numberstyle=\headparameter\c!style,
387 \c!textstyle=\headparameter\c!style,
388
389
390 \c!ownnumber=\v!no,
391
392 \c!placehead=\v!yes,
393 \c!sectionconversionset=\s!default,
394 \c!sectionnumber=\v!yes,
395
396 \c!sectionseparatorset=\s!default,
397 \c!sectionset=\v!all,
398 \c!interlinespace=,
399
400
401
402
403
404
405
406
407
408 ]
409
410\let\setupheads\setuphead
411
412\appendtoks
413 \ifx\currentheadparent\empty
414 \edef\currentheaddefault{\headparameter\c!default}
415 \edef\currentheadsection{\headparameter\c!section}
416 \ifx\currenthead\currentheaddefault
417 \let\currentheadparent\currentheadsection
418 \else\ifx\currentheaddefault\empty
419 \let\currentheadparent\currentheadsection
420 \else
421 \let\currentheadparent\currentheaddefault
422 \fi\fi
423 \normalexpanded {
424 \setheadparameter{\c!label}{\currenthead}
425 \setheadparameter{\c!coupling}{\currenthead}
426 \setheadparameter{\s!parent}{\??head\currentheadparent}
427 \definemarking[\currenthead] [\currentheadsection]
428 \definemarking[\currenthead\v!number][\currentheadsection]
429 \setupmarking [\currenthead] [\c!filtercommand=\noexpand\sectionheadmarkingtitle {\currenthead}]
430 \setupmarking [\currenthead\v!number][\c!filtercommand=\noexpand\sectionheadmarkingnumber{\currenthead}]
431 }
432 \doifelselist\currenthead\donothing
433 {\definelist[\currenthead][\c!prefix=\v!no]}
434
435
436
437 \else
438 \normalexpanded {
439 \setheadparameter{\c!label}{\currenthead}
440 \setheadparameter{\c!coupling}{\currentheadparent}
441 \definemarking[\currenthead] [\currentheadparent]
442 \definemarking[\currenthead\v!number][\currentheadparent\c!number]
443 }
444 \doifelselist\currenthead\donothing
445 {\normalexpanded{\definelist[\currenthead][\currentheadparent][\c!prefix=\v!no]}}
446 \fi
447 \presetlabeltext[\currenthead=]
448 \the\everysetuphead
449\to \everydefinehead
450
451\newtoks\everyredefinehead
452
453\appendtoks
454 \the\everyredefinehead
455\to \everydefinehead
456
457\appendtoks
458 \setstructurelevel\currenthead{\thenamedheadlevel\currenthead}
459\to \everyredefinehead
460
461\appendtoks
462
463 \begingroup
464 \edef\currentsectionheadcoupling{\sectionheadcoupling\currenthead}
465 \edef\currentsectionheadsection {\sectionheadsection \currentsectionheadcoupling}
466 \edef\currentsectionlevel {\sectionlevel \currentsectionheadsection}
467 \clf_registersection {\currenthead} {
468 coupling {\currentsectionheadcoupling}
469 section {\currentsectionheadsection}
470 level \space \currentsectionlevel \space
471 parent {\currentheadparent}
472 }
473 \endgroup
474\to \everyredefinehead
475
476\appendtoks
477
478 \setuevalue{\e!start\currenthead}{\strc_sectioning_start[\currenthead]}
479 \setuevalue{\e!stop \currenthead}{\strc_sectioning_stop [\currenthead]}
480\to \everydefinehead
481
482
483
484
485
486\appendtoks
487 \ifx\currenthead\empty \else
488 \doifelse{\headparameter\c!ownnumber}\v!yes
489 {\setuevalue\currenthead{\strc_sectioning_handle_own[\currenthead]}}
490 {\setuevalue\currenthead{\strc_sectioning_handle_nop[\currenthead]}}
491 \fi
492\to \everysetuphead
493
494\unexpanded\def\doredefinehead#1#2
495 {\push_macro_currenthead
496 \push_macro_currentheadparent
497 \edef\currenthead{#1}
498 \edef\currentheadparent{#2}
499 \the\everyredefinehead\relax
500 \pop_macro_currentheadparent
501 \pop_macro_currenthead}
502
503\let\currentnamedsection\empty
504
505\installmacrostack\currentnamedsection
506
507\unexpanded\def\startnamedsection
508 {\dotripleempty\strc_sectioning_start_named_section}
509
510
511
512
513\unexpanded\def\stopnamedsection
514 {\normalexpanded{\strc_sectioning_stop[\currentnamedsection]}}
515
516
517
518\let\firstsectionname\empty
519\let\lastsectionname \empty
520
521\let\resetallstructuremarks \relax
522\let\resetcurrentstructuremarks \relax
523\let\resetcurrentstructuremarkswithpage\relax
524
525\def\resetallstructuremarks {\resetmarking[\firstsectionname]}
526\def\resetcurrentstructuremarks {\resetmarking[\lastsectionname]}
527
528
529
530
531
532
533
534
535
536
537
538\newcount\maxstructuredepth
539
540\def\sectionlevel#1
541 {\csname\??headlevel\ifcsname\??headlevel#1\endcsname#1\else\v!none\fi\endcsname}
542
543\def\namedsectionlevel#1#2
544 {\csname\??headlevel
545 \ifcsname\??headlevel#1\endcsname
546 #1
547 \else\ifcsname\??headlevel#2\endcsname
548 #2
549 \else
550 \v!none
551 \fi\fi
552 \endcsname}
553
554\def\xthenamedheadlevel#1
555 {\namedsectionlevel{#1}{\sectionheadsection{\sectionheadcoupling{#1}}}}
556
557\setvalue{\??headlevel\v!block}{0}
558\setvalue{\??headlevel\v!none }{1}
559\setvalue{\??headlevel\v!text }{2}
560\setvalue{\??headlevel\v!head }{3}
561
562\newtoks\everydefinesection
563
564\unexpanded\def\definesection[#1]
565 {\ifcsname\??headlevel#1\endcsname \else
566 \edef\currentsection{#1}
567 \edef\currenthead{#1}
568 \global\advance\maxstructuredepth\plusone
569 \setevalue{\??headlevel#1}{\the\maxstructuredepth}
570 \setstructurelevel{#1}{\sectionlevel{#1}}
571 \normalexpanded{\setheadparameter{\s!parent}{\??head\lastsectionname}}
572 \the\everydefinesection
573
574 \definemarking[#1]
575 \ifnum\maxstructuredepth>\plusone
576 \normalexpanded{\relatemarking[#1][\lastsectionname]}
577 \fi
578 \xdef\lastsectionname{#1}
579 \ifx\firstsectionname\empty
580 \glet\firstsectionname\lastsectionname
581 \fi
582 \fi}
583
584\unexpanded\def\setupsection
585 {\dotripleempty\strc_sectioning_setup}
586
587\def\strc_sectioning_setup[#1][#2][#3]
588 {\ifcsname\??headlevel#1\endcsname
589 \strc_sectioning_setup_indeed[#1][#2][#3]
590 \else
591 \strc_sectioning_setup_indeed[\sectionheadsection{#1}][#2][#3]
592 \fi}
593
594\def\strc_sectioning_setup_indeed[#1][#2][#3]
595 {\push_macro_currenthead
596 \ifthirdargument
597 \edef\currenthead{#1#2}
598 \setupcurrenthead[#3]
599 \else
600 \edef\currenthead{#1}
601 \setupcurrenthead[#2]
602 \fi
603 \pop_macro_currenthead}
604
605
606
607
608\appendtoks
609
610
611
612
613 \let\currenthead\currentsection
614 \setheadparameter\c!textstyle {\directheadparameter\c!style}
615 \setheadparameter\c!textcolor {\directheadparameter\c!color}
616 \setheadparameter\c!numberstyle{\directheadparameter\c!style}
617 \setheadparameter\c!numbercolor{\directheadparameter\c!color}
618\to \everydefinesection
619
620
621
622\def\sectionheadmarkingtitle #1#2{\clf_markingtitle {#1}{#2}}
623\def\sectionheadmarkingnumber#1#2{\clf_markingnumber{#1}{#2}}
624
625\def\sectionheadcoupling#1{\namedheadparameter{#1}\c!coupling}
626\def\sectionheadsection #1{\namedheadparameter{#1}\c!section}
627
628
629
630\unexpanded\def\strc_sectioning_handle_own{\dodoubleempty\strc_sectioning_handle_own_indeed}
631\unexpanded\def\strc_sectioning_handle_nop{\dodoubleempty\strc_sectioning_handle_nop_indeed}
632\unexpanded\def\strc_sectioning_start {\dotripleempty\strc_sectioning_start_named_section}
633
634\newconditional\currentstructureown
635
636\newtoks\everybeforehead
637\newtoks\everyafterhead
638
639\unexpanded\def\strc_sectioning_handle_own_indeed[#1][#2]#3#4
640 {\settrue\currentstructureown
641 \triggerautostructurelevel
642 \strc_sectioning_handle{#1}{\c!reference={#2},\c!ownnumber={#3},\c!title={#4}}{}}
643
644
645
646
647
648
649\unexpanded\def\strc_sectioning_handle_nop_indeed[#1][#2]
650 {\setfalse\currentstructureown
651 \triggerautostructurelevel
652 \ifcondition\validassignment{#2}
653 \expandafter\strc_sectioning_handle_nop_indeed_yes
654 \else
655 \expandafter\strc_sectioning_handle_nop_indeed_nop
656 \fi
657 {#1}{#2}}
658
659\unexpanded\def\strc_sectioning_handle_nop_indeed_yes#1#2
660 {\strc_sectioning_handle{#1}{#2}{}}
661
662\unexpanded\def\strc_sectioning_handle_nop_indeed_nop#1#2#3
663 {\strc_sectioning_handle{#1}{\c!reference={#2},\c!title={#3}}{}}
664
665\unexpanded\def\strc_sectioning_start_named_section[#1][#2][#3]
666 {\push_macro_currentnamedsection
667 \push_macro_currentstructurereferenceprefix
668 \edef\currentnamedsection{#1}
669 \setfalse\currentstructureown
670
671 \xdef\currenthead{#1}
672 \setsystemmode\currenthead
673 \headparameter\c!beforesection
674 \the\everybeforehead
675 \strc_sectioning_handle{#1}{#2}{#3}
676
677 \headparameter\c!insidesection}
678
679\unexpanded\def\strc_sectioning_stop[#1]
680 {\dostoptagged
681 \dostoptagged
682
683
684 \xdef\currenthead{#1}
685 \headparameter\c!aftersection
686 \the\everyafterhead
687 \resetsystemmode\currenthead
688 \pop_macro_currentstructurereferenceprefix
689 \pop_macro_currentnamedsection}
690
691\let\dostarthead\strc_sectioning_start
692\let\dostophead \strc_sectioning_stop
693
694
695
696\newconditional\c_strc_sectioning_to_list
697\newconditional\c_strc_sectioning_increment
698\newconditional\c_strc_sectioning_place
699\newconditional\c_strc_sectioning_empty
700\newconditional\c_strc_sectioning_hidden
701\newconditional\c_strc_sectioning_section
702
703\newconditional\headshownumber
704\newconditional\headisdisplay
705\newconditional\headissomewhere
706
707\setvalue{\??headincrement\v!yes }{\settrue \c_strc_sectioning_increment\settrue \c_strc_sectioning_to_list}
708\setvalue{\??headincrement\v!no }{\setfalse\c_strc_sectioning_increment\setfalse\c_strc_sectioning_to_list}
709\setvalue{\??headincrement\v!list }{\setfalse\c_strc_sectioning_increment\settrue \c_strc_sectioning_to_list}
710\setvalue{\??headincrement\s!empty}{\settrue \c_strc_sectioning_increment\settrue \c_strc_sectioning_to_list}
711
712\unexpanded\def\strc_sectioning_initialize_increment
713 {\edef\currentheadincrement{\headparameter\c!incrementnumber}
714 \ifcsname\??headincrement\currentheadincrement\endcsname
715 \lastnamedcs
716 \else
717 \settrue \c_strc_sectioning_increment\settrue \c_strc_sectioning_to_list
718
719 \fi}
720
721\def\filterheadnumber
722 {\settrue\c_strc_sectioning_increment
723 \settrue\c_strc_sectioning_to_list
724 \ifx\currentproduct\empty
725
726
727 \fi}
728
729\setvalue{\??headplace\v!yes}
730 {\setfalse\c_strc_sectioning_empty
731 \settrue \c_strc_sectioning_place
732 \setfalse\c_strc_sectioning_hidden
733 \setfalse\c_strc_sectioning_section}
734
735\setvalue{\??headplace\v!empty}
736 {\settrue \c_strc_sectioning_empty
737 \settrue \c_strc_sectioning_place
738 \setfalse\c_strc_sectioning_hidden
739 \setfalse\c_strc_sectioning_section}
740
741\setvalue{\??headplace\v!no}
742 {\settrue \c_strc_sectioning_empty
743 \setfalse\c_strc_sectioning_place
744 \setfalse\c_strc_sectioning_hidden
745 \setfalse\c_strc_sectioning_section}
746
747\setvalue{\??headplace\v!hidden}
748 {\settrue \c_strc_sectioning_empty
749 \setfalse\c_strc_sectioning_place
750 \settrue \c_strc_sectioning_hidden
751 \setfalse\c_strc_sectioning_section}
752
753\setvalue{\??headplace\v!section}
754 {\settrue \c_strc_sectioning_empty
755 \setfalse\c_strc_sectioning_place
756 \settrue \c_strc_sectioning_hidden
757 \settrue \c_strc_sectioning_section}
758
759\unexpanded\def\strc_sectioning_initialize_placement
760 {\expandnamespaceparameter\??headplace\headparameter\c!placehead\v!yes}
761
762\newmode\v!sectionnumber
763
764\def\dosetstructureheadnumbercontent
765 {\setsystemmode\v!sectionnumber
766 \settrue\headshownumber}
767
768\def\doresetstructureheadnumbercontent
769 {\resetsystemmode\v!sectionnumber
770 \setfalse\headshownumber}
771
772\unexpanded\def\strc_sectioning_initialize_number
773 {\edef\p_number{\sectionblockparameter\c!number}
774 \ifx\p_number\v!yes
775 \edef\p_number{\headparameter\c!number}
776 \ifx\p_number\v!yes
777 \settrue\headshownumber
778 \else
779 \setfalse\headshownumber
780 \fi
781 \else
782 \setfalse\headshownumber
783 \fi}
784
785
786
787
788\newtoks\everyheadsynchronization
789
790
791
792
793
794\let\currentstructuresynchronize\donothing
795
796\appendtoks
797 \currentstructuresynchronize
798 \glet\currentstructuresynchronize\donothing
799\to \everyheadsynchronization
800
801\unexpanded\def\theheadsynchronization
802 {
803 \the\everyheadsynchronization}
804
805
806
807
808\unexpanded\def\setheadmarking
809 {\strc_sectioning_delayed_flush
810 \normalexpanded{\setmarking[\currenthead]{li::\currentstructurelistnumber}}}
811
812\let\deepstructurenumbercommand\relax
813\let\deepstructuretitlecommand \relax
814
815\unexpanded\def\fullheadnumber
816 {\edef\currentheadlabeltag{\currentsectionblock\c!label}
817 \dostarttagged\t!sectionnumber\empty
818 \labeltexts
819 {\headparameter\currentheadlabeltag}
820 {\ifx\deepstructurenumbercommand\relax
821 \structurenumber
822 \else
823 \normalexpanded{\noexpand\deepstructurenumbercommand{\structurenumber}}
824 \fi}
825 \dostoptagged}
826
827\unexpanded\def\fullheadtitle
828 {\dostarttagged\t!sectiontitle\empty
829 \ifx\deepstructuretitlecommand\relax
830 \structuretitle
831 \else
832 \normalexpanded{\noexpand\deepstructuretitlecommand{\structuretitle}}
833 \fi
834 \dostoptagged}
835
836\let\currenthead \empty
837\let\currentheadcoupling\empty
838\let\currentheadsection \empty
839\let\currentheadlevel \!!zerocount
840\let\currentheadcounter \!!zerocount
841
842\let\strc_show_used\relax
843
844\installtextracker
845 {structures.showused}
846 {\let\strc_show_used\clf_showstructure}
847 {\let\strc_show_used\relax}
848
849\appendtoks
850 \strc_show_used
851\to \everystoptext
852
853\unexpanded\def\placeheadtext {\dosingleempty\strc_sectioning_place_head_text }
854\unexpanded\def\placeheadnumber{\dosingleempty\strc_sectioning_place_head_number}
855
856\unexpanded\def\strc_sectioning_report{\clf_reportstructure}
857
858\ifdefined\strc_rendering_initialize_style_and_color \else
859
860 \unexpanded\def\strc_rendering_initialize_style_and_color#1#2
861 {\dontconvertfont
862 \useheadstyleandcolor\c!style\c!color
863 \useheadstyleandcolor#1#2
864 \setupinterlinespace}
865
866\fi
867
868\def\strc_sectioning_place_head_text[#1]
869 {\dontleavehmode
870 \begingroup
871 \unexpanded\def\\{\space}
872 \global\settrue\headisdisplay
873 \edef\currenthead{#1}
874 \strc_rendering_initialize_style_and_color\c!textstyle\c!textcolor
875 \relax
876 \getspecificstructuretitle{\thenamedheadlevel{#1}}
877 \endgraf
878 \endgroup}
879
880\def\strc_sectioning_place_head_number[#1]
881 {\dontleavehmode
882 \begingroup
883 \global\settrue\headisdisplay
884 \edef\currenthead{#1}
885 \strc_rendering_initialize_style_and_color\c!numberstyle\c!numbercolor
886 \relax
887 \getfullstructurenumber{\thenamedheadlevel{#1}}
888 \endgraf
889 \endgroup}
890
891\ifdefined\triggerautostructurelevel \else \let\triggerautostructurelevel\relax \fi
892
893\newtoks\everybeforesectionheadhandle
894\newtoks\everyaftersectionheadhandle
895
896\def\strc_sectioning_handle#1#2#3
897 {\xdef\currenthead {#1}
898 \xdef\currentheadcoupling{\sectionheadcoupling\currenthead}
899 \xdef\currentheadsection {\sectionheadsection \currentheadcoupling}
900 \xdef\currentheadlevel {\sectionlevel \currentheadsection}
901
902
903
904 \strc_sectioning_initialize_autolevel
905 \strc_sectioning_initialize_increment
906 \strc_sectioning_initialize_placement
907 \strc_sectioning_initialize_number
908
909 \the\everybeforesectionheadhandle
910
911
912
913
914
915
916
917
918
919
920
921 \let\getheadnumber\empty
922 \let\getheadtitle \empty
923 \let\getheadsyncs \empty
924 \ifconditional\c_strc_sectioning_increment
925 \ifconditional\c_strc_sectioning_place
926 \strc_sectioning_before_yes
927 \strc_sectioning_register{#1}{#2}{#3}
928 \strc_sectioning_report
929 \dostarttagged\t!sectioncaption\empty
930 \let\getheadsyncs\theheadsynchronization
931 \let\getheadtitle\fullheadtitle
932 \ifconditional\headshownumber
933 \let\getheadnumber\fullheadnumber
934 \strc_rendering_place_head_number_and_text
935 \else
936 \strc_rendering_place_head_text
937 \fi
938 \dostoptagged
939 \strc_sectioning_after_yes
940 \else\ifconditional\c_strc_sectioning_hidden
941 \strc_sectioning_register{#1}{#2}{#3}
942 \strc_sectioning_report
943 \dostarttagged\t!sectioncaption\empty
944 \let\getheadsyncs\theheadsynchronization
945 \ifconditional\c_strc_sectioning_section
946 \strc_rendering_place_head_section
947 \else
948 \strc_rendering_place_head_hidden
949 \fi
950 \dostoptagged
951 \else
952 \strc_sectioning_before_nop
953 \strc_sectioning_register{#1}{#2}{#3}
954 \strc_sectioning_report
955 \dostarttagged\t!sectioncaption\empty
956 \let\getheadsyncs\theheadsynchronization
957 \strc_rendering_place_head_empty
958 \dostoptagged
959 \strc_sectioning_after_nop
960 \fi\fi
961 \else
962 \ifconditional\c_strc_sectioning_place
963 \strc_sectioning_before_yes
964 \strc_sectioning_register{#1}{#2}{#3}
965 \strc_sectioning_report
966 \dostarttagged\t!sectioncaption\empty
967 \let\getheadsyncs\theheadsynchronization
968 \let\getheadtitle\fullheadtitle
969 \strc_rendering_place_head_text
970 \dostoptagged
971 \strc_sectioning_after_yes
972 \else\ifconditional\c_strc_sectioning_hidden
973 \strc_sectioning_register{#1}{#2}{#3}
974 \strc_sectioning_report
975 \let\getheadsyncs\theheadsynchronization
976 \dostarttagged\t!sectioncaption\empty
977 \ifconditional\c_strc_sectioning_section
978 \strc_rendering_place_head_section
979 \else
980 \strc_rendering_place_head_hidden
981 \fi
982 \dostoptagged
983 \else
984
985 \strc_sectioning_before_nop
986 \strc_sectioning_register{#1}{#2}{#3}
987 \strc_sectioning_report
988 \dostarttagged\t!sectioncaption\empty
989 \let\getheadsyncs\theheadsynchronization
990 \strc_rendering_place_head_empty
991 \dostoptagged
992 \strc_sectioning_after_nop
993 \fi\fi
994 \fi
995
996 \the\everyaftersectionheadhandle
997
998 \setfalse\c_strc_sectioning_ignore_page
999
1000 \dostarttagged\t!sectioncontent\empty
1001 \ifx\currentstructureplaceholder\empty
1002 \ifconditional\headisdisplay
1003 \doubleexpandafter\ignorespaces
1004 \else
1005 \doubleexpandafter\ignorepars
1006 \fi
1007 \else
1008 \expandafter\strc_sectioning_placeholder
1009 \fi}
1010
1011
1012
1013
1014
1015
1016
1017\def\strc_sectioning_placeholder
1018 {\placeholder[\currentstructureplaceholder]
1019 \gobblenested{\e!start\currenthead}{\e!stop\currenthead}{\e!stop\currenthead}}
1020
1021
1022
1023\unexpanded\def\strc_rendering_place_head_number_and_text
1024 {\setheadmarking
1025 \getheadnumber\getheadtitle
1026 \getheadsyncs}
1027
1028\unexpanded\def\strc_rendering_place_head_text
1029 {\setheadmarking
1030 \getheadtitle
1031 \getheadsyncs}
1032
1033\unexpanded\def\strc_rendering_place_head_empty
1034 {\setheadmarking
1035 \getheadsyncs}
1036
1037\installcorenamespace{hiddenheadattr}
1038\installcorenamespace{hiddenheadsync}
1039
1040
1041
1042
1043\newbox\b_sectioning_delayed
1044
1045\def\strc_sectioning_delayed_flush
1046 {\ifvoid\b_sectioning_delayed\else
1047 \smashedbox\b_sectioning_delayed
1048 \fi}
1049
1050\unexpanded\def\strc_rendering_place_head_section
1051 {\global\setbox\b_sectioning_delayed\hpack\bgroup
1052 \setmarking[\currentheadcoupling]{li::\currentstructurelistnumber}
1053 \hpack\headreferenceattributes{}
1054 \theheadsynchronization
1055 \egroup}
1056
1057\unexpanded\def\strc_rendering_place_head_hidden
1058 {\setxvalue{\??hiddenheadattr\currenthead}
1059 {\headreferenceattributes}
1060 \setxvalue{\??hiddenheadsync\currenthead}
1061 {\noexpand\letgvalue{\??hiddenheadsync\currenthead}\relax
1062 \noexpand\setmarking[\currentheadcoupling]{li::\currentstructurelistnumber}
1063 \hpack\headreferenceattributes{}
1064 \theheadsynchronization}}
1065
1066\def\synchronizehead #1{\csname\??hiddenheadsync#1\endcsname}
1067\def\theheadreferenceattributes#1{\csname\??hiddenheadattr#1\endcsname}
1068
1069\unexpanded\def\placerawheaddata [#1]{\synchronizehead{#1}}
1070\unexpanded\def\placerawheadtext [#1]{\getspecificstructuretitle{\thenamedheadlevel{#1}}}
1071\unexpanded\def\placerawheadnumber[#1]{\getfullstructurenumber{\thenamedheadlevel{#1}}}
1072
1073\unexpanded\def\repeathead[#1]
1074 {\begingroup
1075 \setupinteraction[\c!state=\v!stop]
1076 \def\currenthead{#1}
1077 \strc_sectioning_initialize_placement
1078 \strc_sectioning_initialize_number
1079 \dostarttagged\t!sectioncaption\empty
1080 \let\getheadsyncs \relax
1081 \def\getheadtitle {\getmarking[#1]}
1082 \def\getheadnumber{\getmarking[#1\v!number]}
1083 \strc_sectioning_before_yes
1084 \ifconditional\headshownumber
1085 \strc_rendering_place_head_number_and_text
1086 \else
1087 \strc_rendering_place_head_text
1088 \fi
1089 \dostoptagged
1090 \strc_sectioning_after_yes
1091 \endgroup}
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106\letvalue{\??headmarknop\v!page }\donothing
1107\setvalue{\??headmarknop\v!reset }{\resetcurrentstructuremarks}
1108\letvalue{\??headmarknop\s!unknown}\donothing
1109
1110\letvalue{\??headmarkyes\v!page }\donothing
1111\setvalue{\??headmarkyes\v!reset }{\resetcurrentstructuremarks}
1112\letvalue{\??headmarkyes\s!unknown}\donothing
1113
1114\def\strc_sectioning_check_layout
1115 {\edef\p_page{\headparameter\c!page}
1116 \ifx\p_page\empty
1117 \strc_sectioning_check_layout_nop
1118 \else
1119 \strc_sectioning_check_layout_yes
1120 \fi}
1121
1122\def\strc_sectioning_check_layout_nop
1123 {\expandnamespaceparameter\??headmarknop\headparameter\c!marking\s!unknown}
1124
1125\def\strc_sectioning_check_layout_yes
1126 {\page[\p_page]
1127 \expandnamespaceparameter\??headmarkyes\headparameter\c!marking\s!unknown
1128 \edef\p_header{\headparameter\c!header}
1129 \ifx\p_header\empty \else
1130 \doifelselayouttextline\v!header{\normalexpanded{\setuplayouttext[\v!header][\c!state=\p_header]}}\donothing
1131 \fi
1132 \edef\p_text{\headparameter\c!text}
1133 \ifx\p_text\empty \else
1134 \doifelselayouttextline\v!text {\normalexpanded{\setuplayouttext[\v!text ][\c!state=\p_text ]}}\donothing
1135 \fi
1136 \edef\p_footer{\headparameter\c!footer}
1137 \ifx\p_footer\empty \else
1138 \doifelselayouttextline\v!footer{\normalexpanded{\setuplayouttext[\v!footer][\c!state=\p_footer]}}\donothing
1139 \fi}
1140
1141\newcount \c_strc_sectioning_preceding_level \c_strc_sectioning_preceding_level\plusone
1142\newconditional\c_strc_sectioning_auto_break \settrue\c_strc_sectioning_auto_break
1143\newconditional\c_strc_sectioning_ignore_page
1144\newsignal \s_strc_sectioning_continuous_signal
1145
1146\unexpanded\def\strc_sectioning_inject_continuous_signal
1147 {\ifhmode
1148 \hskip\s_strc_sectioning_continuous_signal\relax
1149 \fi}
1150
1151
1152
1153\def\strc_sectioning_before_yes
1154 {\strc_sectioning_check_before\strc_sectioning_handle_page_yes
1155 \headparameter\c!inbetween
1156 \dostarttaggedchained\t!section\currenthead\??head
1157
1158 }
1159
1160\def\strc_sectioning_before_nop
1161 {\strc_sectioning_check_before\strc_sectioning_handle_page_nop
1162 \headparameter\c!inbetween
1163 \dostarttagged\currenthead\empty}
1164
1165\def\strc_sectioning_empty_correction
1166 {\ifconditional\c_strc_sectioning_empty
1167
1168 \penalty\plustenthousand
1169 \vskip\lineheight
1170 \kern\zeropoint
1171 \prevdepth\strutdepth
1172 \fi}
1173
1174\def\strc_sectioning_after_nop
1175 {}
1176
1177\def\strc_sectioning_check_before#1
1178 {\ifhmode
1179 \scratchcounter\lastpenalty
1180 \unpenalty
1181 \ifdim\lastskip=\s_strc_sectioning_continuous_signal
1182
1183 \ifconditional\c_strc_sectioning_ignore_page
1184 \setfalse\c_strc_sectioning_ignore_page
1185 \else
1186 \global\c_strc_sectioning_preceding_level\currentheadlevel
1187 \nobreak
1188 \fi
1189
1190 \else
1191 \penalty\scratchcounter
1192
1193 #1
1194 \fi
1195 \else
1196
1197 #1
1198 \fi}
1199
1200\def\currentsectioncountervalue {\clf_depthnumber\numexpr\thenamedheadlevel\currenthead\relax}
1201\def\previoussectioncountervalue{\clf_depthnumber\numexpr\thenamedheadlevel\currenthead\minusone\relax}
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215\def\currentsectioncountervalue {\clf_depthnumber\numexpr\thenamedheadlevel\currenthead\relax}
1216
1217\def\previoussectioncountervalue{\clf_depthnumber\numexpr\thenamedheadlevel\previoushead\relax}
1218
1219\let\previoushead\empty
1220
1221\def\strc_sectioning_handle_page_nop
1222 {\edef\p_continue{\headparameter\c!continue}
1223 \ifx\p_continue\v!yes
1224 \ifx\currenthead\previoushead
1225 \strc_sectioning_check_layout
1226 \else\ifnum\previoussectioncountervalue=\zerocount
1227 \strc_sectioning_check_layout
1228 \else\ifnum\currentsectioncountervalue>\zerocount
1229 \strc_sectioning_check_layout
1230 \fi\fi\fi
1231 \else
1232 \strc_sectioning_check_layout
1233 \fi
1234 \glet\previoushead\currenthead}
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277\def\strc_sectioning_handle_page_yes
1278 {\ifconditional\c_strc_sectioning_ignore_page
1279 \setfalse\c_strc_sectioning_ignore_page
1280 \else
1281
1282 \strc_sectioning_handle_page_nop
1283 \edef\p_aligntitle{\headparameter\c!aligntitle}
1284 \ifx\p_aligntitle\v!float
1285 \ifconditional\c_strc_sectioning_auto_break
1286 \spac_vspacing_same_page\currentheadlevel\zerocount
1287 \fi
1288 \headparameter\c!before\relax
1289 \indent
1290 \else
1291 \page_otr_command_flush_side_floats
1292 \ifconditional\c_strc_sectioning_auto_break
1293 \spac_vspacing_same_page\currentheadlevel\zerocount
1294 \fi
1295 \headparameter\c!before\relax
1296 \fi
1297 \global\c_strc_sectioning_preceding_level\currentheadlevel
1298 \fi
1299 \glet\previoushead\currenthead}
1300
1301\def\strc_sectioning_depth_correction
1302 {\ifvmode
1303 \edef\p_depthcorrection{\headparameter\c!depthcorrection}
1304 \ifx\p_depthcorrection\v!strut
1305 \prevdepth\strutdepth
1306 \fi
1307 \fi}
1308
1309\def\strc_sectioning_after_yes
1310 {\ifconditional\headisdisplay
1311 \ifconditional\c_strc_sectioning_auto_break
1312 \spac_vspacing_same_page\currentheadlevel\plusone
1313 \fi
1314 \strc_sectioning_empty_correction
1315 \headparameter\c!after
1316 \strc_sectioning_depth_correction
1317 \fi}
1318
1319\unexpanded\def\strc_sectioning_prevent_page_break
1320 {\ifconditional\c_strc_sectioning_auto_break
1321 \spac_vspacing_same_page\currentheadlevel\plustwo
1322 \fi}
1323
1324
1325
1326
1327
1328
1329
1330\def\thenamedheadlevel#1
1331 {\sectionlevel{\sectionheadsection{\sectionheadcoupling{#1}}}}
1332
1333\unexpanded\def\setupheadnumber
1334 {\dodoubleargument\strc_sectioning_setup_number}
1335
1336\def\strc_sectioning_setup_number[#1][#2]
1337 {\setstructurenumber{\thenamedheadlevel{#1}}{\number#2}}
1338
1339\def\currentheadnumber{0}
1340
1341\unexpanded\def\determineheadnumber[#1]
1342 {\xdef\currentheadnumber{\getstructurenumber{\thenamedheadlevel{#1}}}}
1343
1344
1345
1346\def\namedheadnumber #1{\getstructurenumber {\thenamedheadlevel{#1}}}
1347\def\somenamedheadnumber#1#2{\getsomestructurenumber{\thenamedheadlevel{#1}}{#2}}
1348
1349\unexpanded\def\headnumber
1350 {\dodoubleempty\strc_sectioning_number}
1351
1352\def\strc_sectioning_number[#1][#2]
1353 {\getsomefullstructurenumber{\iffirstargument\thenamedheadlevel{#1}\fi}{#2}}
1354
1355\unexpanded\def\someheadnumber
1356 {\dodoubleempty\strc_sectioning_number_some}
1357
1358\def\strc_sectioning_number_some[#1][#2]
1359 {\dontleavehmode
1360 \begingroup
1361 \edef\currenthead{#1}
1362 \getsomefullstructurenumber{\thenamedheadlevel{#1}}{#2}
1363 \endgroup}
1364
1365\let\sectioncountervalue\structurevalue
1366
1367\def\currentheadtext{obsolete,\space use marks}
1368
1369
1370
1371\let\startlistreferences\relax
1372\let\stoplistreferences \relax
1373
1374
1375
1376\newconditional\c_strc_sectioning_auto_levels
1377
1378\appendtoks
1379 \settrue\c_strc_sectioning_auto_levels
1380\to \everyenableelements
1381
1382\unexpanded\def\strc_sectioning_initialize_autolevel
1383 {\ifconditional\c_strc_sectioning_auto_levels
1384 \clf_autonextstructurelevel\currentheadlevel\relax
1385 \global\setfalse\c_strc_sectioning_auto_levels
1386 \fi}
1387
1388\unexpanded\def\triggerautostructurelevel
1389 {\global\settrue\c_strc_sectioning_auto_levels}
1390
1391\unexpanded\def\finalizeautostructurelevels
1392 {\clf_autofinishstructurelevels}
1393
1394\unexpanded\def\finalizeautostructurelevel
1395 {\dostoptagged
1396 \dostoptagged}
1397
1398\appendtoks
1399 \finalizeautostructurelevels
1400\to \everystoptext
1401
1402\stopcontextdefinitioncode
1403
1404\protect \endinput
1405 |