context-2020-concepts.tex /size: 17 Kb    last modification: 2021-10-28 13:50
1% language=us
2
3\usemodule[present-boring,abbreviations-logos]
4
5% This was a talk about a preliminary mechanism so it has been adapted to run in
6% the current version. I need to check other 2020 files and examples and will do
7% that when I update (especially the low level) manuals. Let me know when there
8% are issues.
9
10\startdocument
11  [title={CONCEPTS},
12   banner={experiments turned features},
13   location={context\enspace {\bf 2020}\enspace meeting}]
14
15% see datatypes, hyphenation etc
16
17\starttitle[title=Experiments]
18
19There have been quite some experiments. Some results were rejected, some kept.
20Here are a few (that come to mind). This talk is a mix of summary, discussion and
21some demos.
22
23\stoptitle
24
25\starttitle[title=Math]
26
27There are a couple of additional features in the math engine. Most concern a bit
28more control over hard coded behavior, but some are sort of new:
29
30\startbuffer
31test $a = b \discretionary class 3 {$<$}{$>$}{$\neq$}  c$ test
32\stopbuffer
33
34\typebuffer
35
36When there is enough room this will give
37
38\getbuffer
39
40When \type {\hsize} is limited we get:
41
42{\hsize 4mm \getbuffer}
43
44\page
45
46\enabletrackers[math.toysymbol]
47
48\definemathtoysymbol[Plus] [bin][+]
49\definemathtoysymbol[Minus][bin][-]
50\definemathtoysymbol[Equal][rel][=]
51
52\start
53
54\let\darkblue\darkyellow %\showmakeup[glue]
55
56$\dorecurse{199} {
57    x_{#1} \ifodd#1\relax\Plus\else\Minus\fi
58} x_{200} \Equal n$
59
60\dorecurse{10} {
61    test \discretionary
62        {\darkred   hel  $\sqrt{y}$ lo}
63        {\darkgreen good $\sqrt{z}$ bye}
64        {\darkblue  wel  $\sqrt{x}$ come} test
65}
66
67\dorecurse{10} {test #1
68    $x + 2x \discretionary class 2
69        {$+ \, \cdots $}
70        {$     \cdots \, +$}
71        {$+ \, \cdots \, +$} nx$ test
72}
73
74\stop
75
76\stoptitle
77
78\starttitle[title=More math]
79
80In traditional \TEX\ the last setting wins:
81
82\startbuffer
83\def\whatevera
84  {\Umathordrelspacing \textstyle=50mu
85   \Umathopenbinspacing\textstyle=50mu}
86
87\def\whateverb
88  {\Umathordrelspacing \textstyle=25mu
89   \Umathopenbinspacing\textstyle=25mu}
90
91$\whatevera a = (-2)$ \par
92$\whateverb a = (-2)$ \par
93$\whatevera a = (-2) \quad \whateverb a = (-2)$ \par
94\stopbuffer
95
96\typebuffer \startpacked \getbuffer \stoppacked
97
98\page
99
100In \LUAMETATEX\ we can freeze settings on the spot:
101
102\startbuffer
103\def\whatevera
104  {\frozen\Umathordrelspacing \textstyle=50mu
105   \frozen\Umathopenbinspacing\textstyle=50mu}
106
107\def\whateverb
108  {\frozen\Umathordrelspacing \textstyle=25mu
109   \frozen\Umathopenbinspacing\textstyle=25mu}
110
111$\whatevera a = (-2)$ \par
112$\whateverb a = (-2)$ \par
113$\whatevera a = (-2) \quad \whateverb a = (-2)$ \par
114\stopbuffer
115
116\typebuffer \startpacked \getbuffer \stoppacked
117
118{\em We can now also enable and disable specific features in the engine that
119control traditional or \OPENTYPE\ approaches. This is only there for experimental
120and educational purposes.}
121
122\stoptitle
123
124\starttitle[title=Macros]
125
126Not storing arguments:
127
128\starttyping
129\def\foo#1#0#3{....}
130
131\foo{11}{22}{33}
132
133\foo #1#0#3->....
134#1<-11
135#2<-
136#3<-33
137\stoptyping
138
139Ignoring arguments:
140
141\starttyping
142\def\foo#1#-#2{#1#2}
143
144\foo{1}{2}{3}
145
14613
147\stoptyping
148
149\page
150
151Normal behaviour:
152
153\starttyping
154\def\foo#1#2#3{#1#2#3}
155
156\foo{1}{{2}}{3}
157
158\foo #1#2#3->#1#2#3
159#1<-1
160#2<-{2}
161#3<-3
162\stoptyping
163
164Special behaviour:
165
166\starttyping
167\def\foo#1#+#3{#1#2#3}
168
169\foo #1#2#3->#1#2#3
170#1<-1
171#2<-{{2}}
172#3<-3
173\stoptyping
174
175{\em There are more specifiers and I admit that they are hard to remember. But
176they are mostly used in low level macros anyway.}
177
178\page
179
180Optional tokens (we also show some \TEX-expansion-horror here):
181
182\starttyping
183\edef\a!space{\expandtoken \ignorecatcode \spaceasciicode}
184
185\normalexpanded {
186
187    \protected \def \noexpand \doifelseinset#1#2%
188      {\noexpand\ifhasxtoks{,\a!space#1,}{,#2,}%
189         \noexpand\expandafter\noexpand\firstoftwoarguments
190       \noexpand\else
191         \noexpand\expandafter\noexpand\secondoftwoarguments
192       \noexpand\fi}
193
194}
195\stoptyping
196
197or as tokens (\type{\showluatokens\doifelseinset}) on the next page:
198
199{\em There are some expansion related extensions that are discussed in the low
200level expansion manual.}
201
202\page
203
204\starttyping
205591504   13    1  argument
206643771   13    2  argument
207595596   14    0  end match
208633535  120   48  if test       ifhasxtoks
209643789    1  123  left brace
210643793   12   44  other char
211643741    9   32  ignore
212185919    5    1  parameter
213633495   12   44  other char
214 57752    2  125  right brace
215167619    1  123  left brace
216643686   12   44  other char
217228803    5    2  parameter
218643434   12   44  other char
219643792    2  125  right brace
220643788  114    0  expand after  expandafter
221643775  125    0  call          firstoftwoarguments
222590609  120    3  if test       else
223643628  114    0  expand after  expandafter
224643754  125    0  call          secondoftwoarguments
225643763  120    2  if test       fi
226\stoptyping
227
228\page
229
230Cheating with arguments:
231
232\startbuffer
233\def\foo#1=#2,{(#1/#2)}
234
235\foo 1=2,\ignorearguments
236\foo 1=2\ignorearguments
237\foo 1\ignorearguments
238\foo \ignorearguments
239\stopbuffer
240
241\typebuffer
242
243\getbuffer
244
245As in:
246
247\startbuffer
248\def\foo#1=#2,{\ifarguments\or(#1)\or(#1/#2)\fi}
249
250\foo 1=2,\ignorearguments
251\foo 1=2\ignorearguments
252\foo 1\ignorearguments
253\foo \ignorearguments
254\stopbuffer
255
256\typebuffer
257
258\getbuffer
259
260\stoptitle
261
262\starttitle[title=Hyphenation]
263
264Hyphenation at work:
265
266\startlinecorrection[line] \small
267\startcombination[distance=3cm,nx=6]
268    {\vtop{\hsize 2mm \strut NEDERLANDS\vskip.5\lineheight}} {\type{NEDERLANDS}}
269    {\vtop{\hsize 2mm \strut Nederlands\vskip.5\lineheight}} {\type{Nederlands}}
270    {\vtop{\hsize 2mm \strut nederlands\vskip.5\lineheight}} {\type{nederlands}}
271    {\vtop{\hsize 2mm \strut \CONTEXT  \vskip.5\lineheight}} {\type{\CONTEXT  }}
272    {\vtop{\hsize 2mm \strut text\-test\vskip.5\lineheight}} {\type{text\-test}}
273    {\vtop{\hsize 2mm \strut test-test \vskip.5\lineheight}} {\type{test-test }}
274\stopcombination
275\stoplinecorrection
276
277Controlling hyphenation:
278
279\startbuffer[1]
280\nohyphens NEDERLANDS {\dohyphens Nederlands} nederlands
281\stopbuffer
282
283\startbuffer[2]
284NEDERLANDS {\nohyphens Nederlands} nederlands
285\stopbuffer
286
287\typebuffer[1] and \typebuffer[2]
288
289\startlinecorrection[line]
290\startcombination[distance=4cm,nx=2]
291    {\small \small \vtop{\hsize 2mm \strut \nl \getbuffer[1]}} {}
292    {\small \small \vtop{\hsize 2mm \strut \nl \getbuffer[2]}} {}
293\stopcombination
294\stoplinecorrection
295
296\page
297
298There are several ways to implement this:
299
300\startitemize
301\startitem choose a language with no patterns:
302    \startitemize[packed]
303        \startitem it's quite efficient \stopitem
304        \startitem we loose language specifics \stopitem
305    \stopitemize
306\stopitem
307\startitem set the left and right hyphen min values high:
308    \startitemize[packed]
309        \startitem it works okay \stopitem
310        \startitem it is a hack \stopitem
311        \startitem we still enter the routine \stopitem
312    \stopitemize
313\stopitem
314\startitem block the mechanism:
315    \startitemize[packed]
316        \startitem it provides detailed control \stopitem
317        \startitem it is conceptually clean \stopitem
318    \stopitemize
319\stopitem
320\stopitemize
321
322The last method is what we use in \LMTX:
323
324\type {\dohyphens} : {\tttf \meaning\dohyphens}
325
326\type {\nohyphens} : {\tttf \meaning\nohyphens}
327
328\page
329
330For the moment we have this (it might evolve):
331
332\starttyping[style=\tt\small\small]
333\chardef \completehyphenationmodecode \numexpr
334    \normalhyphenationmodecode            % \discretionary
335  + \automatichyphenationmodecode         % -
336  + \explicithyphenationmodecode          % \-
337  + \syllablehyphenationmodecode          % pattern driven
338  + \uppercasehyphenationmodecode         % replaces \uchyph
339  + \compoundhyphenationmodecode          % replaces \compoundhyphenmode
340  % \strictstarthyphenationmodecode       % replaces \hyphenationbounds (strict = original tex)
341  % \strictendhyphenationmodecode         % replaces \hyphenationbounds (strict = original tex)
342  + \automaticpenaltyhyphenationmodecode  % replaces \hyphenpenaltymode (otherwise use \exhyphenpenalty)
343  + \explicitpenaltyhyphenationmodecode   % replaces \hyphenpenaltymode (otherwise use \exhyphenpenalty)
344  + \permitgluehyphenationmodecode        % turn glue into kern in \discretionary
345  + \permitallhyphenationmodecode         % okay, let's be even more tolerant
346  + \permitmathreplacehyphenationmodecode % and again we're more permissive
347\relax
348\stoptyping
349
350This replaces some \LUATEX\ mode variables and adds some more which is why we now use
351a bitset instead of multiple parameters.
352
353\page
354
355In addition we have more detailed discretionary control:
356
357\startbuffer
358nederlands\discretionary           {!}{!}{!}nederlands
359nederlands\discretionary options 1 {!}{!}{!}nederlands
360nederlands\discretionary options 2 {!}{!}{!}nederlands
361nederlands\discretionary options 3 {!}{!}{!}nederlands
362\stopbuffer
363
364\typebuffer
365
366\startlinecorrection[line]
367\startcombination[distance=4cm,nx=4]
368    {\vtop{\hsize 1mm \strut \nl nederlands\discretionary           {!}{!}{!}nederlands}} {}
369    {\vtop{\hsize 1mm \strut \nl nederlands\discretionary options 1 {!}{!}{!}nederlands}} {}
370    {\vtop{\hsize 1mm \strut \nl nederlands\discretionary options 2 {!}{!}{!}nederlands}} {}
371    {\vtop{\hsize 1mm \strut \nl nederlands\discretionary options 3 {!}{!}{!}nederlands}} {}
372\stopcombination
373\stoplinecorrection
374
375At some point it will become \quote {frozen} functionality and that's when it gets
376documented (first we need to integrate and play a bit more with it in \CONTEXT).
377
378{\em There is now a plugin mechanism that provides more control over language
379specific hyphenation, e.g.\ compound words combined with ligatures.}
380
381\stoptitle
382
383\starttitle[title=Local control]
384
385In \LUATEX\ we have experimental (kind of ugly) immediate assignments that can be
386used in expansions without blocking (resulting in tokens that is).
387
388But now we now have local control:
389
390\startbuffer
391\newcount\foocounter
392
393\def\foo
394  {\advance\foocounter\plusone
395   \the\foocounter}
396
397\edef\oof{(\foo)(\foo)(\foo)(\foo)}
398
399\meaning\oof
400\stopbuffer
401
402\typebuffer
403
404{\tttf \nohyphens \veryraggedright \getbuffer}
405
406\page
407
408Immediate expansion:
409
410\startbuffer
411\def\foo
412  {\beginlocalcontrol
413     \advance\foocounter\plusone
414   \endlocalcontrol
415   \the\foocounter}
416
417\edef\oof{(\foo)(\foo)(\foo)(\foo)}
418
419\meaning\oof
420\stopbuffer
421
422\typebuffer
423
424{\tttf \getbuffer}
425
426Hidden assignments:
427
428\startbuffer
429\scratchcounterone \beginlocalcontrol
430    \scratchcountertwo 100
431    \multiply \scratchcountertwo by 4
432\endlocalcontrol \scratchcountertwo
433\the\scratchcounterone
434\stopbuffer
435
436\typebuffer
437
438{\tttf \getbuffer}
439
440% \the \beginlocalcontrol
441%     \scratchcountertwo 100
442%     \multiply \scratchcountertwo by 4
443% \endlocalcontrol \scratchcountertwo
444
445\page
446
447Fancy expansion:
448
449\startbuffer
450\protected\def\foo
451  {\beginlocalcontrol
452     \advance\foocounter\plusone
453   \endlocalcontrol
454   \the\foocounter}
455
456\edef\oof{(\foo)(\foo)(\foo)(\foo)}
457\edef\ofo{(\expand\foo)(\expand\foo)(\expand\foo)(\expand\foo)}
458
459\meaning\oof \par \meaning\ofo
460\stopbuffer
461
462\typebuffer
463
464{\tttf \getbuffer}
465
466And a teaser:
467
468\starttyping
469\protected\def\widthofcontent#1{\beginlocalcontrol
470     \setbox\scratchbox\hbox{#1}\endlocalcontrol \wd\scratchbox}
471\stoptyping
472
473{\em These mechanisms can have surprising side effects due to input stacking.
474There is some more info in the low level expansion manual.}
475
476\stoptitle
477
478\starttitle[title=Conditionals]
479
480We can get nicer code that this:
481
482\starttyping
483\ifdim\scratchdimen=10pt
484   \expandafter\one
485\else\ifnum\scratchcounter=20
486   \expandafter\expandafter\expandafter\two
487\else
488   \expandafter\expandafter\expandafter\three
489\fi\fi
490\stoptyping
491
492This becomes:
493
494\starttyping
495\ifdim\scratchdimen=10pt
496   \expandafter\one
497\orelse\ifnum\scratchcounter=20
498   \expandafter\two
499\else
500   \expandafter\three
501\fi
502\stoptyping
503
504\page
505
506There is a bunch of extra conditions like the generic:
507
508\startnarrower \type {\ifcondition} \stopnarrower
509
510some token testers like:
511
512\startnarrower \type {\iftok} and \type {\ifhas(x)tok(s)} \stopnarrower
513
514some specific for math:
515
516\startnarrower \type {\ifmathstyle} and \type {\ifmathparameter} \stopnarrower
517
518macro helpers:
519
520\startnarrower \type {\ifarguments}, \type {\ifboolean} and \type {\ifempty} \stopnarrower
521
522robust number and dimension interception:
523
524\startnarrower \type {\ifchknum}, \type {\ifchkdim}, \type {\ifcmpnum}, \type {\ifcmpdim)}, \type {\ifnumval} and \type {\ifdimval} \stopnarrower
525
526bonus checks:
527
528\startnarrower \type {\iffrozen}, \type {\ifprotected} and \type {\ifusercmd} \stopnarrower
529
530and the mentioned:
531
532\startnarrower \type {\orelse} and \type {\orunless} \stopnarrower
533
534\stoptitle
535
536\starttitle[title=Migration]
537
538\startbuffer
539h: \setbox0\hbox{box    \footnote{h:     box}}\setbox2\hbox{\box    0}\box2\par
540h: \setbox0\hbox{copy   \footnote{h:    copy}}\setbox2\hbox{\copy   0}\box2\par
541h: \setbox0\hbox{unbox  \footnote{h:  unhbox}}\setbox2\hbox{\unhbox 0}\box2\par
542h: \setbox0\hbox{uncopy \footnote{h: unhcopy}}\setbox2\hbox{\unhcopy0}\box2\par
543
544v: \setbox0\hbox{box    \footnote{v:     box}}\setbox2\vbox{\box    0}\box2\par
545v: \setbox0\hbox{copy   \footnote{v:    copy}}\setbox2\vbox{\copy   0}\box2\par
546v: \setbox0\hbox{unbox  \footnote{v:  unhbox}}\setbox2\vbox{\unhbox 0}\box2\par
547v: \setbox0\hbox{uncopy \footnote{v: unhcopy}}\setbox2\vbox{\unhcopy0}\box2\par
548
549\starttabulate[||]
550\NC tabulate \footnote{tabulate} \NC \NR
551\stoptabulate
552\stopbuffer
553
554\typebuffer[style={\tt\small}]
555
556\page
557
558\startpacked \getbuffer \stoppacked
559
560% \setbox0\hbox{test \footnote{test}} (\prelistbox0) (\postlistbox0)
561% \setprelistbox0\hbox{BEFORE} \setpostlistbox0\hbox{AFTER}
562% \box0
563
564% \setbox0\hbox{test \footnote{test}} (\prelistcopy0) (\postlistcopy0)
565% \setprelistbox0\hbox{BEFORE} \setpostlistbox0\hbox{AFTER}
566% \box0
567
568{\em Everything insert related will always have side effects. It's complicated
569by the fact that the page flow interferes with expectations of where notes
570break cq.\ end up.}
571
572\stoptitle
573
574\starttitle[title=Normalizing lines]
575
576We can have predictable lines:
577
578\startbuffer
579    \hangindent3cm \hangafter 2 \leftskip1cm \rightskip1cm \input ward \par
580\stopbuffer
581
582\typebuffer
583
584Standard (but already with left skips):
585
586\start
587    \bitwiseflip \normalizelinemode -\parindentskipnormalizecode
588    \bitwiseflip \normalizelinemode -\normalizelinenormalizecode
589    \showmakeup \relax \getbuffer
590\stop
591
592Normalized (enhanced, no shifts, indent skip):
593
594\start
595    \bitwiseflip \normalizelinemode \parindentskipnormalizecode
596    \bitwiseflip \normalizelinemode \normalizelinenormalizecode
597    \showmakeup \relax \getbuffer
598\stop
599
600\page
601
602\startbuffer
603    \parshape 2 1cm 10cm 2cm 15cm \leftskip1cm \rightskip1cm \input ward \par
604\stopbuffer
605
606\typebuffer
607
608Standard:
609
610\start
611    \bitwiseflip \normalizelinemode -\parindentskipnormalizecode
612    \bitwiseflip \normalizelinemode -\normalizelinenormalizecode
613    \showmakeup \relax \getbuffer
614\stop
615
616Normalized:
617
618\start
619    \bitwiseflip \normalizelinemode \parindentskipnormalizecode
620    \bitwiseflip \normalizelinemode \normalizelinenormalizecode
621    \showmakeup \relax \getbuffer
622\stop
623
624% {\showmakeup \getbuffer}
625
626{\em There might be some more normalization in the future in other subsystems of
627the engine. One should be aware of this when manipulating node lists after they
628come out such subsystems.}
629
630\stoptitle
631
632\starttitle[title=Freezing paragraph properties]
633
634\startbuffer[sample]
635\startplacefigure[location=left,number=no] \externalfigure[halslegacy.jpg][width=30pt] \stopplacefigure
636
637{\bf David Stork:} \samplefile{stork}
638\stopbuffer
639
640\startbuffer[demo]
641\forgetparagraphfreezing \getbuffer[sample]
642\stopbuffer
643
644\typebuffer[demo][style=\tt\small] \start \switchtobodyfont[6pt] \getbuffer[demo] \par \stop
645
646\startbuffer[demo]
647\setparagraphfreezing    \getbuffer[sample]
648\stopbuffer
649
650\typebuffer[demo][style=\tt\small] \start \switchtobodyfont[6pt] \getbuffer[demo] \par \stop
651
652Sample: \typebuffer[sample][style=\tt\small\small]
653
654{\em This feature will stepwise be applied to mechanism and might have side effects when
655users have their own hacks around \TEX's limitations (and side effects).}
656
657\stoptitle
658
659\starttitle[title=Wrapping up paragraphs]
660
661\setparagraphfreezing
662
663We have \type {\wrapuppar} as new hook. An experimental mechanism has been build
664around it so that Wolfgang and I can freak out on this.
665
666\startbuffer
667\def\TestA{\registerparwrapper
668  {A}
669  {[\ignorespaces}
670  {\removeunwantedspaces]\showparwrapperstate{A}}}
671
672\def\TestB#1{\registerparwrapper
673  {B#1}
674  {(\ignorespaces}
675  {\removeunwantedspaces)\showparwrapperstate{B#1}}}
676
677\def\TestC{\registerparwrapper
678  {C}
679  {<\ignorespaces}
680  {\removeunwantedspaces>\showparwrapperstate{C}\forgetparwrapper}}
681
682\def\TestR{\registerparwrapperreverse
683  {R}
684  {<\ignorespaces}
685  {\removeunwantedspaces>\showparwrapperstate{R}}}
686\stopbuffer
687
688\typebuffer[style=\tt\small] \getbuffer
689
690\page
691
692Example 1:
693
694\startbuffer
695\TestA
696\dorecurse{3}
697    {1.#1 before \ruledvbox{\hsize2em\raggedcenter\TestB1 !\par} after\par}
698\dorecurse{3}
699    {2.#1 before \ruledvbox{\hsize3em\raggedcenter        !\par} after\par}
700\dorecurse{3}
701    {3.#1 before \ruledvbox{\hsize4em\raggedcenter\TestB2 !}     after\par}
702\forgetparwrapper
703\dorecurse{3}
704    {4.#1 before \ruledvbox{\hsize5em\raggedcenter\TestB3 !}     after\par}
705\TestC
706\dorecurse{3}
707    {5.#1 before \ruledvbox{\hsize2em\raggedcenter\TestA  !}     after\par}
708\stopbuffer
709
710\typebuffer[style=\tt\small]
711
712\startcolumns  \startpacked \getbuffer \stoppacked \stopcolumns
713
714\page
715
716Example 2:
717
718\startbuffer
719\TestA
720\dorecurse{3}{6.#1  before after\par} \blank
721\TestB4
722\dorecurse{3}{7.#1 before after\par} \blank
723\TestB5
724\TestR
725\dorecurse{3}{8.#1 before after\par} \blank
726\stopbuffer
727
728\typebuffer[style=\tt\small]
729
730\startcolumns  \startpacked \getbuffer \stoppacked \stopcolumns
731
732{\em These are just weird examples, but you can expect more interesting features to
733show up. Beware of stacking because order matters.}
734
735\stoptitle
736
737\stopdocument
738