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