summaryrefslogtreecommitdiff
path: root/macros/optex/pkg/mte.opm
blob: c3d304610c12b0c774a42fb19b8f75f5baa7d813 (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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
% This is macro package used by OpTeX, see http://petr.olsak.net/optex
% mte.opm, Petr Olšák <petr@olsak.net>, 2021
% See end of the file for more information

\_def \_mte_version {0.1, 2021-05-23}
\_codedecl \enablemte {MicroTypographic Extension <\_mte_version>}
\_namespace{mte}

    \_doc -------------------
    First, we define default protrusion values. They are
    saved in the macros
    \^`\.AlphabetPR`, \^`\.alphabetPR`, \^`\.digitsPR`, \^`\.punctPR`,
    \^`\.quotPR`, \^`\.othersPR`
    for regular and bold fonts. The analogous macros
    \^`\.AlphabetPI`, \^`\.alphabetPI`, \^`\.digitsPI`, \^`\.punctPI`,
    \^`\.quotPI`, \^`\.othersPI` store data
    for italic and bold italic fonts.
    We are using long names of these macros (without the dot shortcut in the
    code) because user can copy these macros to his/her macro file and do modifications.
    \nl
    User (or a font family file) can define other values, for example by
    `\def\_mte_quotPR{...}`. If such definition is done before
    loading this package, it has precedence. This is the reason why we are
    using \`\.trydef` which defines given macro only if it is not defined
    already.
    \_cod -------------------

\_def\.trydef #1{\_ifx#1\_undefined \_afterfi{\_def#1}\_else \_ea\_ignoreit \_fi}

    \_doc
    We want to save size of the following macros with data tables, so we don't write
    `[<code of char>] =` but only \`\_mte`~`<char> =`. We use \OpTeX/ name space for
    \^`\_mte` (no package name space) because user may copy these macros to
    other macro files and modify them. We hope that the name \^`\_mte` will
    be never used in another meaning in \OpTeX/.
    \_cod

\_def\_mte #1{[\_immediateassignment\_tmpnum=`#1 \_the\_tmpnum]}

   \_doc --------------------
   The protrusion data follow.
   The values are coefficients of total width of declared character.
   First value gives left protrusion, second value is right protrusion.
   \`\.AlphabetPR`
   \_cod --------------------

\.trydef \_mte_AlphabetPR {% Alphabets, Protrusion, Regular fonts
   \_mte  A = {.05,.05},
   \_mte  Æ = {.05,  0},
   \_mte  F = {0  ,.05},
   \_mte  J = {.05,  0},
   \_mte  K = {0  ,.05},
   \_mte  L = {0  ,.05},
   \_mte  T = {.05,.05},
   \_mte  V = {.05,.05},
   \_mte  W = {.05,.05},
   \_mte  X = {.05,.05},
   \_mte  Y = {.05,.05},
}
   \_doc
   \`\.alphabetPR`
   \_cod

\.trydef \_mte_alphabetPR {% alphabets, Protrusion, Regular fonts
   \_mte  k = {0  ,.05},
   \_mte  r = {0  ,.05},
   \_mte  t = {0  ,.07},
   \_mte  v = {.05,.05},
   \_mte  w = {.05,.05},
   \_mte  x = {.05,.05},
   \_mte  y = {.05,.07},
}
   \_doc
   \`\.digitsPR`
   \_cod

\.trydef \_mte_digitsPR {% digits, Protrusion, Regular fonts
   \_mte  0 = {0  ,.05},
   \_mte  1 = {.1 ,.2 },
   \_mte  2 = {.05,.05},
   \_mte  3 = {.05,.05},
   \_mte  4 = {.07,.07},
   \_mte  5 = {0  ,.05},
   \_mte  6 = {0  ,.05},
   \_mte  7 = {.05,.1 },
   \_mte  8 = {0  ,.05},
   \_mte  9 = {0  ,.05},
   [0xF731] = {.1, .1},   % /one.oldstyle
   [0xF732] = {.05, .05}, % /two.oldstyle
   [0xF733] = {.03, .08}, % /three.oldstyle
   [0xF734] = {.05, .05}, % /four.oldstyle
   [0xF737] = {.05, .08}, % /seven.oldstyle
}
   \_doc
   \`\.punctPR`
   \_cod

\.trydef \_mte_punctPR {% punctuations, Protrusion, Regular fonts
   \_mte  . = {0 , .7},
   \_mte  , = {0 , .5},
   \_mte  : = {0 , .5},
   \_mte  ; = {0 , .5},
   \_mte  ! = {0 , .1},
   \_mte  ? = {0 , .2},
   \_mte  @ = {.05,.05},
   \_mte  ~ = {.2, .25},
   \_mte \% = {.05,.05}, % /percent
   \_mte  * = {.3, .3},
   \_mte  + = {.25,.25},
   \_mte  - = {.4, .5},   % /hyphen
   \_mte  – = {.4, .3},   % /endash
   \_mte  — = {.3, .2},   % /emdash
   \_mte  _ = {.2, .2},   % /underscore
   \_mte  / = {.2, .3},
   \_mte \\ = {.2, .3},  % /backslash
   \_mte  ¡ = {.1, 0}, \_mte  ¿ = {.1, 0},
}
   \_doc
   \`\.quotPR`
   \_cod

\.trydef \_mte_quotPR {% quotation marks, Protrusion, Regular fonts
   \_mte  ' = {.3,.4},   % /quotesingle
   \_mte  ‘ = {.5,.7}, \_mte  ’ = {.5,.6},
   \_mte  “ = {.5,.3}, \_mte  ” = {.2,.6},
   \_mte  ‚ = {.4,.4}, \_mte  „ = {.4,.4},
   \_mte  ‹ = {.4,.4}, \_mte  › = {.3,.5},
   \_mte  « = {.3,.2}, \_mte  » = {.1,.4},
}
   \_doc
   \`\.othersPR`
   \_cod

\.trydef \_mte_othersPR {% other characters, Protrusion, Regular fonts
   \_mte  ( = {.3, 0},  \_mte  ) = {0 ,.3},
   \_mte  < = {.2, .1}, \_mte  > = {.1, .2},
   \_mte \{ = {.4, .2}, \_mte \} = {.2, .4}, % /braceleft, /braceright
   [0x2329] = {.4,  0}, [0x232A] = {0 ,.4},  % /angleleft, /angleright
   \_mte  † = {.1,.1},
   \_mte  ‡ = {.08, .08},
   \_mte  • = {.2, .2},
   \_mte  · = {.4, .45}, % /periodcentered
   \_mte  ℃ = {.08, .05},
   \_mte  ₡ = {0 , .05},
   \_mte  ° = {.4, .4},
   [0x2122] = {.1, .2}, % /trademark
   \_mte  © = {.1, .1},
   \_mte  ® = {.1, .1},
   \_mte  ª = {.1, .2},
   \_mte  º = {.1, .2},
   \_mte  ¹ = {.2, .25},
   \_mte  ² = {.05, .1},
   \_mte  ³ = {.05, .1},
   \_mte  ¬ = {.2,   0},
   \_mte  − = {.3, .3},
   \_mte  ± = {.15, .2},
   \_mte  × = {.15, .25},
   \_mte  ÷ = {.15, .25},
   \_mte  € = {.1,   0},
   \_mte  Γ = {0   ,.180}, % /Gamma
   \_mte  Δ = {.1, .1},    % /Delta
   \_mte  Θ = {.05, .05},  % /Theta
   \_mte  Λ = {.1,.1},     % /Lambda
   \_mte  Σ = {.05, .05},  % /Sigma
   \_mte  Υ = {.1,.1},     % /Upsilon
   \_mte  Φ = {.05, .05},  % /Phi
   \_mte  Ψ = {.05, .05},  % /Psi
}

   \_doc
   The protrusion data for italic and bold italic fonts follow.
   \`\.AlphabetPI`
   \_cod

\.trydef \_mte_AlphabetPI {% Alphabets, Protrusion, Italic fonts
   \_mte  A = {.125,.1},
   \_mte  Æ = {.125,-.055},
   \_mte  B = {.09,-.04},
   \_mte  C = {.145,-.075},
   \_mte  D = {.075,-.028},
   \_mte  E = {.08,-.055},
   \_mte  F = {.085,-.08},
   \_mte  G = {.153,-.015},
   \_mte  H = {.073,-.06},
   \_mte  I = {.14,-.12},
   [0x0132] = {.14,-.08}, % IJ
   \_mte  J = {.135,-.08},
   \_mte  K = {.07,-.03},
   \_mte  L = {.087,.04},
   \_mte  M = {.067,-.045},
   \_mte  N = {.075,-.055},
   \_mte  O = {.15,-.03},
   \_mte  Œ = {.15,-.055},
   \_mte  P = {.082,-.05},
   \_mte  Q = {.15,-.03},
   \_mte  R = {.075, .015},
   \_mte  S = {.09,-.065},
   \_mte  $ = {.1,-.02}, % $
   \_mte  T = {.22,-.085},
   \_mte  U = {.23,-.055},
   \_mte  V = {.26,-.06},
   \_mte  W = {.185,-.055},
   \_mte  X = {.07,-.03},
   \_mte  Y = {.25,-.06},
   \_mte  Z = {.09,-.06},
}
   \_doc
   \`\.alphabetPI`
   \_cod

\.trydef \_mte_alphabetPI {% alphabets, Protrusion, Italic fonts
   \_mte  a = {.15,-.01},
   \_mte  b = {.17, 0},
   \_mte  c = {.173,-.01},
   \_mte  d = {.15,-.055},
   \_mte  e = {.18, 0},
   \_mte  f = {0  ,-.25},
   \_mte  g = {.15,-.01},
   \_mte  h = {.1,  0},
   \_mte  i = {.21, 0},
   [0x17C9] = {.21,-.04}, % ij
   \_mte  j = {0  ,-.04},
   \_mte  k = {.11,-.05},
   \_mte  l = {.24,-.11},
   \_mte  m = {.08, 0},
   \_mte  n = {.115, 0},
   \_mte  o = {.155, 0},
   \_mte  q = {.17,-.04},
   \_mte  r = {.155,-.04},
   \_mte  s = {.13, 0},
   \_mte  t = {.23,-.01},
   \_mte  u = {.12, 0},
   \_mte  v = {.14,-.025},
   \_mte  w = {.098,-.02},
   \_mte  x = {.065,-.04},
   \_mte  y = {.13,-.02},
   \_mte  z = {.110,-.08},
}
   \_doc
   \`\.digitsPI`
   \_cod

\.trydef \_mte_digitsPI {% digits, Protrusion, Italic fonts
   \_mte  0 = {.17,-.085},
   \_mte  1 = {.23,.11},
   \_mte  2 = {.13,-.07},
   \_mte  3 = {.14,-.07},
   \_mte  4 = {.13,.08},
   \_mte  5 = {.16, 0},
   \_mte  6 = {.175,-.03},
   \_mte  7 = {.25,-.15},
   \_mte  8 = {.13,-.04},
   \_mte  9 = {.155,-.08},
   [0xF730] = {.05,.05}, % /zero.oldstyle
   [0xF731] = {.1, .1},  % /one.oldstyle
   [0xF732] = {.1,.08},  % /two.oldstyle
   [0xF733] = {.08,.05}, % /three.oldstyle
   [0xF734] = {.08,.08}, % /four.oldstyle
   [0xF735] = {.05,  0}, % /five.oldstyle
   [0xF736] = {.05,  0}, % /six.oldstyle
   [0xF737] = {.08,.08}, % /seven.oldstyle
   [0xF738] = {.05,  0}, % /eight.oldstyle
   [0xF739] = {0  ,.05}, % /nine.oldstyle
}
   \_doc
   \`\.punctPI`
   \_cod

\.trydef \_mte_punctPI {% punctuations, Protrusion, Italic fonts
   \_mte  . = {0 ,.5},
   \_mte  , = {0 ,.45},
   \_mte  : = {0 ,.3},
   \_mte  ; = {0 ,.3},
   \_mte  & = {.13,.03},
   \_mte \% = {.18,.05},
   \_mte  * = {.38,.02},
   \_mte  + = {.18,.2},
   \_mte  @ = {.18,.01},
   \_mte  ~ = {.2,.15},
   \_mte  ( = {.3, 0},   \_mte ) = {0  ,.07},
   \_mte  / = {.1,.1},
   \_mte  - = {.5,.3}, % /hyphen
   \_mte  – = {.5,.3}, % /endash
   \_mte  — = {.4,.17}, % /emdash
   \_mte  _ = {.1,.2}, % /underscore
   \_mte  ¡ = {.2,  0},  \_mte ¿ = {.2,  0},
}
   \_doc
   \`\.quotPI`
   \_cod

\.trydef \_mte_quotPI {% quotation marks, Protrusion, Italic fonts
   \_mte  ' = {.3,.4}, % /quotesingle
   \_mte  " = {.5,.3},
   \_mte  ‘ = {.8,.2},  \_mte  ’ = {.8,-.02},
   \_mte  “ = {.54,.1}, \_mte  ” = {.5,.1},
   \_mte  ‚ = {.3,.7},  \_mte  „ = {.2,.6},
   \_mte  ‹ = {.5,.3},  \_mte  › = {.4,.4},
   \_mte  « = {.4,.1},  \_mte  » = {.2,.3},
}
   \_doc
   \`\.othersPI`
   \_cod

\.trydef \_mte_othersPI {% other characters, Protrusion, Italic fonts
   \_mte  < = {.3,.1},  \_mte > = {200,100},
   \_mte \\ = {.3,.3},
   \_mte \{ = {.4,.1},  \_mte \}  = {200,200},
   \_mte  † = {.2,.08},
   \_mte  ‡ = {.12,.08},
   \_mte  • = {.22,.1},
   \_mte  · = {.55,.3}, % /periodcentered
   \_mte  ℃ = {.17, 0},
   \_mte  ₡ = {.1,.05},
   \_mte  ¶ = {.2, 0},
   \_mte  ° = {.5,.3},
   [0x2122] = {.2,.07}, % /trademark
   \_mte  © = {.05,.07},
   \_mte  ® = {.05,.07},
   \_mte  ª = {.14,.1},
   \_mte  º = {.14,.1},
   \_mte  ¹ = {.40,.15},
   \_mte  ² = {.25,.08},
   \_mte  ³ = {.25,.08},
   \_mte  ¬ = {.25,.08},
   \_mte  − = {.3,.2},
   \_mte  ± = {.15,.17},
   \_mte  × = {.2,.2},
   \_mte  ÷ = {.2,.2},
   \_mte  € = {.15, 0},
   \_mte  Γ = {.1,.12}, % /Gamma
   \_mte  Δ = {.12,.1}, % /Delta
   \_mte  Θ = {.12,.05}, % /Theta
   \_mte  Λ = {.13,.1}, % /Lambda
   \_mte  Ξ = {.1, 0}, % /Xi
   \_mte  Π = {.1, 0}, % /Pi
   \_mte  Σ = {.1,.05}, % /Sigma
   \_mte  Υ = {.18,.1}, % /Upsilon
   \_mte  Φ = {.13,.07}, % /Phi
   \_mte  Ψ = {.13,.05}, % /Psi
   \_mte  Ω = {.05, 0}, % /Omega
}

   \_doc --------------------
   The expansion data follow in macros \^`\.AlphabetX`, \^`\.alphabetX`, \^`\.digitsX`
   and \^`\.othersX`.
   They are common for all fonts. \`\.AlphabetX`
   \_cod --------------------

\.trydef \_mte_AlphabetX {% Alphabets, eXpansion
   \_mte  A = .5,
   \_mte  Æ = .5,
   \_mte  B = .7,
   \_mte  C = .7,
   \_mte  D = .5,
   \_mte  E = .7,
   \_mte  F = .7,
   \_mte  G = .5,
   \_mte  H = .7,
   \_mte  K = .7,
   \_mte  M = .7,
   \_mte  N = .7,
   \_mte  O = .5,
   \_mte  Œ = .5,
   \_mte  P = .7,
   \_mte  Q = .5,
   \_mte  R = .7,
   \_mte  S = .7,
   \_mte  U = .7,
   \_mte  W = .7,
   \_mte  Z = .7,
}
   \_doc
   \`\.alphabetX`
   \_cod

\.trydef \_mte_alphabetX {% alphabets, eXpansion
   \_mte  a = .7,
   \_mte  æ = .7,
   \_mte  b = .7,
   \_mte  c = .7,
   \_mte  d = .7,
   \_mte  e = .7,
   \_mte  g = .7,
   \_mte  h = .7,
   \_mte  k = .7,
   \_mte  m = .7,
   \_mte  n = .7,
   \_mte  o = .7,
   \_mte  œ = .7,
   \_mte  p = .7,
   \_mte  q = .7,
   \_mte  s = .7,
   \_mte  u = .7,
   \_mte  w = .7,
   \_mte  z = .7,
}
   \_doc
   \`\.digitsX`
   \_cod

\.trydef \_mte_digitsX {% digits, eXpansion
   \_mte  2 = .7,
   \_mte  3 = .7,
   \_mte  6 = .7,
   \_mte  8 = .7,
   \_mte  9 = .7,
}
   \_doc
   \`\.othersX`
   \_cod

\.trydef \_mte_othersX {% others, eXpansion
}

   \_doc --------------------
   The \`\_mte_P` (for protrusion, all fonts) and \`\_mte_X`
   (for expansion, all fonts) are empty by default but user can
   declare specific values here. These macros are used last in the
   \`\.allPR`, \`\.allPI`, \`\.allX` macros
   (used in the lua code bellow), so it has general precedence.
   \_cod --------------------

\.trydef \_mte_P {} % user specific, Protrusion
\.trydef \_mte_X {} % user specific, eXpansion

\_def \.allPR {\.AlphabetPR \.alphabetPR \.digitsPR \.punctPR \.quotPR \.othersPR \.P}
\_def \.allPI {\.AlphabetPI \.alphabetPI \.digitsPI \.punctPI \.quotPI \.othersPI \.P}
\_def \.allX  {\.AlphabetX  \.alphabetX  \.digitsX  \.othersX \.X}

   \_doc --------------------
   We add a new macro \`\.features` to the \OpTeX/'s
   \olink[fontfeatures]\_fontfeatures. It is empty by
   default but it will be changed by `\enablemte` to read protrusion and
   expansion data using Lua code.
   \_cod --------------------

\_addto\_fontfeatures{\.features}
\_def\.features{}

   \_doc --------------------
   \`\enablemte` initializes protrusion data by the \^`\.initprotrusion` macro
   and expansion data by the \^`\.initexpansion` macro. Then it sets
   \elink[pdfprotrudechars]{\protrudechars} and \elink[pdfadjustspacing]{\adjustspacing}
   primitives and sets the \^`\.features` macro to use
   the protrusion tables `pr` (for regular or bold fonts) or `pi` (for italic
   or bold italic fonts). The table `ex` is used for expansion data.
   These tables are declared in the Lua code below.
   \nl
   \`\disablemte` disables font \^`\.features` and sets appropriate primitive
   registers to zero.
   \_cod --------------------

\_def\.enablemte {%
   \_initunifonts
   \.initprotrusion  % luacode, pr and pi tables initialized
   \.initexpansion   % luacode, ex table initialized
   \_protrudechars=2
   \_adjustspacing=2
   \_def\.features{protrusion=p\.var;expansion=ex;}% pr/pi and ex tables used
   \_reloading \_currvar
}
\_def\.disablemte {%
   \_protrudechars=0
   \_adjustspacing=0
   \_def\.features{}%
   \_reloading \_currvar
}
\_nspublic \enablemte \disablemte ;

   \_doc --------------------
   The \`\.var` macro expands ro `r` when regular or bold font is loaded
   and it expands to `i` if italic or bold italic font is loaded.
   The `pr` or `pi` data table is selected using this macro.
   \_cod --------------------

\_def\.it{it}\_def\.bi{bi}
\_def\.var{\_ifx\_whatresize\.it i\_else \_ifx\_whatresize\.bi i\_else r\_fi\_fi}

   \_doc -------------------
   The `pr` and `pi` data tables are created using lua code in
   the \`\.initprotrusion` macro. The data from \^`\.allPR` or \^`\.allPI`
   are used here.
   The analogical concept is used in the \`\.initexpansion` macro.
   \_cod -------------------

\_def\.initprotrusion {%
   \_directlua {%
      fonts.protrusions.setups['pr']={
         factor=\.fpfactor,
         \.leftright,
         \.allPR
      }
      fonts.protrusions.setups['pi']={
         factor=\.fpfactor,
         \.leftright,
         \.allPI
}}}
\_def\.initexpansion {%
   \_directlua {%
      fonts.expansions.setups['ex']={
         \.stretchshrinkstep,
         factor=\.fxfactor,
         \.allX
}}}

   \_doc --------------------
   The \`\.leftright`, \`\.stretchshrinkstep`,  \`\.fpfactor`, and \`\.fxfactor`
   macros are used in the Lua code above and they have following default values
   (you can re-define them, if you want):
   \_cod --------------------

\_def \.fpfactor{1}
\_def \.leftright {left=1, right=1}
\_def \.fxfactor{1}
\_def \.stretchshrinkstep {stretch=3, shrink=2, step=.5}

   \_doc --------------------
   \`\setfpfactor` and \`\setfxfactor` simply define \^`\.fpfactor` and \^`\.fxfactor`.
   \_cod --------------------

\_def\.setfpfactor #1 {\_def\.fpfactor{#1}}
\_def\.setfxfactor #1 {\_def\.fxfactor{#1}}
\_nspublic \setfpfactor \setfxfactor ;

   \_doc --------------------
   There are similar letters: A, Á, Á, Â, Ã, Ä, Å, they need the same setting.
   But only the basic letter (A in this example) has protrusion and/or expansion
   setting using Lua code. The equivalent settings are done by the macro
   \`\.setequivs``<font-switch>`.
   This macro is used in \olink[_newfontloaded]{\_newfontloaded} `<font-switch>`
   which is called by \OpTeX/ if the font is loaded first.
   The \^`\.setequivs` macro uses data from \^`\.equalcodes` (see bellow)
   and sets equal
   \elink[lpcode]{\lpcode}, \elink[rpcode]{\rpcode}, and \elink[efcode]{\efcode}
   for variant characters.
   It is called only if \^`\.features` is non-empty, i.e.\ if the font
   includes mte data.
   \_cod --------------------

\_def\_newfontloaded#1{\_ifx\.features\_empty \_else \.setequivs#1\_fi}

\_def\.setequivs #1{\_let\.f=#1\_ea\.setequivsA\.equalcodes,,={},}
\_def\.setequivsA#1#2=#3#4,{\_ifx^#3^\_else
   \_afterfi{\_tmpnum=`#1 \.setequivsB#3#4\_end\.setequivsA}\_fi}
\_def\.setequivsB#1{\_ifx\_end#1\_else
   \_lpcode\.f`#1=\_lpcode\.f\_tmpnum
   \_rpcode\.f`#1=\_rpcode\.f\_tmpnum
   \_efcode\.f`#1=\_efcode\.f\_tmpnum
   \_ea\.setequivsB\_fi
}

   \_doc --------------------
   \`\.equalcodes` includes comma separated equivalences. The same
   \elink[lpcode]{\lpcode}, \elink[rpcode]{\rpcode}, and \elink[efcode]{\efcode}
   for all characters
   given at right side is set as these codes of the character given
   at the left side of equal sign.
   You can do `\addto\_mte_equalcodes{<your additional settings>}`
   if you want.
   \_cod --------------------

\_def\.equalcodes {%
   A = ÀÁÂÃÄÅĀĂĄǺȀẠẢẤẦẨẪẬẮẰẲẶΑ,
   B = ฿Β,
   C = ÇĆĈĊČ,
   D = ÐĎĐḌḎ,
   E = ÈÉÊËĒĔĖĘĚȄẸẺẼỀẾỄỂỆΕ,
   G = ĜĞĠĢǦǴ,
   H = ĤĦḤḦḪΗ,
   I = ÌÍÎÏĨĪĬĮİȈỈỊΙ,
   J = Ĵ,
   K = ĶΚ,
   L = ĹĽĻŁḶ,
   M = Μ,
   N = ÑŃŅŇṄṆΝ,
   O = ÒÓÔÕÖØŌŎŐỌƠǪǾȌỎỐỒỔỖỘỚỜỠỞỢΟ,
   P = Ρ,
   R = ŔŖŘȐṚṘṜ,
   S = ŚŜŞŠȘṢ,
   T = ŢŤȚṬṮΤ,
   U = ÙÚÛÜŨŪŬŮŰŲƯȔỤỦỨỪỬỮỰ,
   W = ŴẀẂẄ,
   X = Χ,
   Y = ÝŶŸỴỶỸ,
   Z = ŹŻŽẒΖ,
   a = àáâãäåāăąǻȁạảấầẩẫậắằẳẵ,
   æ = ǽ,
   c = çćĉċč,
   d = đḍḏ, % ď has different right side
   e = èéêëēĕėęěȅẹẻẽếềểễệ,
   g = ĝğġģǧǵ,
   h = ĥħḥḧḫ,
   i = ìíîïĩīĭįıȉỉị,
   j = ĵ,
   k = ķ,
   l = ĺļłḷḹ, % ľ has different right side
   n = ñńņňṅṇ,
   o = òóôõöøōŏőọơǫǿȍỏốồổỗộớờỡởợ,
   r = ŕŗřȑṛṙṝ,
   s = śŝşšșṣ,
   t = ţțṭṯẗť,
   u = ùúûüũūŭůűųưȕụủứừửữự,
   w = ŵẁẃẅ,
   y = ýŷÿỳỵỷỹ,
   z = źżžẓ,
}
\_endnamespace
\_endcode

\tit MicroTypographic Extensions for \OpTeX/
\hfill v. \_mte_version

\centerline{\it Petr Olšák, 2021}
\bigskip

You can do `\load[mte]` followed by \^`\enablemte`. The microtypographic
extensions (protrusions, expansions) of all fonts are available after
\^`\enablemte`. The \LaTeX/ package Microtype does similar effect.

The \^`\enablemte` macro reloads the current font with microtypographic
extensions (mte) enabled and all new fonts loaded by the Font Selection System have
mte enabled too, because they are added to the
\olink[_fontfeatures]{\_fontfeatures} macro used by \OpTeX/.

The \^`\enablemte` macro does only local settings. If it is used in a group then
only fonts used in this group have mte.

The \^`\enablemte` macro sets (among other things)
\elink[pdfprotrudechars]{\protrudechars}`=2` (protrusion is enabled) and
\elink[pdfadjustspacing]{\adjustspacing}`=2` (font expansion is enabled).
You can disable these features by setting these primitive registers to zero
value (it is default if \^`\enablemte` is not used).
Note, that the values of these registers are checked when
paragraph is finalized although the fonts were loaded with mte enabled.
It means that you have to use `\par` before end of group
if you use \^`\enablemte` inside a group.
For example:

\begtt
{\enablemte
  Roman font with mte enabled, \it italic font with mte enabled.
  \par % mte features are used
}
\endtt
%
Or, simply use \^`\enablemte` at beginning of your document.

On the other hand, you can use \^`\disablemte` macro which reloads current
font with mte disabled and all newly loaded fonts have
mte disabled too. The macro has local validity. For example,
`{\disablemte text}` prints `text` by a font with
mte disabled. It works locally in the middle of the paragraph (unlike setting
`\protrudechars` and `\adjustspacing` to zero).

You can define your own protrusion or expansion values: copy macros
`\_mte_AlphabetPR`, `\_mte_quotPR`, etc.\ from this package and define them
as you wish using `\def`. Such definition has precedence.
Similar definitions can be in some font family files too, so: do your
definition after all `\fontfam` if you want to keep the precedence.
All such definitions must be performed before the \^`\enablemte` command.

You can use `\def\_mte_P` for data of protrusion for all fonts
which has general precedence. For example, if you want to protrude hyphen
char with factor one at the right side and by factor 0.5 at the left side, use
\begtt
\def\_mte_P {% user specification, Protrusion, Regular fonts
 \_mte - = {.5, 1},  % /hyphen
}
\endtt
Analogical macro can be used for expansion data `\_mte_X`.

You can use \^`\setfpfactor` `<factor><space>` to set the factor by which
all protrusion data are scaled. The <factor> is decimal number and its default
value is~1. This macro can be used before \^`\enablemte`.
You can use \^`\setfxfactor` `<factor><space>` with analogical meaning,
expansion data are scaled by given~<factor>.

If you feel that default microtypographic data are wrong in a particular case,
please let me know. I can correct it in this package. If you feel
that a specific font family needs different microtypographic data, please
let me know. I can add extra definitions to appropriate font family
file.

\_doc
   % Run  optex -jobname mte-doc '\docgen mte'
   % (two times) to generate documentation including references and the index.

   \load [doc]

   \def\elink[#1]#2{%
      \ulink[http://petr.olsak.net/ftp/olsak/optex/tex-nutshell.pdf\#cs:#1]%
      {\tt\string#2}%
   }
   \def\olink[#1]#2{%
      \ulink[http://petr.olsak.net/ftp/olsak/optex/optex-doc.pdf\#cs:#1]%
      {\tt\string#2}%
   }

   \printdoctail mte.opm
   \printdoc     mte.opm

   \nonum\sec Index
   \begmulti 3
   \tt \makeindex
   \endmulti

   \bye
\_cod

\_endinput