bonum-math.lfg /size: 16 Kb    last modification: 2025-02-21 11:03
1local common  = fonts.goodies.load("common-math.lfg")
2local presets = common.mathematics.tweaks.presets
3
4local integral_variants = { bottomright = -0.20 }
5local integral_top      = { topright    =  0 }
6local integral_bottom   = { bottomright = -0.10 } -- if too big it looks bad with triple integrals
7
8return {
9    name = "bonum-math",
10    version = "1.00",
11    comment = "Goodies that complement bonum.",
12    author = "Hans Hagen & Mikael Sundqvist",
13    copyright = "ConTeXt development team",
14    mathematics = {
15        parameters = {
16            AccentTopShiftUp                  =  -15,
17            FlattenedAccentTopShiftUp         =  -15,
18            AccentBaseDepth                   =   50,
19            DelimiterPercent                  =   85,
20            DelimiterShortfall                =  400,
21            DelimiterDisplayPercent           =   90,
22            DelimiterDisplayShortfall         =  400,
23            DisplayOperatorMinHeight          = 1900, -- 1250 in font
24            SubscriptShiftDown                =  201, -- 231 in font
25            SuperscriptShiftUp                =  364, -- 334 in font
26            SubscriptShiftDownWithSuperscript = "1.4*SubscriptShiftDown", -- trial and error
27            PrimeShiftUp                      = "1.25*SuperscriptShiftUp",
28            PrimeShiftUpCramped               = "1.25*SuperscriptShiftUp",
29        },
30        tweaks = {
31            aftercopying = {
32                {
33                    tweak    = "version",
34                    expected = "Version 1.005",
35                },
36                {
37                    tweak   = "fixprimes",
38                    factor  = 0.77,
39                },
40                {
41                    tweak = "addmirrors",
42                },
43                {
44                    tweak = "addcomposites",
45                },
46                {
47                    tweak   = "replacealphabets",
48                    list    = {
49                        {
50                            source   = { first = 0x003B1 }, -- upright alpha
51                            filename = "texgyrebonummathcompanion-regular.otf",
52                        },
53                        {
54                            source   = { first = 0x1D6FC }, -- italic alpha
55                            filename = "texgyrebonummathcompanion-regular.otf",
56                        },
57                        {
58                            source   = { first = 0x1D6C2 }, -- bold upright alpha
59                            filename = "texgyrebonummathcompanion-regular.otf",
60                        },
61                        {
62                            source   = { first = 0x1D736 }, -- bold italic alpha
63                            filename = "texgyrebonummathcompanion-regular.otf",
64                        },
65                        {
66                            source   = { first = 0x02980 }, -- triplebar
67                            filename = "texgyrebonummathcompanion-regular.otf",
68                        },
69                    },
70                },
71                presets.smalldigits          { factor  = 0.95 },
72                presets.scripttocalligraphic { },
73                presets.rsfstoscript         { rscale  = 0.98 },
74                presets.rsfsuprighttoscript  { rscale  = 0.98 },
75                presets.moderntocalligraphic { rscale  = 0.98 },
76                presets.eulertocalligraphic  { rscale  = 0.98 },
77                presets.xitsarabic           { rscale  = 1    },
78                presets.fallbacks            { },
79                presets.moveintegrals        { factor  = 1.5  },
80                presets.moveitalics          { correct = true },
81                presets.wipeanchors          { },
82                presets.wipeitalics          { },
83                {
84                    tweak = "checkaccents",
85                },
86                {
87                    tweak = "wipecues",
88                },
89                {
90                    -- We need to check these, are the tweaks necessary or not?
91                    tweak = "dimensions",
92                    list  = {
93                        ["lowercasefraktur"] = {
94                            width    = 1.25,
95                            extend   = 1.25,
96                            height   = 1.15,
97                            depth    = 1.15,
98                            squeeze  = 1.15,
99                        },
100
101                        ["lowercasescript"] = {
102                            factor = 1.2,
103                        },
104                    },
105                },
106                {
107                    tweak = "kerns",
108                    list  = {
109                        [0x002F]                = { topleft  = -0.2,  bottomright = -0.2  },
110                        ["0x002F.variants.*"]   = { topleft  = -0.2,  bottomright = -0.2  },
111                        [0x007D]                = { topright = -0.05, bottomright = -0.05 }, -- right brace variants
112                        ["0x7D.variants.*"]     = { topright = -0.05, bottomright = -0.05 }, -- right brace variants
113                        ["0x7D.parts.top"]      = { topright = -0.15,                     }, -- right brace top
114                        ["0x7D.parts.bottom"]   = {                   bottomright = -0.15 }, -- right brace bottom
115                        [0x0029]                = { topright = -0.15, bottomright = -0.15 }, -- right parenthesis variants
116                        ["0x29.variants.*"]     = { topright = -0.15, bottomright = -0.15 }, -- right parenthesis variants
117                        ["0x29.parts.top"]      = { topright = -0.15,                     }, -- right parenthesis top
118                        ["0x29.parts.bottom"]   = {                   bottomright = -0.15 }, -- right parenthesis bottom
119                        [0x221A]                = { topright =  0.2,  bottomright =  0.2  }, -- radical
120                        ["0x221A.variants.*"]   = { topright =  0.2,  bottomright =  0.2  },
121                        ["0x221A.parts.top"]    = { topright =  0.2,                      },
122                        ["0x221A.parts.bottom"] = {                   bottomright =  0.2  },
123                        [0x27E9]                = { topright = -0.1,  bottomright = -0.1  }, -- angle
124                        ["0x27E9.variants.*"]   = { topright = -0.2,  bottomright = -0.2  },
125                        [0x27EB]                = { topright = -0.1,  bottomright = -0.1  },
126                        ["0x27EB.variants.*"]   = { topright = -0.2,  bottomright = -0.2  },
127                        --
128                        [0x1D465]               = { bottomright = -0.05 }, -- italic x (ic is too large)
129                        [0x00393]               = { bottomright = -0.30 }, -- upright Gamma
130                        [0x1D43F]               = { bottomright =  0.01 }, -- upright L
131                        ["0x222B.parts.bottom"] = { bottomright = -0.20 }, -- int
132                        ["0x222C.parts.bottom"] = { bottomright = -0.15 }, -- iint
133                        ["0x222D.parts.bottom"] = { bottomright = -0.10 }, -- iiint
134                        ["0x2A0C.parts.bottom"] = { bottomright = -0.05 }, -- iiiint
135                    },
136                },
137                -- Accents are a mess. We migrate the extensibles from the combiners to the base accent
138                -- and then need to tweak the width (which is auto set because it was zero with a large
139                -- accent anchor offset). First we copy and fix.
140                {
141                    tweak = "extendaccents",
142                },
143                {
144                    tweak = "flattenaccents",
145                },
146                {
147                    tweak = "fixaccents", -- after flatten (zero width intefrerence)
148                },
149                {
150                    tweak   = "radicaldegreeanchors",
151                    list = {
152                        [0x221A]                = { location = "left", hfactor  = .1, vfactor  = .3 },
153                        ["0x221A.variants.*"]   = { location = "left", hfactor  = .1, vfactor  = .625 },
154                        ["0x221A.variants.1"]   = { location = "left", hfactor  = .1, vfactor  = .575 },
155                        ["0x221A.parts.bottom"] = { location = "left", hfactor  = .1, vfactor  = 1.15 },
156                    }
157                },
158                {
159                    tweak = "dimensions",
160                    list  = {
161                     -- [0x007D]              = { topright = -0.05, bottomright = -0.05 }, -- right brace variants
162                        ["0x7C"]              = { width = 1.4, xoffset=0.2 },              -- vertical bar (just looks better tis way)
163                     -- ["0x7C.variants.*"]   = { width = 1, extend = 2.4 },
164                     -- ["0x7C.parts.top"]    = { },
165                     -- ["0x7C.parts.bottom"] = { bottomright = -0.15 },
166                    },
167                },
168                -- First we set the dimensions of the initial accent which started out as zero but we want
169                -- a proper width. Thjis is no longer needed because we tweak the dimensions automatically,
170                -- so this is just some documented history.
171             -- {
172             --     tweak = "dimensions",
173             --     list  = {
174             --         [0x00302]              = { width = 1.4, anchor = 1.20, xoffset = .10 }, -- widehat
175             --         ["0x00302.flataccent"] = { width = 1.4, anchor = 1.20 },                -- no offset, because we copy
176             --     },
177             -- },
178                -- Then we deal with all offsets and heights in one go. So we treat the initial accent
179                -- as well as the variants here. But none for Bonum.
180                -- We now copy these to the not wide slots so that we can set these to stretch as well,
181                -- if only because it is less confusing and more consistent.
182                {
183                    tweak = "copyaccents",
184                },
185                -- So far for the accents.
186                {
187                    -- This one fakes margins to get larger/smaller accents with for example the
188                    -- \widetilde.
189                    tweak = "margins",
190                    list  = {
191                        [0x1D7DC] = { left = -.1,  right = -.1 }, -- doublestruck 4
192
193                        [0x1D712] = { left = -.1,  right = -.1 }, -- italic chi
194                        [0x1D713] = { left = -.1,  right = -.1 }, -- italic psi
195                        [0x1D714] = { left = -.1,  right = -.1 }, -- italic omega
196
197                        [0x003B1] = { left = -.1,  right = -.1 }, -- upright alpha
198                        [0x003B3] = { left = -.1,  right = -.1 }, -- upright gamma
199                        [0x003BA] = { left = -.1,  right = -.1 }, -- upright kappa
200                        [0x003BC] = { left = -.1,  right = -.1 }, -- upright mu
201                        [0x003C0] = { left = -.1,  right = -.1 }, -- upright pi
202                        [0x003C3] = { left = -.1,  right = -.1 }, -- upright sigma
203                        [0x003C5] = { left = -.1,  right = -.1 }, -- upright upsilon
204                        [0x003C6] = { left = -.1,  right = -.1 }, -- upright phi
205                        [0x003C8] = { left = -.1,  right = -.1 }, -- upright psi
206                        [0x003C9] = { left = -.1,  right = -.1 }, -- upright omega
207
208                        -- Greek lowercase sans (bold, italic) can be improved
209
210                        [0x1D451] = { left = -.1,  right = -.1 }, -- italic d
211                        [0x1D453] = { left = -.1,  right = -.1 }, -- italic f
212
213                        [0x00394] = { left =  .1,  right =  .1 }, -- upright Delta
214                        [0x003A3] = { left =  .1,  right =  .1 }, -- upright Sigma
215
216                        [0x00046] = { left =  .1,  right =  .1 }, -- F
217                        [0x0004C] = { left =  .1,  right =  .1 }, -- L
218                        [0x00050] = { left =  .1,  right =  .1 }, -- P
219                        [0x00053] = { left =  .1,  right =  .1 }, -- S
220                        [0x00054] = { left =  .1,  right =  .1 }, -- T
221                        [0x0005A] = { left =  .1,  right =  .1 }, -- Z
222
223                        [0x1D43D] = { left = -.1,  right = -.1  }, -- italic J
224                        [0x1D44B] = { left = -.05, right = -.05 }, -- italic X
225                    },
226                },
227                {
228                    -- The v could have a bit more sidebearing
229                    tweak = "dimensions",
230                    list  = {
231                        ["0x1D463"] = { width = 1.075, }, -- italic v
232                    },
233                },
234                {
235                    tweak = "addprivates",
236                },
237                {
238                    tweak = "addscripts",
239                },
240                {
241                    tweak = "accentdimensions",
242                },
243                {
244                    tweak = "addrules",
245                },
246                {
247                    tweak    = "replacerules",
248                    fraction = { height = .244, yoffset = .758 },
249                    radical  = { height = .244, yoffset = .758, leftoffset = .1, rightoffset = .1 },
250                    stacker  = { height = .244, yoffset = .758 },
251                },
252                {
253                    -- This tweak is only needed for the funny arrows and these now get properly
254                    -- centered. (Could actually be done in the engine).
255                    tweak = "addarrows",
256                    -- These are for documentation purposed as they are the defaults anyway:
257                    left  = 0.05,
258                    right = 0.05,
259                    slack = 0.10,
260                    -- The equal doesn't really match the double arrows, as in plain etc, so it still
261                    -- looks somewhat bad when zoomed in. This is the best we could do. Anyway, this
262                    -- in only used when testing (forced) so it doesn't kick in normally.
263                    list  = { [0x3D] = { squeeze = .85, yoffset = .0975 } }
264                },
265                {
266                    -- Do we need these in the future?
267                    -- Maybe a more general setup?
268                    -- Maybe "reset llx"
269                    tweak = "kernpairs",
270                    list = {
271                        [mathematics.tweaks.subsets.acenorsuvxz] = {
272                            [0x1D453] = -.1, -- f
273                            [0x1D457] = -.1, -- j
274                        },
275                        [mathematics.tweaks.subsets.bhklt] = {
276                            [0x1D453] = -.1, -- f
277                            [0x1D457] = -.1, -- j
278                        },
279                        [mathematics.tweaks.subsets.d] = {
280                            [0x1D453] = -.075, -- f
281                            [0x1D457] = -.075, -- j
282                        },
283                        [mathematics.tweaks.subsets.f] = {
284                            -- [mathematics.tweaks.subsets.aceimnorsuvwxz] = -.05,
285                            [mathematics.tweaks.subsets.gjqy] = -.15,
286                            [0x1D453] = -.2, -- ff
287                        },
288                        [mathematics.tweaks.subsets.i] = {
289                            [0x1D453] = -.2, -- f
290                            [0x1D457] = -.2, -- j
291                        },
292                        [mathematics.tweaks.subsets.mw] = {
293                            [0x1D453] = -.05, -- f
294                            [0x1D457] = -.05, -- j
295                        },
296                        [mathematics.tweaks.subsets.p] = {
297                            [0x1D453] = -.05, -- f
298                            [0x1D457] = -.05, -- j
299                        },
300                        [0x1D45F] = { -- r
301                            [0x1D460] = -.1, -- s
302                        },
303                    }
304                },
305                -- {
306                --     tweak   = "addbars",
307                --     advance = 0.475,
308                -- },
309                {
310                    tweak = "addactuarian",
311                },
312                {
313                    tweak = "addequals",
314                },
315                {
316                    tweak   = "addfourier",
317                    variant = 1,
318                },
319                {
320                    tweak   = "addprimed",
321                },
322                -- this is the mkiv section
323                {
324                    tweak   = "emulatelmtx",
325                    feature = "emulatelmtx",
326                    comment = "this is for mkiv",
327                },
328            },
329        },
330        alternates = {
331            dotless = { feature = 'dtls', value = 1, comment = "Mathematical Dotless Forms" },
332        },
333        bigslots = {
334            1, 3, 5, 7
335        },
336    },
337}
338