strc-con.mklx /size: 42 Kb    last modification: 2023-12-21 09:44
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\lettonothing\currentconstructionmain
109\mutable\lettonothing\currentconstructionlevel
110\mutable\lettonothing\currentconstructionhandler
111\mutable\lettonothing\currentconstructionattribute
112\mutable\lettonothing\currentconstructionbookmark
113\mutable\lettonothing\currentconstructioncatcodes
114\mutable\lettonothing\currentconstructioncoding
115\mutable\lettonothing\currentconstructionexpansion
116\mutable\lettonothing\currentconstructionincrementnumber
117\mutable\lettonothing\currentconstructionlabel
118\mutable\lettonothing\currentconstructionlist
119\mutable\lettonothing\currentconstructionlistentry
120\mutable\lettonothing\currentconstructionlistnumber
121\mutable\lettonothing\currentconstructionmarking
122\mutable\lettonothing\currentconstructionnumber
123\mutable\lettonothing\currentconstructionreference
124\mutable\lettonothing\currentconstructionreferencetext
125\mutable\lettonothing\currentconstructionreferenceprefix
126\mutable\lettonothing\currentconstructionsynchronize
127\mutable\lettonothing\currentconstructiontitle
128\mutable\lettonothing\currentconstructionxmlsetup
129
130\newconditional\c_strc_constructions_define_commands \c_strc_constructions_define_commands\conditionaltrue % use with care, might become a proper key
131
132\appendtoks
133    \ifempty\currentconstructionparent
134        \letcsname\??constructionmain\currentconstruction\endcsname\currentconstruction
135        \definelist[\currentconstruction]% goodie
136    \else
137        \letcsname\??constructionmain\currentconstruction\endcsname\currentconstructionparent
138        \definelist[\currentconstruction][\currentconstructionparent]% goodie
139    \fi
140    \edefcsname\??constructionlevel\currentconstruction\endcsname{\number\constructionparameter\c!level}%
141    \edefcsname\??constructionclass\currentconstruction\endcsname{\constructionparameter\s!handler}%
142    \expandafter\newconditional\csname\??constructionclosesymbol\currentconstruction\endcsname
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]#*[#S#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  {\cdef\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  {\c_strc_constructions_number_state\conditionalfalse
200   \c_strc_constructions_title_state\conditionalfalse}
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   \expand\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\lettonothing\p_strc_constructions_sample
300\lettonothing\p_strc_constructions_align
301\lettonothing\p_strc_constructions_indenting
302\lettonothing\p_strc_constructions_width
303\lettonothing\p_strc_constructions_aligntitle
304\lettonothing\p_strc_constructions_renderingsetup
305\lettonothing\p_strc_constructions_headalign
306\lettonothing\p_strc_constructions_hang
307\lettonothing\p_strc_constructions_inbetween
308\lettonothing\p_strc_constructions_closesymbol
309\lettonothing\p_strc_constructions_distance
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   \c_strc_constructions_distance_none\conditionaltrue}
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     \c_strc_constructions_distance_none\conditionaltrue
358     \constructionsheaddistance\zeropoint
359   \else
360     \c_strc_constructions_distance_none\conditionalfalse
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     {\scratchskip\parindent
403      \forgetall
404      \dontcomplain
405      % new and under testing
406      \ifcstok{\constructionparameter\c!headindenting}\v!yes
407        \hskip\scratchskip
408      \fi
409      %
410      \ifx\currentconstructionalternative\v!serried % brrr, hack, will change
411        \csname\??constructionmainhandler\currentconstructionhandler\endcsname\currentconstructiontext
412      \else
413        \csname\??constructionmainhandler\currentconstructionhandler\endcsname{\boxedconstructionhead\currentconstructiontext}%
414      \fi}%
415   \edef\p_strc_constructions_aligntitle{\constructionparameter\c!aligntitle}%
416   \ifx\p_strc_constructions_aligntitle\v!no
417     \leftconstructionskip \leftskip
418     \rightconstructionskip\rightskip
419   \orelse\ifcase\c_strc_constructions_nested_state
420     \leftconstructionskip \leftskip
421     \rightconstructionskip\rightskip
422   \fi
423   \edef\p_strc_constructions_align{\constructionparameter\c!align}%
424   \ifempty\p_strc_constructions_align \else
425     \setupalign[\p_strc_constructions_align]% \use...
426   \fi
427   \ifcase\c_strc_constructions_nested_state
428     \c_strc_constructions_nested_state\plusone
429   \or
430     \c_strc_constructions_nested_state\plustwo
431   \fi
432   \strc_constructions_close_symbol_reset
433   %
434   \edef\p_strc_constructions_headalign{\constructionparameter\c!headalign}%
435   %
436   \directsetup\p_strc_constructions_renderingsetup\relax
437   % moved to here 2014-07-03
438   \edef\p_strc_constructions_indenting{\constructionparameter\c!indenting}%
439   \ifempty\p_strc_constructions_indenting \else
440     \indenting[\p_strc_constructions_indenting]% \use...
441   \fi
442   %
443   \dostoptagged % tag
444   \dostarttagged\t!constructioncontent\empty
445  %\freezeparagraphproperties
446   \updateparagraphshapes
447   \ignorespaces} % args not needed
448
449\protected\defcsname\??constructionstophandler\v!construction\endcsname
450  {\strc_constructions_close_symbol_place
451   \ifcstok{\constructionparameter\c!display}\v!no\else
452     \par
453   \fi
454   \dostoptagged % content
455   \dostoptagged % construction
456   \endgroup
457   \constructionparameter\c!after
458   \useindentnextparameter\constructionparameter
459   \strc_constructions_finalize
460%   \endgroup
461   \dorechecknextindentation}
462
463\permanent\protected\def\boxedconstructionhead#1%
464  {\ifcstok{\constructionalternativeparameter\c!alignbottom}\v!yes \vbox \else \vtop \fi
465     \bgroup
466       \hsize\constructionsheadwidth
467       \edef\p_strc_constructions_headalign{\constructionparameter\c!headalign}%
468       \ifempty\p_strc_constructions_headalign \else
469         \setupalign[\p_strc_constructions_headalign]% \use...
470       \fi
471       #1%
472     \egroup}
473
474\installcorenamespace{constructionalternative}
475\installcorenamespace{constructionrenderings}
476
477% see lists: alternativemethods ... todo
478%
479% there will be a proper interface to variables
480
481\installcommandhandler \??constructionalternative {constructionalternative} \??constructionalternative
482
483\setupconstructionalternative
484  [%c!left=, % no inheritance
485   %c!right=,% no inheritance
486   \c!width=\constructionparameter\c!width,
487   \c!distance=\constructionparameter\c!distance,
488   \c!stretch=\constructionparameter\c!stretch,
489   \c!shrink=\constructionparameter\c!shrink]
490
491\defineconstructionalternative
492  [\v!left]
493  [%\c!width=7em,
494   %\c!distance=1em,
495   \c!renderingsetup=\??constructionrenderings:\v!left]
496
497\defineconstructionalternative
498  [\v!right]
499  [%\c!width=7em,
500   %\c!distance=1em,
501   \c!renderingsetup=\??constructionrenderings:\v!right]
502
503\defineconstructionalternative
504  [\v!inmargin]
505  [\c!renderingsetup=\??constructionrenderings:\v!inmargin]
506
507\defineconstructionalternative
508  [\v!inleft]
509  [\c!renderingsetup=\??constructionrenderings:\v!inleft]
510
511\defineconstructionalternative
512  [\v!inright]
513  [\c!renderingsetup=\??constructionrenderings:\v!inright]
514
515\defineconstructionalternative
516  [\v!margin]
517  [\c!renderingsetup=\??constructionrenderings:\v!margin]
518
519\defineconstructionalternative
520  [\v!leftmargin]
521  [\c!renderingsetup=\??constructionrenderings:\v!leftmargin]
522
523\defineconstructionalternative
524  [\v!rightmargin]
525  [\c!renderingsetup=\??constructionrenderings:\v!rightmargin]
526
527\defineconstructionalternative
528  [\v!innermargin]
529  [\c!renderingsetup=\??constructionrenderings:\v!innermargin]
530
531\defineconstructionalternative
532  [\v!outermargin]
533  [\c!renderingsetup=\??constructionrenderings:\v!outermargin]
534
535\defineconstructionalternative
536  [\v!serried]
537  [\c!renderingsetup=\??constructionrenderings:\v!serried]
538
539\defineconstructionalternative
540  [\v!hanging]
541  [%\c!width=.75\emwidth
542   \c!renderingsetup=\??constructionrenderings:\v!hanging]
543
544\defineconstructionalternative
545  [\v!top]
546  [\c!renderingsetup=\??constructionrenderings:\v!top,
547   \c!width=\localhsize]
548
549\defineconstructionalternative
550  [\v!command]
551  [\c!renderingsetup=\??constructionrenderings:\v!command]
552
553\defineconstructionalternative
554  [\v!empty]
555  [\c!renderingsetup=\??constructionrenderings:\v!empty]
556
557\defineconstructionalternative
558  [\v!label]
559  [\c!renderingsetup=\??constructionrenderings:\v!label,
560   \c!width=]
561
562\newbox      \constructionheadbox
563\newgluespec \leftconstructionskip
564\newgluespec \rightconstructionskip
565\newdimension\constructionsheadwidth
566\newdimension\constructionsheaddistance
567
568\def\strc_constructions_set_hang_box#1% messy left/rightskip
569  {\setbox\constructionheadbox\vtop   % \vbox gaat fout in hang
570     {\forgetall
571      \dontcomplain
572      \hsize\constructionsheadwidth\relax
573      \ifempty\p_strc_constructions_headalign
574        \setupalign[#1]% use fast one
575      \else
576        \setupalign[\p_strc_constructions_headalign]% use fast one
577      \fi
578      \ifconditional\c_strc_constructions_distance_none \else
579        \advanceby\ifx#1\v!flushleft\rightskip\else\leftskip\fi\constructionsheaddistance % only difference and wrong anyway
580      \fi
581      \flushconstructionheadbox}%
582   \setbox\constructionheadbox\hpack{\box\constructionheadbox}% needed in case of e.g. a real big head font, see descriptions-006.tex
583   \ht\constructionheadbox\strutht
584   \dp\constructionheadbox\strutdp}
585
586\def\strc_constructions_set_pure_box#1% default ... better set up differently
587  {\setbox\constructionheadbox\vtop
588     {\forgetall
589      \dontcomplain
590      \hsize\constructionsheadwidth\relax
591      \ifempty\p_strc_constructions_headalign
592        \setupalign[#1]% use fast one
593      \else
594        \setupalign[\p_strc_constructions_headalign]% use fast one
595      \fi
596      \flushconstructionheadbox}%
597   \setbox\constructionheadbox\hpack{\box\constructionheadbox}% needed in case of e.g. a real big head font, see descriptions-006.tex
598   \ht\constructionheadbox\strutht
599   \dp\constructionheadbox\strutdp}
600
601\def\strc_constructions_set_hang#1%
602  {\ifempty\p_strc_constructions_hang
603     % nothing
604   \orelse\ifx\p_strc_constructions_hang\v!fit
605     \scratchdimen\htdp\constructionheadbox
606     \getnoflines\scratchdimen
607     \hangafter-\noflines
608   \orelse\ifx\p_strc_constructions_hang\v!broad
609     \scratchdimen\dimexpr\htdp\constructionheadbox+.5\strutht\relax
610     \getnoflines\scratchdimen
611     \hangafter-\noflines
612   \else
613     \hangafter-\p_strc_constructions_hang
614   \fi
615   \relax
616   \hangindent\ifx#1\v!right-\fi\constructionsheadwidth}
617
618\permanent\protected\def\flushconstructionheadbox
619  {\ifhbox\constructionheadbox\unhbox\else\box\fi\constructionheadbox}
620
621% The setups. These only deal with placement of the descriptor and initializing the
622% environment. The wrapping happens elsewhere.
623
624% todo: optimize the setups with
625%
626% \ifconditional\c_strc_constructions_distance_none : no need for skip
627% \ifzeropt\wd\constructionheadbox : no need for box and skips
628
629\startsetups[\??constructionrenderings:\v!left]
630    \edef\p_strc_constructions_hang{\constructionparameter\c!hang}%
631    \doifelsesetups{\??constructionrenderings:\v!left:\p_strc_constructions_hang} {
632        \directsetup{\??constructionrenderings:\v!left:\p_strc_constructions_hang}
633    } {
634        \directsetup{\??constructionrenderings:\v!left:\v!hanging}
635    }
636\stopsetups
637
638\startsetups[\??constructionrenderings:\v!right]
639    \edef\p_strc_constructions_hang{\constructionparameter\c!hang}
640    \doifelsesetups{\??constructionrenderings:\v!right:\p_strc_constructions_hang} {
641        \directsetup{\??constructionrenderings:\v!right:\p_strc_constructions_hang}
642    } {
643        \directsetup{\??constructionrenderings:\v!right:\v!hanging}
644    }
645\stopsetups
646
647\startsetups[\??constructionrenderings:\v!left:\v!none]
648    \enforced\let\\\crlf
649    \noindent
650    \strc_constructions_set_pure_box\v!flushleft
651    \leftskip\dimexpr\leftconstructionskip+\constructionsheadwidth+\constructionsheaddistance\relax
652    \rightskip\rightconstructionskip\relax
653    \llap {
654        \hpack to \leftskip {
655            \hskip\leftconstructionskip
656            \box\constructionheadbox % was copy
657            \hss
658        }
659    }
660    \nobreak
661    \useconstructionstyleandcolor\c!style\c!color
662    \ignorespaces
663\stopsetups
664
665\startsetups[\??constructionrenderings:\v!left:0]
666    \directsetup{\??constructionrenderings:\v!left:\v!none}
667\stopsetups
668
669\startsetups[\??constructionrenderings:\v!left:]
670    \directsetup{\??constructionrenderings:\v!left:\v!none}
671\stopsetups
672
673\startsetups[\??constructionrenderings:\v!right:\v!none]
674    \enforced\let\\\crlf
675    \noindent
676    \leftskip\leftconstructionskip
677    \rightskip\dimexpr\rightconstructionskip+\constructionsheadwidth\relax
678   %\strc_constructions_pure_hang_box\raggedleft
679    \strc_constructions_set_pure_box\v!flushright
680    \rlap {
681        \hskip\dimexpr\hsize-\leftskip-\rightskip\relax
682        \copy\constructionheadbox
683        \hskip\rightconstructionskip
684    }
685    \nobreak
686    \advanceby\rightskip \constructionsheaddistance
687    \useconstructionstyleandcolor\c!style\c!color
688    \ignorespaces
689\stopsetups
690
691\startsetups[\??constructionrenderings:\v!right:0]
692    \directsetup{\??constructionrenderings:\v!right:\v!none}
693\stopsetups
694
695\startsetups[\??constructionrenderings:\v!right:]
696    \directsetup{\??constructionrenderings:\v!right:\v!none}
697\stopsetups
698
699\startsetups[\??constructionrenderings:\v!left:\v!margin]%
700    \enforced\let\\\crlf
701    \noindent
702    \strc_constructions_set_pure_box\v!flushleft
703    \llap {
704        \hpack to \constructionsheadwidth {
705            \box\constructionheadbox % was copy
706            \hss
707        }
708        \hskip\constructionsheaddistance
709    }
710    \useconstructionstyleandcolor\c!style\c!color
711    \ignorespaces
712\stopsetups
713
714\startsetups[\??constructionrenderings:\v!right:\v!margin]%
715    \enforced\let\\\crlf
716    \noindent
717    \strc_constructions_set_pure_box\v!flushright
718    \rlap {
719        \hskip\constructionsheaddistance
720        \hpack to \constructionsheadwidth {
721            \box\constructionheadbox % was copy
722            \hss
723        }
724    }
725    \useconstructionstyleandcolor\c!style\c!color
726    \ignorespaces
727\stopsetups
728
729\startsetups[\??constructionrenderings:\v!left:\v!hanging]%
730    \enforced\let\\\crlf
731    \dontcomplain
732    \advanceby\constructionsheadwidth \constructionsheaddistance
733    \strc_constructions_set_hang_box\v!flushleft
734    \strc_constructions_set_hang\v!left
735    \noindent
736    \llap {
737        \tpack to \zeropoint {
738            \box\constructionheadbox
739        }
740    }
741    \nobreak
742    \useconstructionstyleandcolor\c!style\c!color
743    \ignorespaces
744\stopsetups
745
746\startsetups[\??constructionrenderings:\v!right:\v!hanging]%
747    \enforced\let\\\crlf
748    \dontcomplain
749    \advanceby\constructionsheadwidth \constructionsheaddistance
750    \strc_constructions_set_hang_box\v!flushright
751    \strc_constructions_set_hang\v!right
752    \noindent
753    \rlap {
754        \hpack to \dimexpr\hsize-\leftskip-\rightskip\relax {
755            \hss
756            \tpack to \zeropoint {
757                \box\constructionheadbox
758            }
759        }
760    }
761    \nobreak
762    \useconstructionstyleandcolor\c!style\c!color
763    \ignorespaces
764\stopsetups
765
766\startsetups[\??constructionrenderings:\v!top]
767  % \strc_sectioning_prevent_page_break % commented per 31/5/2019
768    \enforced\let\\\space
769    \noindent
770    \copy\constructionheadbox % why copy ?
771    \par
772    \nobreak
773    \edef\p_strc_constructions_inbetween{\constructionparameter\c!inbetween}%
774    \ifempty\p_strc_constructions_inbetween \else
775      \p_strc_constructions_inbetween
776      % shouldn't this move to after the fi?
777      \directcheckedvspacing\v!samepage
778    \fi
779    \useconstructionstyleandcolor\c!style\c!color
780    \ignorespaces
781\stopsetups
782
783% why copy? historic reason?
784
785\startsetups[\??constructionrenderings:\v!margin]
786    \enforced\let\\\crlf
787    \noindent
788    \inmargin[\c!scope=\v!local]{\flushconstructionheadbox}%
789    \useconstructionstyleandcolor\c!style\c!color
790    \ignorespaces
791\stopsetups
792
793\startsetups[\??constructionrenderings:\v!leftmargin]
794    \enforced\let\\\crlf
795    \noindent
796    \inleft[\c!scope=\v!local]{\flushconstructionheadbox}%
797    \useconstructionstyleandcolor\c!style\c!color
798    \ignorespaces
799\stopsetups
800
801\startsetups[\??constructionrenderings:\v!rightmargin]
802    \enforced\let\\\crlf
803    \noindent
804    \inright[\c!scope=\v!local]{\flushconstructionheadbox}%
805    \useconstructionstyleandcolor\c!style\c!color
806    \ignorespaces
807\stopsetups
808
809\startsetups[\??constructionrenderings:\v!innermargin]
810    \enforced\let\\\crlf
811    \noindent
812    \ininner[\c!scope=\v!local]{\flushconstructionheadbox}%
813    \useconstructionstyleandcolor\c!style\c!color
814    \ignorespaces
815\stopsetups
816
817\startsetups[\??constructionrenderings:\v!outermargin]
818    \enforced\let\\\crlf
819    \noindent
820    \inouter[\c!scope=\v!local]{\flushconstructionheadbox}%
821    \useconstructionstyleandcolor\c!style\c!color
822    \ignorespaces
823\stopsetups
824
825\startsetups[\??constructionrenderings:\v!inmargin]
826    \directsetup{\??constructionrenderings:\v!margin}
827\stopsetups
828
829\startsetups[\??constructionrenderings:\v!inleft]
830    \directsetup{\??constructionrenderings:\v!leftmargin}
831\stopsetups
832
833\startsetups[\??constructionrenderings:\v!inright]
834    \directsetup{\??constructionrenderings:\v!rightmargin}
835\stopsetups
836
837\startsetups[\??constructionrenderings:\v!serried]
838    % already set?
839    \edef\p_strc_constructions_width{\constructionparameter\c!width}% CHECK ! ! ! wrong parameter namespace
840    \doifelsesetups{\??constructionrenderings:\v!serried:\p_strc_constructions_width} {
841        \directsetup{\??constructionrenderings:\v!serried:\p_strc_constructions_width}
842    } {
843        \directsetup{\??constructionrenderings:\v!serried:\v!wide}
844    }
845\stopsetups
846
847\startsetups[\??constructionrenderings:\v!serried:\v!fit]
848    \enforced\let\\\crlf
849    \noindent
850    \flushconstructionheadbox
851    \nobreak
852    \hskip\constructionsheaddistance\relax
853    \useconstructionstyleandcolor\c!style\c!color
854    \ignorespaces
855\stopsetups
856
857\startsetups[\??constructionrenderings:\v!serried:\v!broad]
858    \enforced\let\\\crlf
859    \noindent
860    \flushconstructionheadbox
861    \ifconditional\c_strc_constructions_distance_none \else
862        \nobreak
863        \hskip\constructionsheaddistance
864          \s!plus \constructionalternativeparameter\c!stretch\constructionsheaddistance
865          \s!minus\constructionalternativeparameter\c!shrink \constructionsheaddistance
866        \relax
867    \fi
868    \useconstructionstyleandcolor\c!style\c!color
869    \ignorespaces
870\stopsetups
871
872\startsetups[\??constructionrenderings:\v!serried:]
873    \directsetup{\??constructionrenderings:\v!serried:\v!broad}
874\stopsetups
875
876\startsetups[\??constructionrenderings:\v!serried:\v!wide]
877    \enforced\let\\\crlf
878    \noindent
879    \hbox to \constructionsheadwidth {
880        \flushconstructionheadbox
881        \hss
882    }
883    \nobreak
884    \hskip\constructionsheaddistance\relax
885    \useconstructionstyleandcolor\c!style\c!color
886    \ignorespaces
887\stopsetups
888
889\startsetups[\??constructionrenderings:\v!hanging]
890    % tricky: leftskipadaption is somewhat unpredictable
891    \enforced\let\\\crlf
892    \noindent
893    \advanceby\leftskip-\leftskipadaption\relax
894    \ifdim\leftskipadaption=\zeropoint
895        \leftskipadaption1.5\emwidth\relax % just some default
896        \ifnum\c_strc_constructions_nested_state=\plusone
897            \ifdim\leftskip>\zeropoint \relax
898                \leftskipadaption\leftskip
899            \fi
900        \fi
901    \fi
902    \ifnum\c_strc_constructions_nested_state>\zerocount % was \ifnum\c_strc_constructions_nested_state=\plusone
903        \advanceby\leftskip\leftskipadaption % but we're already further on
904    \fi
905    \hskip-\leftskipadaption\relax
906    \ifhbox\constructionheadbox \unhbox\else\box\fi\constructionheadbox
907    \ifconditional\c_strc_constructions_distance_none \else
908      % we used to have just a kern, but long lines look bad then
909      \scratchdistance\ifdim\constructionsheaddistance=\zeropoint .75\emwidth\else\constructionsheaddistance\fi
910      \hskip \scratchdistance
911        \s!plus \constructionalternativeparameter\c!stretch\scratchdistance
912        \s!minus\constructionalternativeparameter\c!shrink \scratchdistance
913    \fi
914    \ifhmode
915        \ifx\p_strc_constructions_width\v!line
916            \hfill\break
917        \else
918            \allowbreak
919        \fi
920    \fi
921    \useconstructionstyleandcolor\c!style\c!color
922    \ignorespaces
923\stopsetups
924
925%D \starttyping
926%D \setupfootnotation[location=command,headcommand=\llap]
927%D \stoptyping
928
929\startsetups[\??constructionrenderings:\v!command]
930    \noindent
931    \constructionparameter\c!headcommand{\flushconstructionheadbox}
932    \useconstructionstyleandcolor\c!style\c!color
933    \ignorespaces
934\stopsetups
935
936\startsetups[\??constructionrenderings:\v!empty]
937    \noindent
938    \useconstructionstyleandcolor\c!style\c!color
939    \ignorespaces
940\stopsetups
941
942\startsetups[\??constructionrenderings:\v!label]
943    \dontleavehmode
944    \begingroup
945    \constructionparameter\c!headcommand{\flushconstructionheadbox}
946    \endgroup
947\stopsetups
948
949% \definedescription[whatever][alternative=right:bottom]
950%
951% \startwhatever{just a small\\example}
952%     \input ward
953% \stopwhatever
954
955\defineconstructionalternative
956  [\v!right:\v!bottom]
957  [%\c!width=7em,
958   %\c!distance=1em,
959   \c!alignbottom=\v!yes,
960   \c!renderingsetup=\??constructionrenderings:\v!right:\v!bottom]
961
962\startsetups[\??constructionrenderings:\v!right:\v!bottom]
963    \enforced\let\\\crlf
964    \noindent
965    \leftskip\leftconstructionskip
966    \rightskip\dimexpr\rightconstructionskip+\constructionsheadwidth+\constructionsheaddistance\relax
967    \parfillskip\zeroskip
968    \strc_constructions_set_pure_box\v!flushright
969    \directparwrapper \relax {%
970      \hfilll
971      \rlap
972        {\kern\constructionsheaddistance
973         \copy\constructionheadbox}%
974    }%
975    \useconstructionstyleandcolor\c!style\c!color
976    \ignorespaces
977\stopsetups
978
979%D This next feature will get an lmtx implementation (probably by using a new generic
980%D close mechanism).
981
982% you can use \placeclosesymbol or \qed to place a symbol at the end of a
983% construction
984
985\installcorenamespace{constructionclosesymbol}
986
987\mutable\let\placeclosesymbol\donothing
988\mutable\let\qed             \donothing
989
990\def\strc_constructions_close_symbol_reset % no need for global
991  {\global\csname\??constructionclosesymbol\currentconstruction\endcsname\conditionaltrue
992   \let\placeclosesymbol\strc_constructions_close_symbol_place
993   \let\qed             \strc_constructions_close_symbol_place}
994
995\protected\def\strc_constructions_close_symbol_place
996  {\ifconditional\csname\??constructionclosesymbol\currentconstruction\endcsname
997     \global\csname\??constructionclosesymbol\currentconstruction\endcsname\conditionalfalse
998     \edef\p_strc_constructions_closesymbol{\constructionparameter\c!closesymbol}%
999     \ifempty\p_strc_constructions_closesymbol \else
1000       \constructionparameter\c!closecommand{\p_strc_constructions_closesymbol}% hm why {} maybe because box expected
1001     \fi
1002   \fi}
1003
1004\newif\ifnoconstructioncaption
1005
1006%D The storage macros:
1007
1008\mutable\let\currentconstructionlistentry\!!zerocount
1009
1010\protected\def\strc_constructions_register
1011  {\clf_doifelselisthasentry\numexpr\currentconstructionlistentry\relax
1012     \strc_constructions_register_nop
1013     \strc_constructions_register_yes}
1014
1015% \def\strc_constructions_register{\strc_constructions_register_yes}
1016
1017\def\strc_constructions_register_nop[#S#1][#S#2]% #1=optional user data #2=interfaced-settings
1018 %{\writestatus{constructions}{reusing \currentconstruction: \number\currentconstructionlistentry}}
1019  {}
1020
1021\def\strc_constructions_discard
1022  {\iftrialtypesetting
1023   % \writestatus{constructions}{discarding \currentconstruction: \number\currentconstructionlistentry}%
1024     \clf_discardfromlist\currentconstructionlistentry\relax
1025   \fi}
1026
1027\let\currentconstructionlistnumber \!!zerocount
1028\let\currentconstructionsynchronize\relax
1029\let\currentconstructionattribute  \attributeunsetvalue
1030
1031\def\strc_constructions_register_yes[#S#1][#S#2]% #1=optional user data #2=interfaced-settings
1032  {\begingroup                              % similar to structure so we might generalize this
1033   \setupcurrentconstruction[#2]%           % xdef's will become edef's
1034   \xdef\currentconstructionexpansion      {\constructionparameter\c!expansion}%
1035   \xdef\currentconstructionxmlsetup       {\constructionparameter\c!xmlsetup}%
1036   \xdef\currentconstructioncatcodes       {\constructionparameter\s!catcodes}%
1037   \xdef\currentconstructionlabel          {\constructionparameter\c!label}%
1038   \xdef\currentconstructionreference      {\constructionparameter\c!reference}%
1039   \xdef\currentconstructionreferencetext  {\constructionparameter\c!referencetext}%
1040   \xdef\currentconstructionreferenceprefix{\constructionparameter\c!referenceprefix}%
1041   %xdef\currentconstructionshownumber     {\constructionparameter\c!number}%
1042   \xdef\currentconstructionincrementnumber{\constructionparameter\c!incrementnumber}%
1043   %
1044   \ifempty\currentconstructionexpansion
1045     \glet\currentconstructionexpansion\v!no
1046   \fi
1047   %
1048   \ifempty\currentconstructionreferenceprefix
1049     \glet\currentconstructionreferenceprefix\referenceprefix
1050   \fi
1051   \ifx\currentconstructionexpansion\s!xml
1052     \xmlstartraw
1053       \xdef\currentconstructiontitle        {\constructionparameter\c!title}%
1054       \xdef\currentconstructionbookmark     {\constructionparameter\c!bookmark}%
1055       \xdef\currentconstructionmarking      {\constructionparameter\c!marking}%
1056       \xdef\currentconstructionlist         {\constructionparameter\c!list}%
1057       \xdef\currentconstructionreferencetext{\constructionparameter\c!referencetext}%
1058     \xmlstopraw
1059     \ifempty\currentconstructionlist
1060       \glet\currentconstructionlist\currentconstructiontitle
1061     \fi
1062     \glet\currentconstructioncoding\s!xml
1063   \else
1064     \ifx\currentconstructionexpansion\v!yes
1065       \xdef\currentconstructiontitle        {\constructionparameter\c!title}%
1066       \xdef\currentconstructionbookmark     {\constructionparameter\c!bookmark}%
1067       \xdef\currentconstructionmarking      {\constructionparameter\c!marking}%
1068       \xdef\currentconstructionlist         {\constructionparameter\c!list}%
1069       \xdef\currentconstructionreferencetext{\constructionparameter\c!referencetext}%
1070     \else
1071       \xdef\currentconstructiontitle        {\detokenizedconstructionparameter\c!title}%
1072       \xdef\currentconstructionbookmark     {\detokenizedconstructionparameter\c!bookmark}%
1073       \xdef\currentconstructionmarking      {\detokenizedconstructionparameter\c!marking}%
1074       \xdef\currentconstructionlist         {\detokenizedconstructionparameter\c!list}%
1075       \xdef\currentconstructionreferencetext{\detokenizedconstructionparameter\c!referencetext}%
1076       \iflocation \ifempty\currentconstructionbookmark
1077         \begingroup
1078         \simplifycommands
1079         \xdef\currentconstructionbookmark{\detokenize\expandafter{\normalexpanded{\constructionparameter\c!title}}}%
1080         \endgroup
1081       \fi \fi
1082     \fi
1083     \ifempty\currentconstructionlist
1084       \glet\currentconstructionlist\currentconstructiontitle
1085     \fi
1086     \glet\currentconstructioncoding\s!tex
1087   \fi
1088   %
1089   \ifx\currentconstructiontitle\v!none % will become obsolete
1090     \global\noconstructioncaptiontrue
1091   \fi
1092   %
1093   \ifnoconstructioncaption % then why analyze anyway?
1094     \endgroup
1095     \let\currentconstructionlistnumber \relax
1096     \let\currentconstructionsynchronize\relax
1097     \let\currentconstructionattribute  \relax
1098   \else
1099     \setnextinternalreferences{construction}\currentconstructionmain % plural
1100     \relax
1101     \scratchcounter\clf_addtolist
1102        metadata {
1103            kind     {construction}
1104            name     {\currentconstructionmain}
1105          % level    structures.sections.currentlevel()
1106            catcodes \catcodetable
1107        }
1108        references {
1109            internal  \locationcount
1110            order     \locationorder
1111            reference {\currentconstructionreference}
1112            prefix    {\currentconstructionreferenceprefix}
1113          % block     {\currentsectionblock}
1114          % section   structures.sections.currentid(),
1115        }
1116        titledata  {
1117            label     {\detokenize\expandafter{\currentconstructionlabel}}
1118            title     {\detokenize\expandafter{\currentconstructiontitle}}
1119        \ifx\currentconstructionbookmark\currentconstructiontitle \else
1120            bookmark  {\detokenize\expandafter{\currentconstructionbookmark}}
1121        \fi
1122        \ifx\currentconstructionreferencetext\currentconstructiontitle \else
1123            reference {\detokenize\expandafter{\currentconstructionreferencetext}}
1124        \fi
1125        \ifx\currentconstructionlist\currentconstructiontitle \else
1126            list      {\detokenize\expandafter{\currentconstructionlist}}
1127        \fi
1128        }
1129    \ifconditional\c_strc_constructions_number_state
1130        prefixdata {
1131            prefix        {\constructionparameter\c!prefix}
1132            separatorset  {\constructionparameter\c!prefixseparatorset}
1133            conversion    {\constructionparameter\c!prefixconversion}
1134            conversionset {\constructionparameter\c!prefixconversionset}
1135            set           {\constructionparameter\c!prefixset}
1136            segments      {\constructionparameter\c!prefixsegments}
1137            connector     {\constructionparameter\c!prefixconnector}
1138        }
1139        numberdata {
1140            numbers       {\currentconstructionnumber}
1141            separatorset  {\constructionparameter\c!numberseparatorset}
1142            conversion    {\constructionparameter\c!numberconversion}
1143            conversionset {\constructionparameter\c!numberconversionset}
1144            starter       {\constructionparameter\c!numberstarter}
1145            stopper       {\constructionparameter\c!numberstopper}
1146            segments      {\constructionparameter\c!numbersegments}
1147        }
1148    \or
1149       % symbol
1150    \fi
1151        userdata {\detokenize{#1}}
1152     \relax
1153   % \writestatus{constructions}{registering \currentconstruction: \number\scratchcounter}%
1154     \clf_setinternalreference
1155       prefix    {\currentconstructionreferenceprefix}%
1156       reference {\currentconstructionreference}%
1157       internal  \locationcount
1158       view      {\interactionparameter\c!focus}%
1159     \relax
1160     \normalexpanded {%
1161       \endgroup
1162       \edef\noexpand\currentconstructionlistentry  {\the\scratchcounter}%
1163       \edef\noexpand\currentconstructionattribute  {\the\lastdestinationattribute}%
1164       \edef\noexpand\currentconstructionsynchronize{\clf_deferredenhancelist\the\scratchcounter}%
1165     }%
1166   \fi}
1167
1168% This is not so nice, some day I'll just store the number with the entry
1169% and deal with all at the Lua end, but first we need to be able to set
1170% macros.
1171
1172\permanent\protected\def\reinstateconstructionnumberentry#1% was xdef
1173  {\edef\currentconstructionattribute  {\clf_getinternallistreference#1}%
1174   \edef\currentconstructionsynchronize{\clf_deferredenhancelist\number#1}}
1175
1176\permanent\protected\def\reinstatecachedconstructionnumberentry#1% was xdef | #1 = cached index can be different from real
1177  {\edef\currentconstructionattribute  {\clf_getinternalcachedlistreference#1}% destination
1178   \edef\currentconstructionsynchronize{\clf_deferredenhancelist\number#1}}
1179
1180\installstructurelistprocessor{construction}{\usestructurelistprocessor{number+title}}
1181
1182% Helpers:
1183
1184\def\currentconstructionnumber{\constructionparameter\s!counter}
1185
1186\protected\def\strc_constructions_next_indeed #get#tag#level{\strc_counters_increment_sub{#get{#tag}\s!counter}{#level}}
1187\protected\def\strc_constructions_reset_indeed#get#tag#level{\strc_counters_reset_sub    {#get{#tag}\s!counter}{#level}}
1188
1189\protect \endinput
1190