Skip to content

Commit 6f379da

Browse files
Omikhleiaalerque
authored andcommitted
feat(math): Support mathvariant on special extra greek characters
1 parent 21bcc5c commit 6f379da

2 files changed

Lines changed: 77 additions & 64 deletions

File tree

packages/math/texlike.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ local function compileToMathML_aux (_, arg_env, tree)
403403
or cp >= SU.codepoint("a") and cp <= SU.codepoint("z")
404404
or cp >= SU.codepoint("Α") and cp <= SU.codepoint("Ω")
405405
or cp >= SU.codepoint("α") and cp <= SU.codepoint("ω")
406+
or cp == SU.codepoint("ϑ")
407+
or cp == SU.codepoint("ϕ")
408+
or cp == SU.codepoint("ϰ")
409+
or cp == SU.codepoint("ϱ")
410+
or cp == SU.codepoint("ϖ")
411+
or cp == SU.codepoint("ϵ")
406412
)
407413
then
408414
tree.command = "mi"

packages/math/unicode-mathvariants.lua

Lines changed: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -216,38 +216,36 @@ local mathScriptConversionTable = {
216216
end,
217217
[scriptType.boldItalic] = function (codepoint)
218218
-- MathML Core "bold-italic" (annex C.2)
219-
-- TODO NOT ADDRESSED
220-
-- ∇ U+2207 𝜵 U+1D735
221-
return codepoint == 0x3F4 and 0x1D6A - 0x391 -- capital theta
222-
or codepoint + 0x1D71C - 0x391
219+
return codepoint == 0x3F4 and 0x1D72D -- capital theta
220+
or codepoint == 0x2207 and 0x1D735 -- nabla
221+
or codepoint + 0x1D71C - 0x391 -- other characters
223222
end,
224223
[scriptType.bold] = function (codepoint)
225224
-- MathML Core "italic" (annex C.4)
226-
-- TODO NOT ADDRESSED
227-
-- ∇ U+2207 𝛁 U+1D6C1
228-
-- ϴ U+03F4 𝚹 U+1D6B9
229-
return codepoint + 0x1D6A8 - 0x391
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
230231
end,
231232
[scriptType.italic] = function (codepoint)
232233
-- MathML Core "italic" (annex C.13)
233-
-- TODO NOT ADDRESSED
234-
-- ϴ U+03F4 𝛳 U+1D6F3
235-
-- ∇ U+2207 𝛻 U+1D6FB
236-
return codepoint + 0x1D6E2 - 0x391
234+
return codepoint == 0x3F4 and 0x1D6F3 -- capital theta
235+
or codepoint == 0x2207 and 0x1D6FB -- nabla
236+
or codepoint + 0x1D6E2 - 0x391 -- other characters
237237
end,
238238
[scriptType.sansSerifBoldItalic] = function (codepoint)
239239
-- MathML Core "sans-serif-bold-italic" (annex C.15)
240-
-- TODO NOT ADDRESSED
241-
-- ϴ U+03F4 𝞡 U+1D7A1
242-
-- ∇ U+2207 𝞩 U+1D7A9
243-
return codepoint + 0x1D790 - 0x391
240+
return codepoint == 0x3F4 and 0x1D7A1 -- capital theta
241+
or codepoint == 0x2207 and 0x1D7A9 -- nabla
242+
or codepoint + 0x1D790 - 0x391 -- other characters
244243
end,
245244
[scriptType.boldSansSerif] = function (codepoint)
246245
-- MathML Core "sans-serif-italic" (annex C.17)
247-
-- TODO NOT ADDRESSED
248-
-- ϴ U+03F4 𝝧 U+1D767
249-
-- ∇ U+2207 𝝯 U+1D76F
250-
return codepoint + 0x1D756 - 0x391
246+
return codepoint == 0x3F4 and 0x1D767 -- capital theta
247+
or codepoint == 0x2207 and 0x1D76F -- nabla
248+
or codepoint + 0x1D756 - 0x391 -- other characters
251249
end,
252250
},
253251
greekLower = {
@@ -256,61 +254,56 @@ local mathScriptConversionTable = {
256254
end,
257255
[scriptType.boldItalic] = function (codepoint)
258256
-- MathML Core "bold-italic" (annex C.2)
259-
-- TODO NOT ADDRESSED
260-
-- ϑ U+03D1 𝝑 U+1D751
261-
-- ϰ U+03F0 𝝒 U+1D752
262-
-- ϕ U+03D5 𝝓 U+1D753
263-
-- ϱ U+03F1 𝝔 U+1D754
264-
-- ϖ U+03D6 𝝕 U+1D755
265-
return codepoint + 0x1D736 - 0x3B1
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
266264
end,
267265
[scriptType.bold] = function (codepoint)
268266
-- MathML Core "italic" (annex C.4)
269-
-- TODO NOT ADDRESSED
270-
-- ϵ U+03F5 𝛜 U+1D6DC
271-
-- ϑ U+03D1 𝛝 U+1D6DD
272-
-- ϰ U+03F0 𝛞 U+1D6DE
273-
-- ϕ U+03D5 𝛟 U+1D6DF
274-
-- ϱ U+03F1 𝛠 U+1D6E0
275-
-- ϖ U+03D6 𝛡 U+1D6E1
276-
-- Ϝ U+03DC 𝟊 U+1D7CA
267+
-- NOT ADDRESSED: Digamma exists only in upright and bold
268+
-- Should we care? Not sure it's used in practice in math!
277269
-- ϝ U+03DD 𝟋 U+1D7CB
278-
return codepoint + 0x1D6C2 - 0x3B1
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
279277
end,
280278
[scriptType.italic] = function (codepoint)
281279
-- MathML Core "italic" (annex C.13)
282-
-- TODO NOT ADDRESSED
283-
-- ϵ U+03F5 𝜖 U+1D716
284-
-- ϑ U+03D1 𝜗 U+1D717
285-
-- ϰ U+03F0 𝜘 U+1D718
286-
-- ϕ U+03D5 𝜙 U+1D719
287-
-- ϱ U+03F1 𝜚 U+1D71A
288-
-- ϖ U+03D6 𝜛 U+1D71B
289-
return codepoint + 0x1D6FC - 0x3B1
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
290287
end,
291288
[scriptType.sansSerifBoldItalic] = function (codepoint)
292289
-- MathML Core "sans-serif-bold-italic" (annex C.15)
293-
-- TODO NOT ADDRESSED
294-
-- ∂ U+2202 𝟃 U+1D7C3
295-
-- ϵ U+03F5 𝟄 U+1D7C4
296-
-- ϑ U+03D1 𝟅 U+1D7C5
297-
-- ϰ U+03F0 𝟆 U+1D7C6
298-
-- ϕ U+03D5 𝟇 U+1D7C7
299-
-- ϱ U+03F1 𝟈 U+1D7C8
300-
-- ϖ U+03D6 𝟉 U+1D7C9
301-
return codepoint + 0x1D7AA - 0x3B1
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
302297
end,
303298
[scriptType.boldSansSerif] = function (codepoint)
304299
-- MathML Core "sans-serif-italic" (annex C.17)
305-
-- TODO NOT ADDRESSED
306-
-- ∂ U+2202 𝞉 U+1D789
307-
-- ϵ U+03F5 𝞊 U+1D78A
308-
-- ϑ U+03D1 𝞋 U+1D78B
309-
-- ϰ U+03F0 𝞌 U+1D78C
310-
-- ϕ U+03D5 𝞍 U+1D78D
311-
-- ϱ U+03F1 𝞎 U+1D78E
312-
-- ϖ U+03D6 𝞏 U+1D78F
313-
return codepoint + 0x1D770 - 0x3B1
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
314307
end,
315308
},
316309
}
@@ -326,9 +319,23 @@ local function convertMathVariantScript (text, script)
326319
converter = mathScriptConversionTable.latinLower[script]
327320
elseif uchr >= 0x30 and uchr <= 0x39 then
328321
converter = mathScriptConversionTable.number[script]
329-
elseif uchr >= 0x391 and uchr <= 0x3A9 and uchr ~= 0x3A2 then
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
330329
converter = mathScriptConversionTable.greekUpper[script]
331-
elseif uchr >= 0x3B1 and uchr <= 0x3C9 then
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
332339
converter = mathScriptConversionTable.greekLower[script]
333340
end
334341
dst_char = converter and luautf8.char(converter(uchr)) or dst_char

0 commit comments

Comments
 (0)