• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 14859255754

06 May 2025 12:08PM UTC coverage: 56.689% (-3.2%) from 59.865%
14859255754

push

github

alerque
fix(build): Pass --enable-debug through to Cargo to actually get a debug-enabled binary

12191 of 21505 relevant lines covered (56.69%)

3298.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/math/unicode-mathvariants.lua
1
local scriptType = {
×
2
   upright = 1,
3
   boldScript = 2,
4
   boldItalic = 3,
5
   -- tailed = 4,
6
   bold = 5,
7
   fraktur = 6,
8
   script = 7,
9
   initial = 8,
10
   monospace = 9,
11
   sansSerif = 10,
12
   doubleStruck = 11,
13
   -- looped = 12,
14
   -- stretched = 13,
15
   italic = 14,
16
   boldFraktur = 15,
17
   sansSerifBoldItalic = 16,
18
   sansSerifItalic = 17,
19
   boldSansSerif = 18,
20
}
21

22
local mathVariantAttribute = {
×
23
   normal = scriptType.upright,
24
   ["bold-script"] = scriptType.boldScript, -- MathML Core "bold-script" (annex C.1)
25
   ["bold-italic"] = scriptType.boldItalic, --MathML Core "bold-italic" (annex C.2)
26
   -- tailed = scriptType.tailed, -- MathML Core "tailed" (annex C.3) not supported yet
27
   bold = scriptType.bold, -- MathML Core "bold" (annex C.4)
28
   fraktur = scriptType.fraktur, --MatML Core "bold" (annex C.5)
29
   script = scriptType.script, -- MathML Core "script" (annex C.6)
30
   monospace = scriptType.monospace, -- MathML Core "monospace" (annex C.7)
31
   -- initial = scriptType.initial, -- MathML Core "initial" (annex C.8) not supported yet
32
   ["sans-serif"] = scriptType.sansSerif, -- MathML Core "sans-serif" (annex C.9)
33
   ["double-struck"] = scriptType.doubleStruck, -- MathML Core "double-struck" (annex C.10)
34
   -- looped = scriptType.looped, -- MathML Core "looped" (annex C.11) not supported yet
35
   -- stretched = scriptType.stretched,-- MathML Core "stretched" (annex C.12) not supported yet
36
   italic = scriptType.italic, --MathML Core "italic" (annex C.13)
37
   ["bold-fraktur"] = scriptType.boldFraktur, --MathML Core "bold-fraktur" (annex C.14)
38
   ["sans-serif-bold-italic"] = scriptType.sansSerifBoldItalic, --MathML Core "sans-serif-bold-italic" (annex C.15)
39
   ["sans-serif-italic"] = scriptType.sansSerifItalic, --MathML Core "sans-serif-italic" (annex C.16)
40
   ["bold-sans-serif"] = scriptType.boldSansSerif, --MathML Core "sans-serif-bold" (annex C.17)
41
}
42

43
local function mathVariantToScriptType (attr)
44
   if mathVariantAttribute[attr] then
×
45
      return mathVariantAttribute[attr]
×
46
   end
47
end
48

49
local mathScriptConversionTable = {
×
50
   latinUpper = {
×
51
      [scriptType.upright] = function (codepoint)
×
52
         return codepoint
×
53
      end,
54
      [scriptType.boldScript] = function (codepoint)
×
55
         -- MathML Core "bold-script" (annex C.1)
56
         return codepoint + 0x1D4D0 - 0x41
×
57
      end,
58
      [scriptType.boldItalic] = function (codepoint)
×
59
         -- MathML Core "bold-italic" (annex C.2)
60
         return codepoint + 0x1D468 - 0x41
×
61
      end,
62
      [scriptType.bold] = function (codepoint)
×
63
         -- MathML Core "bold" (annex C.4)
64
         return codepoint + 0x1D400 - 0x41
×
65
      end,
66
      [scriptType.doubleStruck] = function (codepoint)
×
67
         -- MathML Core "double-struck" (annex C.10)
68
         return codepoint == 0x43 and 0x2102 -- C
×
69
            or codepoint == 0x48 and 0x210D -- H
×
70
            or codepoint == 0x4E and 0x2115 -- N
×
71
            or codepoint == 0x50 and 0x2119 -- P
×
72
            or codepoint == 0x51 and 0x211A -- Q
×
73
            or codepoint == 0x52 and 0x211D -- R
×
74
            or codepoint == 0x5A and 0x2124 -- Z
×
75
            or codepoint + 0x1D538 - 0x41
×
76
      end,
77
      [scriptType.fraktur] = function (codepoint)
×
78
         -- MathML Core "fraktur" (annex C.5)
79
         return codepoint == 0x43 and 0x212D -- C
×
80
            or codepoint == 0x48 and 0x210C -- H
×
81
            or codepoint == 0x49 and 0x2111 -- I
×
82
            or codepoint == 0x52 and 0x211C -- R
×
83
            or codepoint == 0x5A and 0x2128 -- Z
×
84
            or codepoint + 0x1D504 - 0x41
×
85
      end,
86
      [scriptType.script] = function (codepoint)
×
87
         -- MathML Core "script" (annex C.6)
88
         return codepoint == 0x42 and 0x212C -- B
×
89
            or codepoint == 0x45 and 0x2130 -- E
×
90
            or codepoint == 0x46 and 0x2131 -- F
×
91
            or codepoint == 0x48 and 0x210B -- H
×
92
            or codepoint == 0x49 and 0x2110 -- I
×
93
            or codepoint == 0x4C and 0x2112 -- L
×
94
            or codepoint == 0x4D and 0x2133 -- M
×
95
            or codepoint == 0x52 and 0x211D -- R
×
96
            or codepoint + 0x1D49C - 0x41
×
97
      end,
98
      [scriptType.monospace] = function (codepoint)
×
99
         -- MathML Core "monospace" (annex C.7)
100
         return codepoint + 0x1D670 - 0x41
×
101
      end,
102
      [scriptType.sansSerif] = function (codepoint)
×
103
         -- MathML Core "sans-serif" (annex C.9)
104
         return codepoint + 0x1D5A0 - 0x41
×
105
      end,
106
      [scriptType.italic] = function (codepoint)
×
107
         -- MathML Core "italic" (annex C.13)
108
         return codepoint + 0x1D434 - 0x41
×
109
      end,
110
      [scriptType.boldFraktur] = function (codepoint)
×
111
         -- MathML Core "bold-fraktur" (annex C.14)
112
         return codepoint + 0x1D56C - 0x41
×
113
      end,
114
      [scriptType.sansSerifBoldItalic] = function (codepoint)
×
115
         -- MathML Core "sans-serif-bold-italic" (annex C.15)
116
         return codepoint + 0x1D63C - 0x41
×
117
      end,
118
      [scriptType.sansSerifItalic] = function (codepoint)
×
119
         -- MathML Core "sans-serif-italic" (annex C.16)
120
         return codepoint + 0x1D608 - 0x41
×
121
      end,
122
      [scriptType.boldSansSerif] = function (codepoint)
×
123
         -- MathML Core "sans-serif-bold" (annex C.17)
124
         return codepoint + 0x1D5D4 - 0x41
×
125
      end,
126
   },
127
   latinLower = {
×
128
      [scriptType.upright] = function (codepoint)
×
129
         return codepoint
×
130
      end,
131
      [scriptType.boldScript] = function (codepoint)
×
132
         -- MathML Core "bold-script" (annex C.1)
133
         return codepoint + 0x1D4EA - 0x61
×
134
      end,
135
      [scriptType.boldItalic] = function (codepoint)
×
136
         -- MathML Core "bold-italic" (annex C.2)
137
         return codepoint + 0x1D482 - 0x61
×
138
      end,
139
      [scriptType.bold] = function (codepoint)
×
140
         -- MathML Core "bold" (annex C.4)
141
         return codepoint + 0x1D41A - 0x61
×
142
      end,
143
      [scriptType.doubleStruck] = function (codepoint)
×
144
         -- MathML Core "double-struck" (annex C.10)
145
         return codepoint + 0x1D552 - 0x61
×
146
      end,
147
      [scriptType.fraktur] = function (codepoint)
×
148
         -- MathML Core "fraktur" (annex C.5)
149
         return codepoint + 0x1D51E - 0x61
×
150
      end,
151
      [scriptType.script] = function (codepoint)
×
152
         -- MathML Core "script" (annex C.6)
153
         return codepoint == 0x65 and 0x212F -- e
×
154
            or codepoint == 0x67 and 0x210A -- g
×
155
            or codepoint == 0x6F and 0x2134 -- o
×
156
            or codepoint + 0x01D4B6 - 0x61
×
157
      end,
158
      [scriptType.monospace] = function (codepoint)
×
159
         -- MathML Core "monospace" (annex C.7)
160
         return codepoint + 0x1D68A - 0x61
×
161
      end,
162
      [scriptType.sansSerif] = function (codepoint)
×
163
         -- MathML Core "sans-serif" (annex C.9)
164
         return codepoint + 0x1D5BA - 0x61
×
165
      end,
166
      [scriptType.italic] = function (codepoint)
×
167
         -- MathML Core "italic" (annex C.13)
168
         return codepoint == 0x68 and 0x210E -- h
×
169
            or codepoint + 0x1D44E - 0x61
×
170
      end,
171
      [scriptType.boldFraktur] = function (codepoint)
×
172
         -- MathML Core "bold-fraktur" (annex C.14)
173
         return codepoint + 0x1D586 - 0x61
×
174
      end,
175
      [scriptType.sansSerifBoldItalic] = function (codepoint)
×
176
         -- MathML Core "sans-serif-bold-italic" (annex C.15)
177
         return codepoint + 0x1D656 - 0x61
×
178
      end,
179
      [scriptType.sansSerifItalic] = function (codepoint)
×
180
         -- MathML Core "sans-serif-italic" (annex C.16)
181
         return codepoint + 0x1D622 - 0x61
×
182
      end,
183
      [scriptType.boldSansSerif] = function (codepoint)
×
184
         -- MathML Core "sans-serif-bold" (annex C.17)
185
         return codepoint + 0x1D5EE - 0x61
×
186
      end,
187
   },
188
   number = {
×
189
      [scriptType.upright] = function (codepoint)
×
190
         return codepoint
×
191
      end,
192
      [scriptType.bold] = function (codepoint)
×
193
         -- MathML Core "bold" (annex C.4)
194
         return codepoint + 0x1D7CE - 0x30
×
195
      end,
196
      [scriptType.monospace] = function (codepoint)
×
197
         -- MathML Core "monospace" (annex C.7)
198
         return codepoint + 0x1D7F6 - 0x30
×
199
      end,
200
      [scriptType.sansSerif] = function (codepoint)
×
201
         -- MathML Core "sans-serif" (annex C.9)
202
         return codepoint + 0x1D7E2 - 0x30
×
203
      end,
204
      [scriptType.doubleStruck] = function (codepoint)
×
205
         -- MathML Core "double-struck" (annex C.10)
206
         return codepoint + 0x1D7D8 - 0x30
×
207
      end,
208
      [scriptType.boldSansSerif] = function (codepoint)
×
209
         -- MathML Core "sans-serif-bold" (annex C.17)
210
         return codepoint + 0x1D7EC - 0x30
×
211
      end,
212
   },
213
   greekUpper = {
×
214
      [scriptType.upright] = function (codepoint)
×
215
         return codepoint
×
216
      end,
217
      [scriptType.boldItalic] = function (codepoint)
×
218
         -- MathML Core "bold-italic" (annex C.2)
219
         return codepoint == 0x3F4 and 0x1D72D -- capital theta
×
220
            or codepoint == 0x2207 and 0x1D735 -- nabla
×
221
            or codepoint + 0x1D71C - 0x391 -- other characters
×
222
      end,
223
      [scriptType.bold] = function (codepoint)
×
224
         -- MathML Core "italic" (annex C.4)
225
         -- NOT ADDRESSED: Digamma exists only in upright and bold
226
         -- Should we care? Not sure it's used in practice in math!
227
         -- Ϝ U+03DC 𝟊 U+1D7CA
228
         return codepoint == 0x3F4 and 0x1D6B9 -- capital theta
×
229
            or codepoint == 0x2207 and 0x1D6C1 -- nabla
×
230
            or codepoint + 0x1D6A8 - 0x391 -- other characters
×
231
      end,
232
      [scriptType.italic] = function (codepoint)
×
233
         -- MathML Core "italic" (annex C.13)
234
         return codepoint == 0x3F4 and 0x1D6F3 -- capital theta
×
235
            or codepoint == 0x2207 and 0x1D6FB -- nabla
×
236
            or codepoint + 0x1D6E2 - 0x391 -- other characters
×
237
      end,
238
      [scriptType.sansSerifBoldItalic] = function (codepoint)
×
239
         -- MathML Core "sans-serif-bold-italic" (annex C.15)
240
         return codepoint == 0x3F4 and 0x1D7A1 -- capital theta
×
241
            or codepoint == 0x2207 and 0x1D7A9 -- nabla
×
242
            or codepoint + 0x1D790 - 0x391 -- other characters
×
243
      end,
244
      [scriptType.boldSansSerif] = function (codepoint)
×
245
         -- MathML Core "sans-serif-italic" (annex C.17)
246
         return codepoint == 0x3F4 and 0x1D767 -- capital theta
×
247
            or codepoint == 0x2207 and 0x1D76F -- nabla
×
248
            or codepoint + 0x1D756 - 0x391 -- other characters
×
249
      end,
250
   },
251
   greekLower = {
×
252
      [scriptType.upright] = function (codepoint)
×
253
         return codepoint
×
254
      end,
255
      [scriptType.boldItalic] = function (codepoint)
×
256
         -- MathML Core "bold-italic" (annex C.2)
257
         return codepoint == 0x3D1 and 0x1D751 -- theta
×
258
            or codepoint == 0x3D5 and 0x1D753 -- phi
×
259
            or codepoint == 0x3D6 and 0x1D755 -- pi
×
260
            or codepoint == 0x3F0 and 0x1D752 -- kappa
×
261
            or codepoint == 0x3F1 and 0x1D754 -- rho
×
262
            or codepoint == 0x3F5 and 0x1D750 -- epsilon
×
263
            or codepoint + 0x1D736 - 0x3B1 -- other characters
×
264
      end,
265
      [scriptType.bold] = function (codepoint)
×
266
         -- MathML Core "italic" (annex C.4)
267
         -- NOT ADDRESSED: Digamma exists only in upright and bold
268
         -- Should we care? Not sure it's used in practice in math!
269
         -- ϝ U+03DD 𝟋 U+1D7CB
270
         return codepoint == 0x3D1 and 0x1D6DD -- theta
×
271
            or codepoint == 0x3D5 and 0x1D6DF -- phi
×
272
            or codepoint == 0x3D6 and 0x1D6E1 -- pi
×
273
            or codepoint == 0x3F0 and 0x1D6DE -- kappa
×
274
            or codepoint == 0x3F1 and 0x1D6E0 -- rho
×
275
            or codepoint == 0x3F5 and 0x1D6DC -- epsilon
×
276
            or codepoint + 0x1D6C2 - 0x3B1
×
277
      end,
278
      [scriptType.italic] = function (codepoint)
×
279
         -- MathML Core "italic" (annex C.13)
280
         return codepoint == 0x3D1 and 0x1D717 -- theta
×
281
            or codepoint == 0x3D5 and 0x1D719 -- phi
×
282
            or codepoint == 0x3D6 and 0x1D71B -- pi
×
283
            or codepoint == 0x3F0 and 0x1D718 -- kappa
×
284
            or codepoint == 0x3F1 and 0x1D71A -- rho
×
285
            or codepoint == 0x3F5 and 0x1D716 -- epsilon
×
286
            or codepoint + 0x1D6FC - 0x3B1
×
287
      end,
288
      [scriptType.sansSerifBoldItalic] = function (codepoint)
×
289
         -- MathML Core "sans-serif-bold-italic" (annex C.15)
290
         return codepoint == 0x3D1 and 0x1D7C5 -- theta
×
291
            or codepoint == 0x3D5 and 0x1D7C7 -- phi
×
292
            or codepoint == 0x3D6 and 0x1D7C9 -- pi
×
293
            or codepoint == 0x3F0 and 0x1D7C6 -- kappa
×
294
            or codepoint == 0x3F1 and 0x1D7C8 -- rho
×
295
            or codepoint == 0x3F5 and 0x1D7C4 -- epsilon
×
296
            or codepoint + 0x1D7AA - 0x3B1 -- other characters
×
297
      end,
298
      [scriptType.boldSansSerif] = function (codepoint)
×
299
         -- MathML Core "sans-serif-italic" (annex C.17)
300
         return codepoint == 0x3D1 and 0x1D78B -- theta
×
301
            or codepoint == 0x3D5 and 0x1D78D -- phi
×
302
            or codepoint == 0x3D6 and 0x1D78F -- pi
×
303
            or codepoint == 0x3F0 and 0x1D78C -- kappa
×
304
            or codepoint == 0x3F1 and 0x1D78E -- rho
×
305
            or codepoint == 0x3F5 and 0x1D78A -- epsilon
×
306
            or codepoint + 0x1D770 - 0x3B1 -- other characters
×
307
      end,
308
   },
309
}
310

311
local function convertMathVariantScript (text, script)
312
   local converted = ""
×
313
   for _, uchr in luautf8.codes(text) do
×
314
      local dst_char = luautf8.char(uchr)
×
315
      local converter
316
      if uchr >= 0x41 and uchr <= 0x5A then
×
317
         converter = mathScriptConversionTable.latinUpper[script]
×
318
      elseif uchr >= 0x61 and uchr <= 0x7A then
×
319
         converter = mathScriptConversionTable.latinLower[script]
×
320
      elseif uchr >= 0x30 and uchr <= 0x39 then
×
321
         converter = mathScriptConversionTable.number[script]
×
322
      elseif
×
323
         uchr >= 0x391
×
324
            and uchr <= 0x3A9 -- Greek capital letters
×
325
            and uchr ~= 0x3A2 -- invalid character
×
326
         or uchr == 0x3F4
×
327
         or uchr == 0x2207 -- capital theta, nabla symbols
×
328
      then
329
         converter = mathScriptConversionTable.greekUpper[script]
×
330
      elseif
×
331
         uchr >= 0x3B1 and uchr <= 0x3C9 -- Greek small letters
×
332
         or uchr == 0x03D1 -- theta variant
×
333
         or uchr == 0x03D5 -- phi variant
×
334
         or uchr == 0x03D6 -- pi variant
×
335
         or uchr == 0x03F0 -- kappa variant
×
336
         or uchr == 0x03F1 -- rho variant
×
337
         or uchr == 0x03F5 -- epsilon variant
×
338
      then
339
         converter = mathScriptConversionTable.greekLower[script]
×
340
      end
341
      dst_char = converter and luautf8.char(converter(uchr)) or dst_char
×
342
      converted = converted .. dst_char
×
343
   end
344
   return converted
×
345
end
346

347
return {
×
348
   mathVariantToScriptType = mathVariantToScriptType,
349
   scriptType = scriptType,
350
   convertMathVariantScript = convertMathVariantScript,
351
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc