strc-con.mklx /size: 42 Kb    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=strc-con,
3%D        version=2008.10.20,
4%D          title=\CONTEXT\ Structure Macros,
5%D       subtitle=Constructions,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Structure Macros / Constructions}
15
16\registerctxluafile{strc-con}{}
17
18% todo: check why \copy .. probably mkii leftover
19%
20% todo: check if commands similar to lists
21% todo: \strc_constructions_setup_counter\strc_constructions_setup_counter{#1} in setup ... synchronization
22%
23% ? : \def\showdnlisttext{\constructionparameter\c!listtext}   % space in default
24%
25% maybe: pickup text and store in buffer ...
26%
27% \@@notemakeconstruction[##1]{}{##2}%
28% \expandafter\endgroup\noteparameter\c!next}}
29%
30% todo: \currentconstructionattribute : can be a counter instead
31
32%D Constructions are just descriptions but a bit more abstract so that we can
33%D conveniently build upon them. They are not really meant for users but module
34%D writers might find them useful. We mention a couple of parameters but these are
35%D only mentioned because in the shared code we map all resolvers to constructions.
36%D
37%D On top of constructions we build descriptions, enumerations, notes, labels and
38%D maybe some day more.
39
40\unprotect
41
42%D Todo:
43
44\installcorenamespace{construction}
45
46\installcommandhandler \??construction {construction} \??construction
47
48\aliased\let\setupconstructions\setupconstruction
49
50\setupconstructions[%
51    %c!title=,
52    %c!text=,
53    %
54    %c!style=,
55    %c!color=,
56    %c!command=,
57    %c!align=,
58    %
59    %c!headstyle=,
60    %c!headcolor=,
61    %c!headalign=,
62    %
63    %c!titlestyle=,
64    %c!titlecolor=,
65    %c!titlecommand=,
66    %c!titleleft=,
67    %c!titleright=,
68    %
69    %c!closesymbol=,
70    %c!closecommand=,
71    %
72    \c!alternative=\v!left,
73    \c!display=\v!yes,
74    \c!width=7\emwidth,
75    \c!distance=\emwidth,
76    \c!stretch=.50,
77    \c!shrink=.25,
78    \c!titledistance=.5\emwidth,
79    %c!hang=,
80    %c!sample=,
81    \c!margin=\v!no,
82    \c!before=\blank,
83    \c!inbetween=\blank,
84    \c!after=\blank,
85    %c!indentnext=,
86    %c!indenting=,
87    %
88    \c!expansion=\v!no,
89    %c!xmlsetup=,
90    %s!catcodes=,
91]
92
93%D Constructions and alike uses similar structures. In order to prevent issues
94%D we freeze some states. There is some overhead in the intermediate define
95%D step (as we could set them directly) but this is more flexible (and looks
96%D nicer). Keep in mind that descriptions, enumeration and notations are all
97%D independent and that we just remap the resolvers.
98
99% \defineconstruction[test][handler=description,level=1]
100% \defineconstruction[test][parent][handler=description,level=3]
101
102\installcorenamespace{constructionmain}  % frozen after definition
103\installcorenamespace{constructionlevel} % frozen after definition
104\installcorenamespace{constructionclass} % frozen after definition
105
106%aliased\let\currentconstructionhash           \??construction
107
108\mutable\let\currentconstructionmain           \empty
109\mutable\let\currentconstructionlevel          \empty
110\mutable\let\currentconstructionhandler        \empty
111
112\mutable\let\currentconstructionattribute      \empty
113\mutable\let\currentconstructionbookmark       \empty
114\mutable\let\currentconstructioncatcodes       \empty
115\mutable\let\currentconstructioncoding         \empty
116\mutable\let\currentconstructionexpansion      \empty
117\mutable\let\currentconstructionincrementnumber\empty
118\mutable\let\currentconstructionlabel          \empty
119\mutable\let\currentconstructionlist           \empty
120\mutable\let\currentconstructionlistentry      \empty
121\mutable\let\currentconstructionlistnumber     \empty
122\mutable\let\currentconstructionmarking        \empty
123\mutable\let\currentconstructionnumber         \empty
124\mutable\let\currentconstructionreference      \empty
125\mutable\let\currentconstructionreferencetext  \empty
126\mutable\let\currentconstructionreferenceprefix\empty
127\mutable\let\currentconstructionsynchronize    \empty
128\mutable\let\currentconstructiontitle          \empty
129\mutable\let\currentconstructionxmlsetup       \empty
130
131\settrue\c_strc_constructions_define_commands % use with care, might become a proper key
132
133\appendtoks
134    \ifempty\currentconstructionparent
135        \letcsname\??constructionmain\currentconstruction\endcsname\currentconstruction
136        \definelist[\currentconstruction]% goodie
137    \else
138        \letcsname\??constructionmain\currentconstruction\endcsname\currentconstructionparent
139        \definelist[\currentconstruction][\currentconstructionparent]% goodie
140    \fi
141    \edefcsname\??constructionlevel\currentconstruction\endcsname{\number\constructionparameter\c!level}%
142    \edefcsname\??constructionclass\currentconstruction\endcsname{\constructionparameter\s!handler}%
143\to \everydefineconstruction
144
145% todo: inhibit this when we have a different handle .. current we cannot do \frozen
146
147\appendtoks
148    \ifconditional\c_strc_constructions_define_commands
149        \protected\instance\edefcsname\e!start\currentconstruction\endcsname{\startnamedconstruction[\currentconstruction]}%
150        \protected\instance \defcsname\e!stop \currentconstruction\endcsname{\stopnamedconstruction}%
151    \fi
152\to \everydefineconstruction
153
154%D Just a basic environment (mostly for testing). We will provide a 'setup' based
155%D plugin once the rest is sorted out.
156
157\tolerant\permanent\protected\def\startnamedconstruction[#1]#*[#2]#*[#3]%
158  {\begingroup
159   \strc_constructions_initialize{#1}%
160   \strc_constructions_register[#3][\c!label={\constructionparameter\c!text},\c!reference=,\c!title=,\c!bookmark=,\c!list=,\c!referencetext=,#2]%
161   \csname\??constructionstarthandler\currentconstructionhandler\endcsname}
162
163\permanent\protected\def\stopnamedconstruction
164  {\csname\??constructionstophandler\currentconstructionhandler\endcsname
165   \endgroup}
166
167%D As we will build on top of the generic construction mechanism we have handlers
168%D as a sort of plug in mechanism. In order to have some consistency we share
169%D some namespaces.
170
171\installcorenamespace{constructioninitializer}
172\installcorenamespace{constructionfinalizer}
173
174\installcorenamespace{constructionmainhandler}
175\installcorenamespace{constructioncommandhandler}
176\installcorenamespace{constructionstarthandler}
177\installcorenamespace{constructionstophandler}
178
179\installcorenamespace{constructiontexthandler}
180\installcorenamespace{constructionnotehandler}
181
182\protected\def\strc_constructions_initialize#1% class instance
183  {\edef\currentconstruction{#1}%
184   \enforced\let\currentconstructionhash\??construction
185   \let\currentconstructionlistentry\!!zerocount
186   \enforced\expandafter\let\expandafter\currentconstructionmain   \csname\??constructionmain \currentconstruction\endcsname
187   \enforced\expandafter\let\expandafter\currentconstructionlevel  \csname\??constructionlevel\currentconstruction\endcsname
188   \enforced\expandafter\let\expandafter\currentconstructionhandler\csname\??constructionclass\currentconstruction\endcsname
189   \csname\??constructioninitializer\currentconstructionhandler\endcsname}
190
191\protected\def\strc_constructions_finalize
192  {\csname\??constructionfinalizer\currentconstructionhandler\endcsname
193   \strc_constructions_discard}
194
195\newconditional\c_strc_constructions_number_state
196\newconditional\c_strc_constructions_title_state
197
198\protected\defcsname\??constructioninitializer\v!construction\endcsname
199  {\setfalse\c_strc_constructions_number_state
200   \setfalse\c_strc_constructions_title_state}
201
202\protected\defcsname\??constructionfinalizer\v!construction\endcsname
203  {}
204
205%D We keep the command variant around but rather would move to the start-stop one.
206%D Also, passing the title as argument has some history so we need to keep that as
207%D well.
208
209% \ifdefined\dotagsetconstruction \else \aliased\let\dotagsetconstruction\relax \fi
210
211% \startuseMPgraphic{MyFrame}
212%     picture p ; numeric o ; path a, b ; pair c ;
213%     p := textext.rt("\FunnyFramed{\currentconstructiontext}") ;
214%   % p := textext.rt("\wrappedconstruction{\FunnyFramed{\currentconstructiontext}}") ;
215%   % p := textext.rt("\FunnyFramed{\wrappedconstruction{\currentconstructiontext}}") ;
216%   % p := textext.rt("\FunnyFramed{\wrappedcurrentconstruction}") ;
217%     ...
218% \stopuseMPgraphic
219%
220% \defineoverlay[MyFrame][\useMPgraphic{MyFrame}]
221%
222% \defineframedtext
223%   [MyText]
224%   [frame=off,
225%    background=MyFrame]
226%
227% \defineenumeration[Theorem]
228%   [alternative=empty,
229%    before=\startMyText,
230%    after=\stopMyText]
231
232\newtoks\everyconstruction
233
234\permanent\protected\def\currentconstructiontext
235  {\begstrut
236   \csname\??constructiontexthandler\currentconstructionhandler\endcsname
237   \endstrut}
238
239\permanent\protected\def\currentconstructionsample
240  {\begstrut
241   \constructionparameter\c!text
242   \p_strc_constructions_sample
243   \endstrut}
244
245\permanent\protected\def\wrappedconstruction#1%
246  {\begingroup
247     \iftrialtypesetting \else
248       \currentconstructionsynchronize
249       \c_attr_destination\currentconstructionattribute\relax
250     \fi
251     #1%
252   \endgroup}
253
254\permanent\protected\def\wrappedcurrentconstruction
255  {\begingroup
256     \iftrialtypesetting \else
257       \currentconstructionsynchronize
258       \c_attr_destination\currentconstructionattribute\relax
259     \fi
260     \currentconstructiontext
261   \endgroup}
262
263\protected\defcsname\??constructionmainhandler\v!construction\endcsname#1%
264  {\iftrialtypesetting \else
265     \begingroup
266     \currentconstructionsynchronize % reinstated
267     \c_attr_destination\currentconstructionattribute\relax % todo, whole text
268     \signalcharacter
269     \endgroup
270   \fi#1}
271
272\protected\defcsname\??constructiontexthandler\v!construction\endcsname
273  {\begingroup
274   \useconstructionstyleandcolor\c!headstyle\c!headcolor % move to \currentconstructiontext
275   \the\everyconstruction
276   \constructionparameter\c!headcommand
277     {\strut
278      \constructionparameter\c!text
279      \clf_savedlisttitle{\currentconstructionmain}\currentconstructionlistentry\relax}%
280   \endgroup}
281
282\protected\def\strc_constructions_stored_start
283  {\begingroup % brrr \endgroup elsewhere ... will be sorted out
284   \csname\??constructionstarthandler\currentconstructionhandler\endcsname}
285
286\protected\def\strc_constructions_stored_stop
287  {\csname\??constructionstophandler\currentconstructionhandler\endcsname}
288
289\newconstant\c_strc_constructions_nested_state % to be redone
290
291% not used any more
292%
293% \def\resetconstructions % to be used in e.g. footnotes
294%   {\c_strc_constructions_nested_state\zerocount}
295
296\protected\defcsname\??constructioncommandhandler\v!construction\endcsname
297  {\endgroup}
298
299\let\p_strc_constructions_sample        \empty
300\let\p_strc_constructions_align         \empty
301\let\p_strc_constructions_indenting     \empty
302\let\p_strc_constructions_width         \empty
303\let\p_strc_constructions_aligntitle    \empty
304\let\p_strc_constructions_renderingsetup\empty
305\let\p_strc_constructions_headalign     \empty
306\let\p_strc_constructions_hang          \empty
307\let\p_strc_constructions_inbetween     \empty
308\let\p_strc_constructions_closesymbol   \empty
309\let\p_strc_constructions_distance      \empty
310
311\newconditional\c_strc_constructions_distance_none
312
313\def\strc_constructions_set_width_and_distance
314  {\assignwidth
315     \p_strc_constructions_width
316     \constructionsheadwidth
317     {\unhcopy\constructionheadbox}
318     \constructionsheaddistance}
319
320\def\strc_constructions_preroll_head#content%
321  {\setbox\constructionheadbox\hbox
322     {\forgetall
323      \dontcomplain
324      \settrialtypesetting
325      \csname\??constructionmainhandler\currentconstructionhandler\endcsname#content}}
326
327\def\strc_constructions_ignore_head
328  {\constructionsheaddistance\zeropoint
329   \constructionsheadwidth   \zeropoint
330   % we also need to make sure that no stretch creeps in (new per 2015-02-02, for Alan)
331   \settrue\c_strc_constructions_distance_none}
332
333\protected\defcsname\??constructionstarthandler\v!construction\endcsname % this will be redone (reorganized) .. too much boxing
334  {\dostarttaggedchained\t!construction\currentconstruction\currentconstructionhash
335%    \dotagsetconstruction
336   \constructionparameter\c!before
337   \begingroup
338   \edef\currentconstructionalternative{\constructionparameter\c!alternative}%
339   \edef\p_strc_constructions_renderingsetup{\constructionalternativeparameter\c!renderingsetup}%
340   % catch fuzzyness
341   \ifempty\p_strc_constructions_renderingsetup
342      \letconstructionparameter\c!alternative\v!left
343      \let\currentconstructionalternative\v!left
344      \edef\p_strc_constructions_renderingsetup{\constructionalternativeparameter\c!renderingsetup}%
345   \else
346     \doifnotsetups\p_strc_constructions_renderingsetup
347       {\letconstructionparameter\c!alternative\v!left
348        \let\currentconstructionalternative\v!left
349        \edef\p_strc_constructions_renderingsetup{\constructionalternativeparameter\c!renderingsetup}}%
350   \fi
351   %
352   \doadaptleftskip{\constructionparameter\c!margin}%
353   \setlocalhsize % so we can use \localhsize in width assignments
354   \edef\p_strc_constructions_distance{\constructionalternativeparameter\c!distance}%
355   \edef\p_strc_constructions_width{\constructionalternativeparameter\c!width}%
356   \ifx\p_strc_constructions_distance\v!none
357     \settrue\c_strc_constructions_distance_none
358     \constructionsheaddistance\zeropoint
359   \else
360     \setfalse\c_strc_constructions_distance_none
361     \constructionsheaddistance\p_strc_constructions_distance\relax
362     \ifdim\constructionsheaddistance=\zeropoint
363       \ifx\p_strc_constructions_width\v!broad
364         \constructionsheaddistance\emwidth
365       \orelse\ifx\p_strc_constructions_width\v!line
366         \constructionsheaddistance\emwidth
367       \fi
368     \fi
369   \fi
370   % inefficient and not always needed, for instance not with margins so we will make checkers
371   % per alternative some day (especially in labels this is unwanted overhead)
372   %
373   % maybe we should have an option as i cannot oversee the consequences now
374   %
375   % \edef\p_strc_constructions_sample{\constructionparameter\c!sample}%
376   % \ifempty\p_strc_constructions_sample
377   %   \strc_constructions_preroll_head\currentconstructiontext
378   % \else
379   %   \strc_constructions_preroll_head\currentconstructiontextsample
380   % \fi
381   % \strc_constructions_set_width_and_distance
382   %
383   \strc_constructions_preroll_head\currentconstructiontext
384   \ifzeropt\wd\constructionheadbox
385     \strc_constructions_ignore_head
386   \else
387     \edef\p_strc_constructions_sample{\constructionparameter\c!sample}%
388     \ifempty\p_strc_constructions_sample
389       \strc_constructions_set_width_and_distance
390     \else
391       \strc_constructions_preroll_head\currentconstructionsample
392       \ifzeropt\wd\constructionheadbox
393         \strc_constructions_ignore_head
394       \else
395         \strc_constructions_set_width_and_distance
396       \fi
397     \fi
398   \fi
399   %
400   \dostarttagged\t!constructiontag\empty % todo
401   \setbox\constructionheadbox\hbox
402     {\forgetall
403      \dontcomplain
404      \ifx\currentconstructionalternative\v!serried % brrr, hack, will change
405        \csname\??constructionmainhandler\currentconstructionhandler\endcsname\currentconstructiontext
406      \else
407        \csname\??constructionmainhandler\currentconstructionhandler\endcsname{\boxedconstructionhead\currentconstructiontext}%
408      \fi}%
409   \edef\p_strc_constructions_aligntitle{\constructionparameter\c!aligntitle}%
410   \ifx\p_strc_constructions_aligntitle\v!no
411     \leftconstructionskip \leftskip
412     \rightconstructionskip\rightskip
413   \else
414     \ifcase\c_strc_constructions_nested_state
415       \leftconstructionskip \leftskip
416       \rightconstructionskip\rightskip
417     \fi
418   \fi
419   \edef\p_strc_constructions_align{\constructionparameter\c!align}%
420   \ifempty\p_strc_constructions_align \else
421     \setupalign[\p_strc_constructions_align]% \use...
422   \fi
423   \ifcase\c_strc_constructions_nested_state
424     \c_strc_constructions_nested_state\plusone
425   \or
426     \c_strc_constructions_nested_state\plustwo
427   \fi
428   \strc_constructions_close_symbol_reset
429   %
430   \edef\p_strc_constructions_headalign{\constructionparameter\c!headalign}%
431   %
432   \directsetup\p_strc_constructions_renderingsetup\relax
433   % moved to here 2014-07-03
434   \edef\p_strc_constructions_indenting{\constructionparameter\c!indenting}%
435   \ifempty\p_strc_constructions_indenting \else
436     \indenting[\p_strc_constructions_indenting]% \use...
437   \fi
438   %
439   \dostoptagged % tag
440   \dostarttagged\t!constructioncontent\empty
441  %\freezeparagraphproperties
442   \updateparagraphshapes
443   \ignorespaces} % args not needed
444
445\protected\defcsname\??constructionstophandler\v!construction\endcsname
446  {\strc_constructions_close_symbol_place
447   \doifnot{\constructionparameter\c!display}\v!no\par
448   \dostoptagged % content
449   \dostoptagged % construction
450   \endgroup
451   \constructionparameter\c!after
452   \useindentnextparameter\constructionparameter
453   \strc_constructions_finalize
454%   \endgroup
455   \dorechecknextindentation}
456
457\permanent\protected\def\boxedconstructionhead#1%
458  {\doifelse{\constructionalternativeparameter\c!alignbottom}{\v!yes}\vbox\vtop
459     {\hsize\constructionsheadwidth
460      \edef\p_strc_constructions_headalign{\constructionparameter\c!headalign}%
461      \ifempty\p_strc_constructions_headalign \else
462        \setupalign[\p_strc_constructions_headalign]% \use...
463      \fi
464      #1}}
465
466\installcorenamespace{constructionalternative}
467\installcorenamespace{constructionrenderings}
468
469% see lists: alternativemethods ... todo
470%
471% there will be a proper interface to variables
472
473\installcommandhandler \??constructionalternative {constructionalternative} \??constructionalternative
474
475\setupconstructionalternative
476  [%c!left=, % no inheritance
477   %c!right=,% no inheritance
478   \c!width=\constructionparameter\c!width,
479   \c!distance=\constructionparameter\c!distance,
480   \c!stretch=\constructionparameter\c!stretch,
481   \c!shrink=\constructionparameter\c!shrink]
482
483\defineconstructionalternative
484  [\v!left]
485  [%\c!width=7em,
486   %\c!distance=1em,
487   \c!renderingsetup=\??constructionrenderings:\v!left]
488
489\defineconstructionalternative
490  [\v!right]
491  [%\c!width=7em,
492   %\c!distance=1em,
493   \c!renderingsetup=\??constructionrenderings:\v!right]
494
495\defineconstructionalternative
496  [\v!inmargin]
497  [\c!renderingsetup=\??constructionrenderings:\v!inmargin]
498
499\defineconstructionalternative
500  [\v!inleft]
501  [\c!renderingsetup=\??constructionrenderings:\v!inleft]
502
503\defineconstructionalternative
504  [\v!inright]
505  [\c!renderingsetup=\??constructionrenderings:\v!inright]
506
507\defineconstructionalternative
508  [\v!margin]
509  [\c!renderingsetup=\??constructionrenderings:\v!margin]
510
511\defineconstructionalternative
512  [\v!leftmargin]
513  [\c!renderingsetup=\??constructionrenderings:\v!leftmargin]
514
515\defineconstructionalternative
516  [\v!rightmargin]
517  [\c!renderingsetup=\??constructionrenderings:\v!rightmargin]
518
519\defineconstructionalternative
520  [\v!innermargin]
521  [\c!renderingsetup=\??constructionrenderings:\v!innermargin]
522
523\defineconstructionalternative
524  [\v!outermargin]
525  [\c!renderingsetup=\??constructionrenderings:\v!outermargin]
526
527\defineconstructionalternative
528  [\v!serried]
529  [\c!renderingsetup=\??constructionrenderings:\v!serried]
530
531\defineconstructionalternative
532  [\v!hanging]
533  [%\c!width=.75\emwidth
534   \c!renderingsetup=\??constructionrenderings:\v!hanging]
535
536\defineconstructionalternative
537  [\v!top]
538  [\c!renderingsetup=\??constructionrenderings:\v!top,
539   \c!width=\localhsize]
540
541\defineconstructionalternative
542  [\v!command]
543  [\c!renderingsetup=\??constructionrenderings:\v!command]
544
545\defineconstructionalternative
546  [\v!empty]
547  [\c!renderingsetup=\??constructionrenderings:\v!empty]
548
549\defineconstructionalternative
550  [\v!label]
551  [\c!renderingsetup=\??constructionrenderings:\v!label,
552   \c!width=]
553
554\newbox   \constructionheadbox
555\newskip  \leftconstructionskip
556\newskip  \rightconstructionskip
557\newdimen \constructionsheadwidth
558\newdimen \constructionsheaddistance
559
560\def\strc_constructions_set_hang_box#1% messy left/rightskip
561  {\setbox\constructionheadbox\vtop   % \vbox gaat fout in hang
562     {\forgetall
563      \dontcomplain
564      \hsize\constructionsheadwidth\relax
565      \ifempty\p_strc_constructions_headalign
566        \setupalign[#1]% use fast one
567      \else
568        \setupalign[\p_strc_constructions_headalign]% use fast one
569      \fi
570      \ifconditional\c_strc_constructions_distance_none \else
571        \advance\ifx#1\v!flushleft\rightskip\else\leftskip\fi\constructionsheaddistance % only difference and wrong anyway
572      \fi
573      \flushconstructionheadbox}%
574   \setbox\constructionheadbox\hpack{\box\constructionheadbox}% needed in case of e.g. a real big head font, see descriptions-006.tex
575   \ht\constructionheadbox\strutht
576   \dp\constructionheadbox\strutdp}
577
578\def\strc_constructions_set_pure_box#1% default ... better set up differently
579  {\setbox\constructionheadbox\vtop
580     {\forgetall
581      \dontcomplain
582      \hsize\constructionsheadwidth\relax
583      \ifempty\p_strc_constructions_headalign
584        \setupalign[#1]% use fast one
585      \else
586        \setupalign[\p_strc_constructions_headalign]% use fast one
587      \fi
588      \flushconstructionheadbox}%
589   \setbox\constructionheadbox\hpack{\box\constructionheadbox}% needed in case of e.g. a real big head font, see descriptions-006.tex
590   \ht\constructionheadbox\strutht
591   \dp\constructionheadbox\strutdp}
592
593\def\strc_constructions_set_hang#1%
594  {\ifempty\p_strc_constructions_hang
595     % nothing
596   \orelse\ifx\p_strc_constructions_hang\v!fit
597     \scratchdimen\htdp\constructionheadbox
598     \getnoflines\scratchdimen
599     \hangafter-\noflines
600   \orelse\ifx\p_strc_constructions_hang\v!broad
601     \scratchdimen\dimexpr\htdp\constructionheadbox+.5\strutht\relax
602     \getnoflines\scratchdimen
603     \hangafter-\noflines
604   \else
605     \hangafter-\p_strc_constructions_hang
606   \fi
607   \relax
608   \hangindent\ifx#1\v!right-\fi\constructionsheadwidth}
609
610\permanent\protected\def\flushconstructionheadbox
611  {\ifhbox\constructionheadbox\unhbox\else\box\fi\constructionheadbox}
612
613% The setups. These only deal with placement of the descriptor and initializing the
614% environment. The wrapping happens elsewhere.
615
616% todo: optimize the setups with
617%
618% \ifconditional\c_strc_constructions_distance_none : no need for skip
619% \ifzeropt\wd\constructionheadbox : no need for box and skips
620
621\startsetups[\??constructionrenderings:\v!left]
622    \edef\p_strc_constructions_hang{\constructionparameter\c!hang}%
623    \doifelsesetups{\??constructionrenderings:\v!left:\p_strc_constructions_hang} {
624        \directsetup{\??constructionrenderings:\v!left:\p_strc_constructions_hang}
625    } {
626        \directsetup{\??constructionrenderings:\v!left:\v!hanging}
627    }
628\stopsetups
629
630\startsetups[\??constructionrenderings:\v!right]
631    \edef\p_strc_constructions_hang{\constructionparameter\c!hang}
632    \doifelsesetups{\??constructionrenderings:\v!right:\p_strc_constructions_hang} {
633        \directsetup{\??constructionrenderings:\v!right:\p_strc_constructions_hang}
634    } {
635        \directsetup{\??constructionrenderings:\v!right:\v!hanging}
636    }
637\stopsetups
638
639\startsetups[\??constructionrenderings:\v!left:\v!none]
640    \enforced\let\\\crlf
641    \noindent
642    \strc_constructions_set_pure_box\v!flushleft
643    \leftskip\dimexpr\leftconstructionskip+\constructionsheadwidth+\constructionsheaddistance\relax
644    \rightskip\rightconstructionskip\relax
645    \llap {
646        \hpack to \leftskip {
647            \hskip\leftconstructionskip
648            \box\constructionheadbox % was copy
649            \hss
650        }
651    }
652    \nobreak
653    \useconstructionstyleandcolor\c!style\c!color
654    \ignorespaces
655\stopsetups
656
657\startsetups[\??constructionrenderings:\v!left:0]
658    \directsetup{\??constructionrenderings:\v!left:\v!none}
659\stopsetups
660
661\startsetups[\??constructionrenderings:\v!left:]
662    \directsetup{\??constructionrenderings:\v!left:\v!none}
663\stopsetups
664
665\startsetups[\??constructionrenderings:\v!right:\v!none]
666    \enforced\let\\\crlf
667    \noindent
668    \leftskip\leftconstructionskip
669    \rightskip\dimexpr\rightconstructionskip+\constructionsheadwidth\relax
670   %\strc_constructions_pure_hang_box\raggedleft
671    \strc_constructions_set_pure_box\v!flushright
672    \rlap {
673        \hskip\dimexpr\hsize-\leftskip-\rightskip\relax
674        \copy\constructionheadbox
675        \hskip\rightconstructionskip
676    }
677    \nobreak
678    \advance\rightskip \constructionsheaddistance
679    \useconstructionstyleandcolor\c!style\c!color
680    \ignorespaces
681\stopsetups
682
683\startsetups[\??constructionrenderings:\v!right:0]
684    \directsetup{\??constructionrenderings:\v!right:\v!none}
685\stopsetups
686
687\startsetups[\??constructionrenderings:\v!right:]
688    \directsetup{\??constructionrenderings:\v!right:\v!none}
689\stopsetups
690
691\startsetups[\??constructionrenderings:\v!left:\v!margin]%
692    \enforced\let\\\crlf
693    \noindent
694    \strc_constructions_set_pure_box\v!flushleft
695    \llap {
696        \hpack to \constructionsheadwidth {
697            \box\constructionheadbox % was copy
698            \hss
699        }
700        \hskip\constructionsheaddistance
701    }
702    \useconstructionstyleandcolor\c!style\c!color
703    \ignorespaces
704\stopsetups
705
706\startsetups[\??constructionrenderings:\v!right:\v!margin]%
707    \enforced\let\\\crlf
708    \noindent
709    \strc_constructions_set_pure_box\v!flushright
710    \rlap {
711        \hskip\constructionsheaddistance
712        \hpack to \constructionsheadwidth {
713            \box\constructionheadbox % was copy
714            \hss
715        }
716    }
717    \useconstructionstyleandcolor\c!style\c!color
718    \ignorespaces
719\stopsetups
720
721\startsetups[\??constructionrenderings:\v!left:\v!hanging]%
722    \enforced\let\\\crlf
723    \dontcomplain
724    \advance\constructionsheadwidth \constructionsheaddistance
725    \strc_constructions_set_hang_box\v!flushleft
726    \strc_constructions_set_hang\v!left
727    \noindent
728    \llap {
729        \tpack to \zeropoint {
730            \box\constructionheadbox
731        }
732    }
733    \nobreak
734    \useconstructionstyleandcolor\c!style\c!color
735    \ignorespaces
736\stopsetups
737
738\startsetups[\??constructionrenderings:\v!right:\v!hanging]%
739    \enforced\let\\\crlf
740    \dontcomplain
741    \advance\constructionsheadwidth \constructionsheaddistance
742    \strc_constructions_set_hang_box\v!flushright
743    \strc_constructions_set_hang\v!right
744    \noindent
745    \rlap {
746        \hpack to \dimexpr\hsize-\leftskip-\rightskip\relax {
747            \hss
748            \tpack to \zeropoint {
749                \box\constructionheadbox
750            }
751        }
752    }
753    \nobreak
754    \useconstructionstyleandcolor\c!style\c!color
755    \ignorespaces
756\stopsetups
757
758\startsetups[\??constructionrenderings:\v!top]
759  % \strc_sectioning_prevent_page_break % commented per 31/5/2019
760    \enforced\let\\\space
761    \noindent
762    \copy\constructionheadbox % why copy ?
763    \par
764    \nobreak
765    \edef\p_strc_constructions_inbetween{\constructionparameter\c!inbetween}%
766    \ifempty\p_strc_constructions_inbetween \else
767      \p_strc_constructions_inbetween
768      % shouldn't this move to after the fi?
769      \directcheckedvspacing\v!samepage
770    \fi
771    \useconstructionstyleandcolor\c!style\c!color
772    \ignorespaces
773\stopsetups
774
775% why copy? historic reason?
776
777\startsetups[\??constructionrenderings:\v!margin]
778    \enforced\let\\\crlf
779    \noindent
780    \inmargin[\c!scope=\v!local]{\flushconstructionheadbox}%
781    \useconstructionstyleandcolor\c!style\c!color
782    \ignorespaces
783\stopsetups
784
785\startsetups[\??constructionrenderings:\v!leftmargin]
786    \enforced\let\\\crlf
787    \noindent
788    \inleft[\c!scope=\v!local]{\flushconstructionheadbox}%
789    \useconstructionstyleandcolor\c!style\c!color
790    \ignorespaces
791\stopsetups
792
793\startsetups[\??constructionrenderings:\v!rightmargin]
794    \enforced\let\\\crlf
795    \noindent
796    \inright[\c!scope=\v!local]{\flushconstructionheadbox}%
797    \useconstructionstyleandcolor\c!style\c!color
798    \ignorespaces
799\stopsetups
800
801\startsetups[\??constructionrenderings:\v!innermargin]
802    \enforced\let\\\crlf
803    \noindent
804    \ininner[\c!scope=\v!local]{\flushconstructionheadbox}%
805    \useconstructionstyleandcolor\c!style\c!color
806    \ignorespaces
807\stopsetups
808
809\startsetups[\??constructionrenderings:\v!outermargin]
810    \enforced\let\\\crlf
811    \noindent
812    \inouter[\c!scope=\v!local]{\flushconstructionheadbox}%
813    \useconstructionstyleandcolor\c!style\c!color
814    \ignorespaces
815\stopsetups
816
817\startsetups[\??constructionrenderings:\v!inmargin]
818    \directsetup{\??constructionrenderings:\v!margin}
819\stopsetups
820
821\startsetups[\??constructionrenderings:\v!inleft]
822    \directsetup{\??constructionrenderings:\v!leftmargin}
823\stopsetups
824
825\startsetups[\??constructionrenderings:\v!inright]
826    \directsetup{\??constructionrenderings:\v!rightmargin}
827\stopsetups
828
829\startsetups[\??constructionrenderings:\v!serried]
830    % already set?
831    \edef\p_strc_constructions_width{\constructionparameter\c!width}% CHECK ! ! ! wrong parameter namespace
832    \doifelsesetups{\??constructionrenderings:\v!serried:\p_strc_constructions_width} {
833        \directsetup{\??constructionrenderings:\v!serried:\p_strc_constructions_width}
834    } {
835        \directsetup{\??constructionrenderings:\v!serried:\v!wide}
836    }
837\stopsetups
838
839\startsetups[\??constructionrenderings:\v!serried:\v!fit]
840    \enforced\let\\\crlf
841    \noindent
842    \flushconstructionheadbox
843    \nobreak
844    \hskip\constructionsheaddistance\relax
845    \useconstructionstyleandcolor\c!style\c!color
846    \ignorespaces
847\stopsetups
848
849\startsetups[\??constructionrenderings:\v!serried:\v!broad]
850    \enforced\let\\\crlf
851    \noindent
852    \flushconstructionheadbox
853    \ifconditional\c_strc_constructions_distance_none \else
854        \nobreak
855        \hskip\constructionsheaddistance
856          \s!plus \constructionalternativeparameter\c!stretch\constructionsheaddistance
857          \s!minus\constructionalternativeparameter\c!shrink \constructionsheaddistance
858        \relax
859    \fi
860    \useconstructionstyleandcolor\c!style\c!color
861    \ignorespaces
862\stopsetups
863
864\startsetups[\??constructionrenderings:\v!serried:]
865    \directsetup{\??constructionrenderings:\v!serried:\v!broad}
866\stopsetups
867
868\startsetups[\??constructionrenderings:\v!serried:\v!wide]
869    \enforced\let\\\crlf
870    \noindent
871    \hbox to \constructionsheadwidth {
872        \flushconstructionheadbox
873        \hss
874    }
875    \nobreak
876    \hskip\constructionsheaddistance\relax
877    \useconstructionstyleandcolor\c!style\c!color
878    \ignorespaces
879\stopsetups
880
881\startsetups[\??constructionrenderings:\v!hanging]
882    % tricky: leftskipadaption is somewhat unpredictable
883    \enforced\let\\\crlf
884    \noindent
885    \advance\leftskip-\leftskipadaption\relax
886    \ifdim\leftskipadaption=\zeropoint
887        \leftskipadaption1.5\emwidth\relax % just some default
888        \ifnum\c_strc_constructions_nested_state=\plusone
889            \ifdim\leftskip>\zeropoint \relax
890                \leftskipadaption\leftskip
891            \fi
892        \fi
893    \fi
894    \ifnum\c_strc_constructions_nested_state>\zerocount % was \ifnum\c_strc_constructions_nested_state=\plusone
895        \advance\leftskip\leftskipadaption % but we're already further on
896    \fi
897    \hskip-\leftskipadaption\relax
898    \ifhbox\constructionheadbox \unhbox\else\box\fi\constructionheadbox
899    \ifconditional\c_strc_constructions_distance_none \else
900      % we used to have just a kern, but long lines look bad then
901      \scratchdistance\ifdim\constructionsheaddistance=\zeropoint .75\emwidth\else\constructionsheaddistance\fi
902      \hskip \scratchdistance
903        \s!plus \constructionalternativeparameter\c!stretch\scratchdistance
904        \s!minus\constructionalternativeparameter\c!shrink \scratchdistance
905    \fi
906    \ifhmode
907        \ifx\p_strc_constructions_width\v!line
908            \hfill\break
909        \else
910            \allowbreak
911        \fi
912    \fi
913    \useconstructionstyleandcolor\c!style\c!color
914    \ignorespaces
915\stopsetups
916
917%D \starttyping
918%D \setupfootnotation[location=command,headcommand=\llap]
919%D \stoptyping
920
921\startsetups[\??constructionrenderings:\v!command]
922    \noindent
923    \constructionparameter\c!headcommand{\flushconstructionheadbox}
924    \useconstructionstyleandcolor\c!style\c!color
925    \ignorespaces
926\stopsetups
927
928\startsetups[\??constructionrenderings:\v!empty]
929    \noindent
930    \useconstructionstyleandcolor\c!style\c!color
931    \ignorespaces
932\stopsetups
933
934\startsetups[\??constructionrenderings:\v!label]
935    \dontleavehmode
936    \begingroup
937    \constructionparameter\c!headcommand{\flushconstructionheadbox}
938    \endgroup
939\stopsetups
940
941\ifcase\contextlmtxmode \else
942    % just an empty check so that we can grep for contextlmtxmode in mkiv files
943\fi
944
945% \definedescription[whatever][alternative=right:bottom]
946%
947% \startwhatever{just a small\\example}
948%     \input ward
949% \stopwhatever
950
951\defineconstructionalternative
952  [\v!right:\v!bottom]
953  [%\c!width=7em,
954   %\c!distance=1em,
955   \c!alignbottom=\v!yes,
956   \c!renderingsetup=\??constructionrenderings:\v!right:\v!bottom]
957
958\startsetups[\??constructionrenderings:\v!right:\v!bottom]
959    \enforced\let\\\crlf
960    \noindent
961    \leftskip\leftconstructionskip
962    \rightskip\dimexpr\rightconstructionskip+\constructionsheadwidth+\constructionsheaddistance\relax
963    \parfillskip\zeropoint
964    \strc_constructions_set_pure_box\v!flushright
965    \directparwrapper \relax {%
966      \hfilll
967      \rlap
968        {\kern\constructionsheaddistance
969         \copy\constructionheadbox}%
970    }%
971    \useconstructionstyleandcolor\c!style\c!color
972    \ignorespaces
973\stopsetups
974
975%D This next feature will get an lmtx implementation (probably by using a new generic
976%D close mechanism).
977
978% you can use \placeclosesymbol or \qed to place a symbol at the end of a
979% construction
980
981\installcorenamespace{constructionclosesymbol}
982
983\mutable\let\placeclosesymbol\donothing
984\mutable\let\qed             \donothing
985
986\def\strc_constructions_close_symbol_reset % no need for global
987  {\global\expandafter\settrue\csname\??constructionclosesymbol\currentconstruction\endcsname
988   \let\placeclosesymbol\strc_constructions_close_symbol_place
989   \let\qed             \strc_constructions_close_symbol_place}
990
991\protected\def\strc_constructions_close_symbol_place
992  {\ifconditional\csname\??constructionclosesymbol\currentconstruction\endcsname
993     \global\expandafter\setfalse\csname\??constructionclosesymbol\currentconstruction\endcsname
994     \edef\p_strc_constructions_closesymbol{\constructionparameter\c!closesymbol}%
995     \ifempty\p_strc_constructions_closesymbol \else
996       \constructionparameter\c!closecommand{\p_strc_constructions_closesymbol}% hm why {} maybe because box expected
997     \fi
998   \fi}
999
1000\newif\ifnoconstructioncaption
1001
1002%D The storage macros:
1003
1004\mutable\let\currentconstructionlistentry\!!zerocount
1005
1006\protected\def\strc_constructions_register
1007  {\clf_doifelselisthasentry\numexpr\currentconstructionlistentry\relax
1008     \strc_constructions_register_nop
1009     \strc_constructions_register_yes}
1010
1011% \def\strc_constructions_register{\strc_constructions_register_yes}
1012
1013\def\strc_constructions_register_nop[#1][#2]% #1=optional user data #2=interfaced-settings
1014 %{\writestatus{constructions}{reusing \currentconstruction: \number\currentconstructionlistentry}}
1015  {}
1016
1017\def\strc_constructions_discard
1018  {\iftrialtypesetting
1019   % \writestatus{constructions}{discarding \currentconstruction: \number\currentconstructionlistentry}%
1020     \clf_discardfromlist\currentconstructionlistentry\relax
1021   \fi}
1022
1023\let\currentconstructionlistnumber \!!zerocount
1024\let\currentconstructionsynchronize\relax
1025\let\currentconstructionattribute  \attributeunsetvalue
1026
1027\def\strc_constructions_register_yes[#1][#2]% #1=optional user data #2=interfaced-settings
1028  {\begingroup                              % similar to structure so we might generalize this
1029   \setupcurrentconstruction[#2]%           % xdef's will become edef's
1030   \xdef\currentconstructionexpansion      {\constructionparameter\c!expansion}%
1031   \xdef\currentconstructionxmlsetup       {\constructionparameter\c!xmlsetup}%
1032   \xdef\currentconstructioncatcodes       {\constructionparameter\s!catcodes}%
1033   \xdef\currentconstructionlabel          {\constructionparameter\c!label}%
1034   \xdef\currentconstructionreference      {\constructionparameter\c!reference}%
1035   \xdef\currentconstructionreferencetext  {\constructionparameter\c!referencetext}%
1036   \xdef\currentconstructionreferenceprefix{\constructionparameter\c!referenceprefix}%
1037   %xdef\currentconstructionshownumber     {\constructionparameter\c!number}%
1038   \xdef\currentconstructionincrementnumber{\constructionparameter\c!incrementnumber}%
1039   %
1040   \ifempty\currentconstructionexpansion
1041     \glet\currentconstructionexpansion\v!no
1042   \fi
1043   %
1044   \ifempty\currentconstructionreferenceprefix
1045     \glet\currentconstructionreferenceprefix\referenceprefix
1046   \fi
1047   \ifx\currentconstructionexpansion\s!xml
1048     \xmlstartraw
1049       \xdef\currentconstructiontitle        {\constructionparameter\c!title}%
1050       \xdef\currentconstructionbookmark     {\constructionparameter\c!bookmark}%
1051       \xdef\currentconstructionmarking      {\constructionparameter\c!marking}%
1052       \xdef\currentconstructionlist         {\constructionparameter\c!list}%
1053       \xdef\currentconstructionreferencetext{\constructionparameter\c!referencetext}%
1054     \xmlstopraw
1055     \ifempty\currentconstructionlist
1056       \glet\currentconstructionlist\currentconstructiontitle
1057     \fi
1058     \glet\currentconstructioncoding\s!xml
1059   \else
1060     \ifx\currentconstructionexpansion\v!yes
1061       \xdef\currentconstructiontitle        {\constructionparameter\c!title}%
1062       \xdef\currentconstructionbookmark     {\constructionparameter\c!bookmark}%
1063       \xdef\currentconstructionmarking      {\constructionparameter\c!marking}%
1064       \xdef\currentconstructionlist         {\constructionparameter\c!list}%
1065       \xdef\currentconstructionreferencetext{\constructionparameter\c!referencetext}%
1066     \else
1067       \xdef\currentconstructiontitle        {\detokenizedconstructionparameter\c!title}%
1068       \xdef\currentconstructionbookmark     {\detokenizedconstructionparameter\c!bookmark}%
1069       \xdef\currentconstructionmarking      {\detokenizedconstructionparameter\c!marking}%
1070       \xdef\currentconstructionlist         {\detokenizedconstructionparameter\c!list}%
1071       \xdef\currentconstructionreferencetext{\detokenizedconstructionparameter\c!referencetext}%
1072       \iflocation \ifempty\currentconstructionbookmark
1073         \begingroup
1074         \simplifycommands
1075         \xdef\currentconstructionbookmark{\detokenize\expandafter{\normalexpanded{\constructionparameter\c!title}}}%
1076         \endgroup
1077       \fi \fi
1078     \fi
1079     \ifempty\currentconstructionlist
1080       \glet\currentconstructionlist\currentconstructiontitle
1081     \fi
1082     \glet\currentconstructioncoding\s!tex
1083   \fi
1084   %
1085   \ifx\currentconstructiontitle\v!none % will become obsolete
1086     \global\noconstructioncaptiontrue
1087   \fi
1088   %
1089   \ifnoconstructioncaption % then why analyze anyway?
1090     \endgroup
1091     \let\currentconstructionlistnumber \relax
1092     \let\currentconstructionsynchronize\relax
1093     \let\currentconstructionattribute  \relax
1094   \else
1095     \setnextinternalreferences{construction}\currentconstructionmain % plural
1096     \relax
1097     \scratchcounter\clf_addtolist
1098        metadata {
1099            kind     {construction}
1100            name     {\currentconstructionmain}
1101          % level    structures.sections.currentlevel()
1102            catcodes \catcodetable
1103        }
1104        references {
1105            internal  \locationcount
1106            order     \locationorder
1107            reference {\currentconstructionreference}
1108            prefix    {\currentconstructionreferenceprefix}
1109          % block     {\currentsectionblock}
1110          % section   structures.sections.currentid(),
1111        }
1112        titledata  {
1113            label     {\detokenize\expandafter{\currentconstructionlabel}}
1114            title     {\detokenize\expandafter{\currentconstructiontitle}}
1115        \ifx\currentconstructionbookmark\currentconstructiontitle \else
1116            bookmark  {\detokenize\expandafter{\currentconstructionbookmark}}
1117        \fi
1118        \ifx\currentconstructionreferencetext\currentconstructiontitle \else
1119            reference {\detokenize\expandafter{\currentconstructionreferencetext}}
1120        \fi
1121        \ifx\currentconstructionlist\currentconstructiontitle \else
1122            list      {\detokenize\expandafter{\currentconstructionlist}}
1123        \fi
1124        }
1125    \ifconditional\c_strc_constructions_number_state
1126        prefixdata {
1127            prefix        {\constructionparameter\c!prefix}
1128            separatorset  {\constructionparameter\c!prefixseparatorset}
1129            conversion    {\constructionparameter\c!prefixconversion}
1130            conversionset {\constructionparameter\c!prefixconversionset}
1131            set           {\constructionparameter\c!prefixset}
1132            segments      {\constructionparameter\c!prefixsegments}
1133            connector     {\constructionparameter\c!prefixconnector}
1134        }
1135        numberdata {
1136            numbers       {\currentconstructionnumber}
1137            separatorset  {\constructionparameter\c!numberseparatorset}
1138            conversion    {\constructionparameter\c!numberconversion}
1139            conversionset {\constructionparameter\c!numberconversionset}
1140            starter       {\constructionparameter\c!numberstarter}
1141            stopper       {\constructionparameter\c!numberstopper}
1142            segments      {\constructionparameter\c!numbersegments}
1143        }
1144    \or
1145       % symbol
1146    \fi
1147        userdata {\detokenize{#1}}
1148     \relax
1149   % \writestatus{constructions}{registering \currentconstruction: \number\scratchcounter}%
1150     \clf_setinternalreference
1151       prefix    {\currentconstructionreferenceprefix}%
1152       reference {\currentconstructionreference}%
1153       internal  \locationcount
1154       view      {\interactionparameter\c!focus}%
1155     \relax
1156     \normalexpanded {%
1157       \endgroup
1158       \edef\noexpand\currentconstructionlistentry  {\the\scratchcounter}%
1159       \edef\noexpand\currentconstructionattribute  {\the\lastdestinationattribute}%
1160       \edef\noexpand\currentconstructionsynchronize{\clf_deferredenhancelist\the\scratchcounter}%
1161     }%
1162   \fi}
1163
1164% This is not so nice, some day I'll just store the number with the entry
1165% and deal with all at the Lua end, but first we need to be able to set
1166% macros.
1167
1168\permanent\protected\def\reinstateconstructionnumberentry#1% was xdef
1169  {\edef\currentconstructionattribute  {\clf_getinternallistreference#1}%
1170   \edef\currentconstructionsynchronize{\clf_deferredenhancelist\number#1}}
1171
1172\permanent\protected\def\reinstatecachedconstructionnumberentry#1% was xdef | #1 = cached index can be different from real
1173  {\edef\currentconstructionattribute  {\clf_getinternalcachedlistreference#1}% destination
1174   \edef\currentconstructionsynchronize{\clf_deferredenhancelist\number#1}}
1175
1176\installstructurelistprocessor{construction}{\usestructurelistprocessor{number+title}}
1177
1178% Helpers:
1179
1180\def\currentconstructionnumber{\constructionparameter\s!counter}
1181
1182\protected\def\strc_constructions_next_indeed #get#tag#level{\strc_counters_increment_sub{#get{#tag}\s!counter}{#level}}
1183\protected\def\strc_constructions_reset_indeed#get#tag#level{\strc_counters_reset_sub    {#get{#tag}\s!counter}{#level}}
1184
1185\protect \endinput
1186