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

sile-typesetter / sile / 11989223534

23 Nov 2024 05:54PM CUT coverage: 64.386% (-4.2%) from 68.563%
11989223534

push

github

web-flow
Merge 144192218 into f0ddaed08

3 of 12 new or added lines in 1 file covered. (25.0%)

1080 existing lines in 35 files now uncovered.

12771 of 19835 relevant lines covered (64.39%)

4344.53 hits per line

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

53.21
/packages/math/unicode-mathvariants.lua
1
local scriptType = {
1✔
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 = {
1✔
23
   normal = scriptType.upright,
1✔
24
   ["bold-script"] = scriptType.boldScript, -- MathML Core "bold-script" (annex C.1)
1✔
25
   ["bold-italic"] = scriptType.boldItalic, --MathML Core "bold-italic" (annex C.2)
1✔
26
   -- tailed = scriptType.tailed, -- MathML Core "tailed" (annex C.3) not supported yet
27
   bold = scriptType.bold, -- MathML Core "bold" (annex C.4)
1✔
28
   fraktur = scriptType.fraktur, --MatML Core "bold" (annex C.5)
1✔
29
   script = scriptType.script, -- MathML Core "script" (annex C.6)
1✔
30
   monospace = scriptType.monospace, -- MathML Core "monospace" (annex C.7)
1✔
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)
1✔
33
   ["double-struck"] = scriptType.doubleStruck, -- MathML Core "double-struck" (annex C.10)
1✔
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)
1✔
37
   ["bold-fraktur"] = scriptType.boldFraktur, --MathML Core "bold-fraktur" (annex C.14)
1✔
38
   ["sans-serif-bold-italic"] = scriptType.sansSerifBoldItalic, --MathML Core "sans-serif-bold-italic" (annex C.15)
1✔
39
   ["sans-serif-italic"] = scriptType.sansSerifItalic, --MathML Core "sans-serif-italic" (annex C.16)
1✔
40
   ["bold-sans-serif"] = scriptType.boldSansSerif, --MathML Core "sans-serif-bold" (annex C.17)
1✔
41
}
42

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

49
local mathScriptConversionTable = {
1✔
50
   latinUpper = {
1✔
51
      [scriptType.upright] = function (codepoint)
1✔
UNCOV
52
         return codepoint
×
53
      end,
54
      [scriptType.boldScript] = function (codepoint)
1✔
55
         -- MathML Core "bold-script" (annex C.1)
56
         return codepoint + 0x1D4D0 - 0x41
×
57
      end,
58
      [scriptType.boldItalic] = function (codepoint)
1✔
59
         -- MathML Core "bold-italic" (annex C.2)
UNCOV
60
         return codepoint + 0x1D468 - 0x41
×
61
      end,
62
      [scriptType.bold] = function (codepoint)
1✔
63
         -- MathML Core "bold" (annex C.4)
UNCOV
64
         return codepoint + 0x1D400 - 0x41
×
65
      end,
66
      [scriptType.doubleStruck] = function (codepoint)
1✔
67
         -- MathML Core "double-struck" (annex C.10)
68
         return codepoint == 0x43 and 0x2102 -- C
18✔
69
            or codepoint == 0x48 and 0x210D -- H
18✔
70
            or codepoint == 0x4E and 0x2115 -- N
18✔
71
            or codepoint == 0x50 and 0x2119 -- P
18✔
72
            or codepoint == 0x51 and 0x211A -- Q
12✔
73
            or codepoint == 0x52 and 0x211D -- R
12✔
74
            or codepoint == 0x5A and 0x2124 -- Z
6✔
75
            or codepoint + 0x1D538 - 0x41
18✔
76
      end,
77
      [scriptType.fraktur] = function (codepoint)
1✔
78
         -- MathML Core "fraktur" (annex C.5)
79
         return codepoint == 0x43 and 0x212D -- C
×
80
            or codepoint == 0x48 and 0x210B -- H
×
81
            or codepoint == 0x49 and 0x2110 -- 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)
1✔
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)
1✔
99
         -- MathML Core "monospace" (annex C.7)
100
         return codepoint + 0x1D670 - 0x41
×
101
      end,
102
      [scriptType.sansSerif] = function (codepoint)
1✔
103
         -- MathML Core "sans-serif" (annex C.9)
104
         return codepoint + 0x1D5A0 - 0x41
×
105
      end,
106
      [scriptType.italic] = function (codepoint)
1✔
107
         -- MathML Core "italic" (annex C.13)
UNCOV
108
         return codepoint + 0x1D434 - 0x41
×
109
      end,
110
      [scriptType.boldFraktur] = function (codepoint)
1✔
111
         -- MathML Core "bold-fraktur" (annex C.14)
112
         return codepoint + 0x1D56C - 0x41
×
113
      end,
114
      [scriptType.sansSerifBoldItalic] = function (codepoint)
1✔
115
         -- MathML Core "sans-serif-bold-italic" (annex C.15)
116
         return codepoint + 0x1D63C - 0x41
×
117
      end,
118
      [scriptType.sansSerifItalic] = function (codepoint)
1✔
119
         -- MathML Core "sans-serif-italic" (annex C.16)
120
         return codepoint + 0x1D608 - 0x41
×
121
      end,
122
      [scriptType.boldSansSerif] = function (codepoint)
1✔
123
         -- MathML Core "sans-serif-bold" (annex C.17)
124
         return codepoint + 0x1D5D4 - 0x41
×
125
      end,
126
   },
1✔
127
   latinLower = {
1✔
128
      [scriptType.upright] = function (codepoint)
1✔
129
         return codepoint
12✔
130
      end,
131
      [scriptType.boldScript] = function (codepoint)
1✔
132
         -- MathML Core "bold-script" (annex C.1)
133
         return codepoint + 0x1D4EA - 0x61
×
134
      end,
135
      [scriptType.boldItalic] = function (codepoint)
1✔
136
         -- MathML Core "bold-italic" (annex C.2)
UNCOV
137
         return codepoint + 0x1D482 - 0x61
×
138
      end,
139
      [scriptType.bold] = function (codepoint)
1✔
140
         -- MathML Core "bold" (annex C.4)
UNCOV
141
         return codepoint + 0x1D41A - 0x61
×
142
      end,
143
      [scriptType.doubleStruck] = function (codepoint)
1✔
144
         -- MathML Core "double-struck" (annex C.10)
145
         return codepoint + 0x1D552 - 0x61
12✔
146
      end,
147
      [scriptType.fraktur] = function (codepoint)
1✔
148
         -- MathML Core "fraktur" (annex C.5)
149
         return codepoint + 0x1D51E - 0x61
×
150
      end,
151
      [scriptType.script] = function (codepoint)
1✔
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)
1✔
159
         -- MathML Core "monospace" (annex C.7)
160
         return codepoint + 0x1D68A - 0x61
×
161
      end,
162
      [scriptType.sansSerif] = function (codepoint)
1✔
163
         -- MathML Core "sans-serif" (annex C.9)
164
         return codepoint + 0x1D5BA - 0x61
×
165
      end,
166
      [scriptType.italic] = function (codepoint)
1✔
167
         -- MathML Core "italic" (annex C.13)
168
         return codepoint == 0x68 and 0x210E -- h
18✔
169
            or codepoint + 0x1D44E - 0x61
18✔
170
      end,
171
      [scriptType.boldFraktur] = function (codepoint)
1✔
172
         -- MathML Core "bold-fraktur" (annex C.14)
173
         return codepoint + 0x1D586 - 0x61
×
174
      end,
175
      [scriptType.sansSerifBoldItalic] = function (codepoint)
1✔
176
         -- MathML Core "sans-serif-bold-italic" (annex C.15)
177
         return codepoint + 0x1D656 - 0x61
×
178
      end,
179
      [scriptType.sansSerifItalic] = function (codepoint)
1✔
180
         -- MathML Core "sans-serif-italic" (annex C.16)
181
         return codepoint + 0x1D622 - 0x61
×
182
      end,
183
      [scriptType.boldSansSerif] = function (codepoint)
1✔
184
         -- MathML Core "sans-serif-bold" (annex C.17)
185
         return codepoint + 0x1D5EE - 0x61
×
186
      end,
187
   },
1✔
188
   number = {
1✔
189
      [scriptType.upright] = function (codepoint)
1✔
190
         return codepoint
6✔
191
      end,
192
      [scriptType.bold] = function (codepoint)
1✔
193
         -- MathML Core "bold" (annex C.4)
194
         return codepoint + 0x1D7CE - 0x30
×
195
      end,
196
      [scriptType.monospace] = function (codepoint)
1✔
197
         -- MathML Core "monospace" (annex C.7)
198
         return codepoint + 0x1D7F6 - 0x30
×
199
      end,
200
      [scriptType.sansSerif] = function (codepoint)
1✔
201
         -- MathML Core "sans-serif" (annex C.9)
202
         return codepoint + 0x1D7E2 - 0x30
×
203
      end,
204
      [scriptType.doubleStruck] = function (codepoint)
1✔
205
         -- MathML Core "double-struck" (annex C.10)
206
         return codepoint + 0x1D7D8 - 0x30
×
207
      end,
208
      [scriptType.boldSansSerif] = function (codepoint)
1✔
209
         -- MathML Core "sans-serif-bold" (annex C.17)
210
         return codepoint + 0x1D7EC - 0x30
×
211
      end,
212
   },
1✔
213
   greekUpper = {
1✔
214
      [scriptType.upright] = function (codepoint)
1✔
UNCOV
215
         return codepoint
×
216
      end,
217
      [scriptType.boldItalic] = function (codepoint)
1✔
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)
1✔
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)
1✔
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)
1✔
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)
1✔
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
   },
1✔
251
   greekLower = {
1✔
252
      [scriptType.upright] = function (codepoint)
1✔
253
         return codepoint
×
254
      end,
255
      [scriptType.boldItalic] = function (codepoint)
1✔
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)
1✔
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)
1✔
279
         -- MathML Core "italic" (annex C.13)
UNCOV
280
         return codepoint == 0x3D1 and 0x1D717 -- theta
×
UNCOV
281
            or codepoint == 0x3D5 and 0x1D719 -- phi
×
UNCOV
282
            or codepoint == 0x3D6 and 0x1D71B -- pi
×
UNCOV
283
            or codepoint == 0x3F0 and 0x1D718 -- kappa
×
UNCOV
284
            or codepoint == 0x3F1 and 0x1D71A -- rho
×
UNCOV
285
            or codepoint == 0x3F5 and 0x1D716 -- epsilon
×
UNCOV
286
            or codepoint + 0x1D6FC - 0x3B1
×
287
      end,
288
      [scriptType.sansSerifBoldItalic] = function (codepoint)
1✔
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)
1✔
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
   },
1✔
309
}
310

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

347
return {
1✔
348
   mathVariantToScriptType = mathVariantToScriptType,
1✔
349
   scriptType = scriptType,
1✔
350
   convertMathVariantScript = convertMathVariantScript,
1✔
351
}
1✔
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