summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/context/presentations/context/2020/context-2020-concepts.tex
blob: a472a33f462f3a93ef0b8dfca0c9816260e176df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
% language=us

\usemodule[present-boring,abbreviations-logos]

\startdocument
  [title={CONCEPTS},
   banner={experiments turned features},
   location={context\enspace {\bf 2020}\enspace meeting}]

% see datatypes, hyphenation etc

\starttitle[title=Experiments]

There have been quite some experiments. Some results were rejected, some kept.
Here are a few (that come to mind). This talk is a mix of summary, discussion and
some demos.

\stoptitle

\starttitle[title=Math]

There are a couple of additional features in the math engine. Most concern a bit
more control over hard coded behavior, but some are sort of new:

\startbuffer
test $a = b \discretionary class 3 {$<$}{$>$}{$\neq$}  c$ test
\stopbuffer

\typebuffer

When there is enough room this will give

\getbuffer

When \type {\hsize} is limited we get:

{\hsize 4mm \getbuffer}

\page

\enabletrackers[math.toysymbol]

\definemathtoysymbol[Plus] [bin][+]
\definemathtoysymbol[Minus][bin][-]
\definemathtoysymbol[Equal][rel][=]

\start

\let\darkblue\darkyellow %\showmakeup[glue]

$\dorecurse{199} {
    x_{#1} \ifodd#1\relax\Plus\else\Minus\fi
} x_{200} \Equal n$

\dorecurse{10} {
    test \discretionary
        {\darkred   hel  $\sqrt{y}$ lo}
        {\darkgreen good $\sqrt{z}$ bye}
        {\darkblue  wel  $\sqrt{x}$ come} test
}

\dorecurse{10} {test #1
    $x + 2x \discretionary class 2
        {$+ \, \cdots $}
        {$     \cdots \, +$}
        {$+ \, \cdots \, +$} nx$ test
}

\stop

\stoptitle

\starttitle[title=More math]

In traditional \TEX\ the last setting wins:

\startbuffer
\def\whatevera
  {\Umathordrelspacing \textstyle=50mu
   \Umathopenbinspacing\textstyle=50mu}

\def\whateverb
  {\Umathordrelspacing \textstyle=25mu
   \Umathopenbinspacing\textstyle=25mu}

$\whatevera a = (-2)$ \par
$\whateverb a = (-2)$ \par
$\whatevera a = (-2) \quad \whateverb a = (-2)$ \par
\stopbuffer

\typebuffer \startpacked \getbuffer \stoppacked

\page

In \LUAMETATEX\ we can freeze settings on the spot:

\startbuffer
\def\whatevera
  {\frozen\Umathordrelspacing \textstyle=50mu
   \frozen\Umathopenbinspacing\textstyle=50mu}

\def\whateverb
  {\frozen\Umathordrelspacing \textstyle=25mu
   \frozen\Umathopenbinspacing\textstyle=25mu}

$\whatevera a = (-2)$ \par
$\whateverb a = (-2)$ \par
$\whatevera a = (-2) \quad \whateverb a = (-2)$ \par
\stopbuffer

\typebuffer \startpacked \getbuffer \stoppacked

\stoptitle

\starttitle[title=Macros]

Not storing arguments:

\starttyping
\def\foo#1#0#3{....}

\foo{11}{22}{33}

\foo #1#0#3->....
#1<-11
#2<-
#3<-33
\stoptyping

Ignoring arguments:

\starttyping
\def\foo#1#-#2{#1#2}

\foo{1}{2}{3}

13
\stoptyping

\page

Normal behaviour:

\starttyping
\def\foo#1#2#3{#1#2#3}

\foo{1}{{2}}{3}

\foo #1#2#3->#1#2#3
#1<-1
#2<-{2}
#3<-3
\stoptyping

Special behaviour:

\starttyping
\def\foo#1#+#3{#1#2#3}

\foo #1#2#3->#1#2#3
#1<-1
#2<-{{2}}
#3<-3
\stoptyping

\page

Optional tokens (we also show some \TEX-expansion-horror here):

\starttyping
\edef\a!space{\expandtoken \ignorecatcode \spaceasciicode}

\normalexpanded {

    \protected \def \noexpand \doifelseinset#1#2%
      {\noexpand\ifhasxtoks{,\a!space#1,}{,#2,}%
         \noexpand\expandafter\noexpand\firstoftwoarguments
       \noexpand\else
         \noexpand\expandafter\noexpand\secondoftwoarguments
       \noexpand\fi}

}
\stoptyping

or as tokens (\type{\showluatokens\doifelseinset}) on the next page:

\page

\starttyping
591504   13    1  argument
643771   13    2  argument
595596   14    0  end match
633535  120   48  if test       ifhasxtoks
643789    1  123  left brace
643793   12   44  other char
643741    9   32  ignore
185919    5    1  parameter
633495   12   44  other char
 57752    2  125  right brace
167619    1  123  left brace
643686   12   44  other char
228803    5    2  parameter
643434   12   44  other char
643792    2  125  right brace
643788  114    0  expand after  expandafter
643775  125    0  call          firstoftwoarguments
590609  120    3  if test       else
643628  114    0  expand after  expandafter
643754  125    0  call          secondoftwoarguments
643763  120    2  if test       fi
\stoptyping

\page

Cheating with arguments:

\startbuffer
\def\foo#1=#2,{(#1/#2)}

\foo 1=2,\ignorearguments
\foo 1=2\ignorearguments
\foo 1\ignorearguments
\foo \ignorearguments
\stopbuffer

\typebuffer

\getbuffer

As in:

\startbuffer
\def\foo#1=#2,{\ifarguments\or(#1)\or(#1/#2)\fi}

\foo 1=2,\ignorearguments
\foo 1=2\ignorearguments
\foo 1\ignorearguments
\foo \ignorearguments
\stopbuffer

\typebuffer

\getbuffer

\stoptitle

\starttitle[title=Hyphenation]

Hyphenation at work:

\startlinecorrection[line]
\startcombination[distance=3cm,nx=6]
    {\vtop{\hsize 2mm \strut NEDERLANDS\vskip.5\lineheight}} {\type{NEDERLANDS}}
    {\vtop{\hsize 2mm \strut Nederlands\vskip.5\lineheight}} {\type{Nederlands}}
    {\vtop{\hsize 2mm \strut nederlands\vskip.5\lineheight}} {\type{nederlands}}
    {\vtop{\hsize 2mm \strut \CONTEXT  \vskip.5\lineheight}} {\type{\CONTEXT  }}
    {\vtop{\hsize 2mm \strut text\-test\vskip.5\lineheight}} {\type{text\-test}}
    {\vtop{\hsize 2mm \strut test-test \vskip.5\lineheight}} {\type{test-test }}
\stopcombination
\stoplinecorrection

Controlling hyphenation:

\startbuffer[1]
\nohyphens NEDERLANDS {\dohyphens Nederlands} nederlands
\stopbuffer

\startbuffer[2]
NEDERLANDS {\nohyphens Nederlands} nederlands
\stopbuffer

\typebuffer[1] and \typebuffer[2]

\startlinecorrection[line]
\startcombination[distance=4cm,nx=2]
    {\small \small \vtop{\hsize 2mm \strut \nl \getbuffer[1]}} {}
    {\small \small \vtop{\hsize 2mm \strut \nl \getbuffer[2]}} {}
\stopcombination
\stoplinecorrection

\page

There are several ways to implement this:

\startitemize
\startitem choose a language with no patterns:
    \startitemize[packed]
        \startitem it's quite efficient \stopitem
        \startitem we loose language specifics \stopitem
    \stopitemize
\stopitem
\startitem set the left and right hyphen min values high:
    \startitemize[packed]
        \startitem it works okay \stopitem
        \startitem it is a hack \stopitem
        \startitem we still enter the routine \stopitem
    \stopitemize
\stopitem
\startitem block the mechanism:
    \startitemize[packed]
        \startitem it provides detailed control \stopitem
        \startitem it is conceptually clean \stopitem
    \stopitemize
\stopitem
\stopitemize

The last method is what we use in \LMTX:

\type {\dohyphens} : {\tttf \meaning\dohyphens}

\type {\nohyphens} : {\tttf \meaning\nohyphens}

\page

For the moment we have this (it might evolve):

\starttyping[style=\tt\small\small]
\chardef \completehyphenationmodecode \numexpr
    \normalhyphenationmodecode            % \discretionary
  + \automatichyphenationmodecode         % -
  + \explicithyphenationmodecode          % \-
  + \syllablehyphenationmodecode          % pattern driven
  + \uppercasehyphenationmodecode         % replaces \uchyph
  + \compoundhyphenationmodecode          % replaces \compoundhyphenmode
  % \strictstarthyphenationmodecode       % replaces \hyphenationbounds (strict = original tex)
  % \strictendhyphenationmodecode         % replaces \hyphenationbounds (strict = original tex)
  + \automaticpenaltyhyphenationmodecode  % replaces \hyphenpenaltymode (otherwise use \exhyphenpenalty)
  + \explicitpenaltyhyphenationmodecode   % replaces \hyphenpenaltymode (otherwise use \exhyphenpenalty)
  + \permitgluehyphenationmodecode        % turn glue into kern in \discretionary
  + \permitallhyphenationmodecode         % okay, let's be even more tolerant
  + \permitmathreplacehyphenationmodecode % and again we're more permissive
\relax
\stoptyping

This replaces some \LUATEX\ mode variables and adds some more which is why we now use
a bitset instead of multiple parameters.

\page

In addition we have more detailed discretionary control:

\startbuffer
nederlands\discretionary           {!}{!}{!}nederlands
nederlands\discretionary options 1 {!}{!}{!}nederlands
nederlands\discretionary options 2 {!}{!}{!}nederlands
nederlands\discretionary options 3 {!}{!}{!}nederlands
\stopbuffer

\typebuffer

\startlinecorrection[line]
\startcombination[distance=4cm,nx=4]
    {\vtop{\hsize 1mm \strut \nl nederlands\discretionary           {!}{!}{!}nederlands}} {}
    {\vtop{\hsize 1mm \strut \nl nederlands\discretionary options 1 {!}{!}{!}nederlands}} {}
    {\vtop{\hsize 1mm \strut \nl nederlands\discretionary options 2 {!}{!}{!}nederlands}} {}
    {\vtop{\hsize 1mm \strut \nl nederlands\discretionary options 3 {!}{!}{!}nederlands}} {}
\stopcombination
\stoplinecorrection

At some point it will become \quote {frozen} functionality and that's when it gets
documented (first we need to integrate and play a bit more with it in \CONTEXT).

\stoptitle

\starttitle[title=Local control]

In \LUATEX\ we have experimental (kind of ugly) immediate assignments that can be
used in expansions without blocking (resulting in tokens that is).

But now we now have local control:

\startbuffer
\newcount\foocounter

\def\foo
  {\advance\foocounter\plusone
   \the\foocounter}

\edef\oof{(\foo)(\foo)(\foo)(\foo)}

\meaning\oof
\stopbuffer

\typebuffer

{\tttf \nohyphens \veryraggedright \getbuffer}

\page

Immediate expansion:

\startbuffer
\def\foo
  {\beginlocalcontrol
     \advance\foocounter\plusone
   \endlocalcontrol
   \the\foocounter}

\edef\oof{(\foo)(\foo)(\foo)(\foo)}

\meaning\oof
\stopbuffer

\typebuffer

{\tttf \getbuffer}

Hidden assignments:

\startbuffer
\scratchcounterone \beginlocalcontrol
    \scratchcountertwo 100
    \multiply \scratchcountertwo by 4
\endlocalcontrol \scratchcountertwo
\the\scratchcounterone
\stopbuffer

\typebuffer

{\tttf \getbuffer}

% \the \beginlocalcontrol
%     \scratchcountertwo 100
%     \multiply \scratchcountertwo by 4
% \endlocalcontrol \scratchcountertwo

\page

Fancy expansion:

\startbuffer
\protected\def\foo
  {\beginlocalcontrol
     \advance\foocounter\plusone
   \endlocalcontrol
   \the\foocounter}

\edef\oof{(\foo)(\foo)(\foo)(\foo)}
\edef\ofo{(\expand\foo)(\expand\foo)(\expand\foo)(\expand\foo)}

\meaning\oof \par \meaning\ofo
\stopbuffer

\typebuffer

{\tttf \getbuffer}

And a teaser:

\starttyping
\protected\def\widthofcontent#1{\beginlocalcontrol
     \setbox\scratchbox\hbox{#1}\endlocalcontrol   \wd\scratchbox}
\stoptyping

\stoptitle

\starttitle[title=Conditionals]

We can get nicer code that this:

\starttyping
\ifdim\scratchdimen=10pt
   \expandafter\one
\else\ifnum\scratchcounter=20
   \expandafter\expandafter\expandafter\two
\else
   \expandafter\expandafter\expandafter\three
\fi\fi
\stoptyping

This becomes:

\starttyping
\ifdim\scratchdimen=10pt
   \expandafter\one
\orelse\ifnum\scratchcounter=20
   \expandafter\two
\else
   \expandafter\three
\fi
\stoptyping

\page

There is a bunch of extra conditions like the generic:

\startnarrower \type {\ifcondition} \stopnarrower

some token testers like:

\startnarrower \type {\iftok} and \type {\ifhas(x)tok(s)} \stopnarrower

some specific for math:

\startnarrower \type {\ifmathstyle} and \type {\ifmathparameter} \stopnarrower

macro helpers:

\startnarrower \type {\ifarguments}, \type {\ifboolean} and \type {\ifempty} \stopnarrower

robust number and dimension interception:

\startnarrower \type {\ifchknum}, \type {\ifchkdim}, \type {\ifcmpnum}, \type {\ifcmpdim)}, \type {\ifnumval} and \type {\ifdimval} \stopnarrower

bonus checks:

\startnarrower \type {\iffrozen}, \type {\ifprotected} and \type {\ifusercmd} \stopnarrower

and the mentioned:

\startnarrower \type {\orelse} and \type {\orunless} \stopnarrower

\stoptitle

\starttitle[title=Migration]

\startbuffer
h: \setbox0\hbox{box    \footnote{h:     box}}\setbox2\hbox{\box    0}\box2\par
h: \setbox0\hbox{copy   \footnote{h:    copy}}\setbox2\hbox{\copy   0}\box2\par
h: \setbox0\hbox{unbox  \footnote{h:  unhbox}}\setbox2\hbox{\unhbox 0}\box2\par
h: \setbox0\hbox{uncopy \footnote{h: unhcopy}}\setbox2\hbox{\unhcopy0}\box2\par

v: \setbox0\hbox{box    \footnote{v:     box}}\setbox2\vbox{\box    0}\box2\par
v: \setbox0\hbox{copy   \footnote{v:    copy}}\setbox2\vbox{\copy   0}\box2\par
v: \setbox0\hbox{unbox  \footnote{v:  unhbox}}\setbox2\vbox{\unhbox 0}\box2\par
v: \setbox0\hbox{uncopy \footnote{v: unhcopy}}\setbox2\vbox{\unhcopy0}\box2\par

\starttabulate[||]
\NC tabulate \footnote{tabulate} \NC \NR
\stoptabulate
\stopbuffer

\typebuffer[style={\tt\small}]

\page

\startpacked \getbuffer \stoppacked

% \setbox0\hbox{test \footnote{test}} (\prelistbox0) (\postlistbox0)
% \setprelistbox0\hbox{BEFORE} \setpostlistbox0\hbox{AFTER}
% \box0

% \setbox0\hbox{test \footnote{test}} (\prelistcopy0) (\postlistcopy0)
% \setprelistbox0\hbox{BEFORE} \setpostlistbox0\hbox{AFTER}
% \box0

\stoptitle

\starttitle[title=Normalizing lines]

We can have predictable lines:

\startbuffer
    \hangindent3cm \hangafter 2 \leftskip1cm \rightskip1cm \input ward \par
\stopbuffer

\typebuffer

Standard (but already with left skips):

\start
    \bitwiseflip \normalizelinemode -\indentskipmodecode
    \bitwiseflip \normalizelinemode -\normalizelinemodecode
    \showmakeup \relax \getbuffer
\stop

Normalized (enhanced, no shifts, indent skip):

\start
    \bitwiseflip \normalizelinemode \indentskipmodecode
    \bitwiseflip \normalizelinemode \normalizelinemodecode
    \showmakeup \relax \getbuffer
\stop

\page

\startbuffer
    \parshape 2 1cm 10cm 2cm 15cm \leftskip1cm \rightskip1cm \input ward \par
\stopbuffer

\typebuffer

Standard:

\start
    \bitwiseflip \normalizelinemode -\indentskipmodecode
    \bitwiseflip \normalizelinemode -\normalizelinemodecode
    \showmakeup \relax \getbuffer
\stop

Normalized:

\start
    \bitwiseflip \normalizelinemode \indentskipmodecode
    \bitwiseflip \normalizelinemode \normalizelinemodecode
    \showmakeup \relax \getbuffer
\stop

% {\showmakeup \getbuffer}

\stoptitle

\starttitle[title=Freezing paragraph properties]

\startbuffer
\forgetparagraphfreezing \placefigure[left]{}{} {\bf Andrew Cuomo:} \input cuomo
\stopbuffer

\typebuffer[style=\tt\small] \start \switchtobodyfont[8pt] \getbuffer \par \stop

\startbuffer
\setparagraphfreezing \placefigure[left]{}{} {\bf Andrew Cuomo:}  \input cuomo
\stopbuffer

\typebuffer[style=\tt\small] \start \switchtobodyfont[8pt] \getbuffer \par \stop

\stoptitle

\starttitle[title=Wrapping up paragraphs]

\setparagraphfreezing

We have \type {\wrapuppar} as new hook. An experimental mechanism has been build
around it so that Wolfgang and I can freak out on this.

\startbuffer
\def\TestA{\registerparwrapper
  {A}
  {[\ignorespaces}
  {\removeunwantedspaces]\showparwrapperstate{A}}}

\def\TestB#1{\registerparwrapper
  {B#1}
  {(\ignorespaces}
  {\removeunwantedspaces)\showparwrapperstate{B#1}}}

\def\TestC{\registerparwrapper
  {C}
  {<\ignorespaces}
  {\removeunwantedspaces>\showparwrapperstate{C}\forgetparwrapper}}

\def\TestR{\registerparwrapperreverse
  {R}
  {<\ignorespaces}
  {\removeunwantedspaces>\showparwrapperstate{R}}}
\stopbuffer

\typebuffer[style=\tt\small] \getbuffer

\page

Example 1:

\startbuffer
\TestA
\dorecurse{3}
    {1.#1 before \ruledvbox{\hsize2em\raggedcenter\TestB1 !\par} after\par}
\dorecurse{3}
    {2.#1 before \ruledvbox{\hsize3em\raggedcenter        !\par} after\par}
\dorecurse{3}
    {3.#1 before \ruledvbox{\hsize4em\raggedcenter\TestB2 !}     after\par}
\forgetparwrapper
\dorecurse{3}
    {4.#1 before \ruledvbox{\hsize5em\raggedcenter\TestB3 !}     after\par}
\TestC
\dorecurse{3}
    {5.#1 before \ruledvbox{\hsize2em\raggedcenter\TestA  !}     after\par}
\stopbuffer

\typebuffer[style=\tt\small]

\startcolumns  \startpacked \getbuffer \stoppacked \stopcolumns

\page

Example 2:

\startbuffer
\TestA
\dorecurse{3}{6.#1  before after\par} \blank
\TestB4
\dorecurse{3}{7.#1 before after\par} \blank
\TestB5
\TestR
\dorecurse{3}{8.#1 before after\par} \blank
\stopbuffer

\typebuffer[style=\tt\small]

\startcolumns  \startpacked \getbuffer \stoppacked \stopcolumns

\stoptitle

\stopdocument