mk-plain.tex /size: 10 Kb    last modification: 2023-12-21 09:43
1% language=us
2
3\environment mk-environment
4
5\startcomponent mk-plain
6
7\chapter {Just plain}
8
9\subject{running}
10
11For testing basic \LUATEX\ functionality it makes sense to have a
12minimal system, and traditionally plain \TEX\ has been the most
13natural candidate. It is for this reason that it had been on the
14agenda for a while to provide basic \OPENTYPE\ font support for
15plain \TEX\ as well. Although the \MKIV\ node mode subsystem is
16not yet perfect, the time was right to start experimenting with a
17subset of the \MKIV\ code.
18
19Using plain roughly comes down to the following. First you need
20to generate a format:
21
22\starttyping
23luatex --ini --fmt=luatex.fmt luatex-plain.tex
24\stoptyping
25
26This format has to be moved to a place where it can be found by
27the \KPSE\ library. Since this can differ per distribution there
28is no clear recipe for it, but for \TEXLIVE\ some path ending in
29\type {web2c/luatex} is probably the right spot. After that you
30can run
31
32\starttyping
33luatex luatex-test.tex
34\stoptyping
35
36This file lives under \type {generic/context}. When it
37is run it is quite likely that you will get an error message
38because the font name database cannot be found. You
39can generate one with the following command (which assumes that
40you have \CONTEXT\ installed):
41
42\starttyping
43mtxrun --usekpse --script fonts --names
44\stoptyping
45
46The resulting file \type {luatex-fonts-names.lua} has to be placed
47somewhere in your \TEX\ tree so that it can be found anytime.
48Beware: the \type {--usekpse} flag is only used outside \CONTEXT\
49and provides very limited functionality, just enough for this
50task. Again this is a distribution specific issue so we will not
51dwell upon it here.
52
53The way fonts are defined is modelled after \XETEX, as it makes no
54sense to support the somewhat more fancy \CONTEXT\ way of doing
55things. Keep in mind that although \CONTEXT\ \MKIV\ does support
56the \XETEX\ syntax too, the preferred way there is to use a more
57symbolic feature definition approach.
58
59As this is an experimental setup, it might not always work out as
60expected. Around \LUATEX\ version 0.50 we expect the code to be
61more or less okay.
62
63\subject{implementation}
64
65The \type {luatex-fonts.lua} file is the first in a series of
66basic functionality enhancements for \LUATEX\ derived from the
67\CONTEXT\ \MKIV\ code base. Please don't pollute the \type
68{luatex-*} namespace with code not coming from the \CONTEXT\
69development team as we may add more files.
70
71This file implements a basic font system for a bare \LUATEX\
72system. By default \LUATEX\ only knows about the classic \TFM\
73fonts but it can read other font formats and pass them to \LUA.
74With some glue code one can then construct a suitable \TFM\
75representation that \LUATEX\ can work with. For more advanced font
76support a bit more code is needed that needs to be hooked
77into the callback mechanism.
78
79This file is currently rather simple: it just loads the \LUA\ file
80with the same name. An example of a \type {luatex.tex} file that is
81just the plain \TEX\ format:
82
83\starttyping
84\catcode`\{=1 % left brace is begin-group character
85\catcode`\}=2 % right brace is end-group character
86
87\input plain
88
89\everyjob\expandafter{\the\everyjob\input luatex-fonts\relax}
90
91\dump
92\stoptyping
93
94We could load the \LUA\ file in \type {\everyjob} but maybe some
95day we will need more here.
96
97When defining a font, in addition to the \XETEX\ way, you can use
98two prefixes. A \type {file:}\ prefix forces a file search, while
99a \type {name:}\ prefix will result in consulting the names
100database. The font definitions shown in figure~1 are all valid.
101
102\starttyping
103\font\testa=file:lmroman10-regular at 12pt
104\font\testb=file:lmroman12-regular:+liga; at 24pt
105\font\testc=file:lmroman12-regular:mode=node;+liga; at 24pt
106\font\testd=name:lmroman10bold at 12pt
107\font\testh=cmr10
108\font\testi=ptmr8t
109\font\teste=[lmroman12-regular]:+liga at 30pt
110\font\testf=[lmroman12-regular] at 40pt
111\font\testj=adobesongstd-light % cid font
112\font\testk=cambria(math) {\mathtest 123}
113\font\testl=file:IranNastaliq.ttf:mode=node;script=arab;\
114    language=dflt;+calt;+ccmp;+init;+isol;+medi;+fina;+liga;\
115    +rlig;+kern;+mark;+mkmk at 14pt
116\stoptyping
117
118You can load maths fonts but as Plain \TEX\ is set up for Computer
119Modern (and as we don't adapt Plain \TEX) loading Cambria does
120not give you support for its math features automatically.
121
122If you want access by name you need to generate a font
123database, using:
124
125\starttyping
126mtxrun --script font --names
127\stoptyping
128
129and put the resulting file in a spot where \LUATEX\ can find it.
130
131\subject {remarks}
132
133The code loaded in \type {luatex-fonts.lua} does not come out of
134thin air, but is mostly shared with \CONTEXT; however, in that
135macro package we go beyond what is provided in the plain variant.
136When using this code you need to keep a few things in mind:
137
138\startitemize
139
140\item This subsystem will be extended, improved etc.\ at about the
141same pace as \CONTEXT\ \MKIV. However, because \CONTEXT\ provides a
142rather high level of integration not all features will be supported
143in the same quality. Use \CONTEXT\ if you want more goodies.
144
145\item There is no official \API\ yet, which means that using
146functions implemented here is at your own risk, in the sense that
147names and namespaces might change. There will be a minimal \API\
148defined once \LUATEX\ version 1.0 is out. Instead of patching the
149files it's better to overload functions if needed.
150
151\item The modules are not stripped too much, which makes it
152possible to benefit from improvements in the code that take place
153in the perspective of \CONTEXT\ development. They might be split a
154bit more in due time so the baseline might become smaller.
155
156\item The code is maintained and tested by the \CONTEXT\
157development team. As such it might be better suited for this macro
158package and integration in other systems might demand some
159additional wrapping. The plain version discussed here is the
160benchmark and should be treated as a kind of black box.
161
162\item Problems can be reported to the team but as we use \CONTEXT\
163\MKIV\ as our baseline, you'd better check if the problem is a general
164\CONTEXT\ problem too.
165
166\item The more high level support for features that is provided in
167\CONTEXT\ is not part of the code loaded here as it makes no sense
168elsewhere. Some experimental features are not part of this code
169either but some might show up later.
170
171\item Math font support will be added but only in its basic form
172once the Latin Modern and \TEX\ Gyre math fonts are
173available. Currently traditional and \OPENTYPE\ math fonts can
174be loaded.
175
176\item At this moment the more nifty speedups are not enabled
177because they work in tandem with the alternative file handling
178that \CONTEXT\ uses. Maybe around \LUATEX\ 1.0 we will bring some
179speedup into this code too (if it pays off at all).
180
181\item The code defines a few global tables. If this code is used
182in a larger perspective then you can best make sure that no
183conflicts occur. The \CONTEXT\ package expects users to work in
184their own namespace (\type {userdata}, \type {thirddata}, \type
185{moduledata} or \type {document}). We give ourselves the freedom to
186use any table at the global level but will not use tables that are
187named after macro packages. Later, \CONTEXT\ might operate in
188a more controlled namespace but it has a low priority.
189
190\item There is some tracing code present but this is not enabled
191and not supported as it integrates quite tightly into \CONTEXT. In
192case of problems you can use \CONTEXT\ for tracking down problems.
193
194\item Patching the original code in distributions is dangerous as
195it might fix your problem but introduce new ones for \CONTEXT. So,
196best keep the original code as it is and overload functions and
197callbacks when needed. This is trivial in \LUA.
198
199\item Attributes are (automatically) taken from the range 127||255 so
200you'd best not use these yourself. Don't count on an attribute number
201staying the same and don't mess with these attributes.
202
203\stopitemize
204
205If this all sounds a bit strict, keep in mind that it makes no sense
206for us to maintain multiple code bases and we happen to use \CONTEXT.
207
208\subject{advanced features}
209
210The latest versions now also support font extending, slanting,
211protrusion and expansion. Here are a few examples:
212
213\starttyping
214\pdfprotrudechars2 \pdfadjustspacing2
215
216\font\testa=file:lmroman12-regular:+liga;extend=1.5         at 12pt
217\font\testb=file:lmroman12-regular:+liga;slant=0.8          at 12pt
218\font\testc=file:lmroman12-regular:+liga;protrusion=default at 12pt
219\font\testd=file:lmroman12-regular:+liga;expansion=default  at 12pt
220\stoptyping
221
222The extend and slant options are similar to those used in
223map files. The extend is limited to 10 and the slant to 1.
224
225In the protrusion and expansion specification the keyword \type
226{default} is an entry in a definition table. You can find an
227example at the end of \type {font-dum.lua}.
228
229A setup for expansion looks as follows:
230
231\starttyping
232fonts.expansions.setups['default'] = {
233    stretch = 2, shrink = 2, step = .5, factor = 1,
234
235    [byte('A')] = 0.5, [byte('B')] = 0.7,
236    ...........
237    [byte('8')] = 0.7, [byte('9')] = 0.7,
238}
239\stoptyping
240
241The stretch, shrink and steps become font properties
242and characters gets a value assigned. In pseudo code
243it looks like:
244
245\starttyping
246chr(A).expansion_factor = 0.5 * factor
247\stoptyping
248
249The protrusion table has left and right protrusion
250factors for each relevant character.
251
252\starttyping
253fonts.protrusions.setups['default'] = {
254    factor = 1, left = 1, right = 1,
255
256    [0x002C] = { 0, 1 }, -- comma
257    [0x002E] = { 0, 1 }, -- period
258    [0x003A] = { 0, 1 }, -- colon
259    ........
260    [0x061B] = { 0, 1 }, -- arabic semicolon
261    [0x06D4] = { 0, 1 }, -- arabic full stop
262}
263\stoptyping
264
265So, the comma will stick out in the right margin:
266
267\starttyping
268chr(comma).right_protruding = right * 1 * factor
269\stoptyping
270
271As we prefer measures relative to the width (precentages) we
272actualy use:
273
274\starttyping
275chr(comma).right_protruding = right * 1 * factor * (width/quad)
276\stoptyping
277
278You can add additional tables and access them by keyword in the
279font specification.
280
281The model used in the plain variant is a simplification of the
282\CONTEXT\ model so \CONTEXT\ users should not take this as
283starting point.
284
285\stopcomponent
286