-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(math): Add missing MathML mathvariant mappings
- Loading branch information
Showing
4 changed files
with
455 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
-- "normal" | "bold" | "italic" | "bold-italic" | "double-struck" | "bold-fraktur" | "script" | "bold-script" | "fraktur" | "sans-serif" | "bold-sans-serif" | "sans-serif-italic" | "sans-serif-bold-italic" | "monospace" | "initial" | "tailed" | "looped" | "stretched" | ||
-- For numbers we only have "normal" "bold" monospace sans-serif double-struck and sans-serif-bold | ||
local letter_variants = { | ||
"normal", | ||
"bold", | ||
"italic", | ||
"bold-italic", | ||
"double-struck", | ||
"fraktur", | ||
"bold-fraktur", | ||
"script", | ||
"bold-script", | ||
"sans-serif", | ||
"bold-sans-serif", | ||
"sans-serif-italic", | ||
"sans-serif-bold-italic", | ||
"monospace", | ||
-- "initial", | ||
-- "tailed", | ||
-- "looped", | ||
-- "stretched" | ||
} | ||
local number_variants = { | ||
"normal", | ||
"bold", | ||
"sans-serif", | ||
"bold-sans-serif", | ||
"double-struck", | ||
"monospace", | ||
} | ||
|
||
|
||
local greek_variants = { | ||
"normal", | ||
"bold", | ||
"italic", | ||
"bold-italic", | ||
"bold-sans-serif", | ||
} | ||
|
||
local function mathvariant(variant, char) | ||
return ('<mathml><mo mathvariant="%s">%s</mo></mathml>'):format(variant, char) | ||
end | ||
|
||
local function build_table(start, stop, variants) | ||
local t = {} | ||
local ncols = #variants | ||
local szcols = 1 / ncols * 99 .. "%lw" | ||
|
||
local header = {} | ||
for _, variant in ipairs(variants) do | ||
local cell = SU.ast.createCommand("cell", { | ||
halign = "left", | ||
}, { variant }) | ||
table.insert(header, cell) | ||
end | ||
-- table.insert(t, SU.ast.createStructuredCommand("row", { | ||
-- background = "#f0f0f0" | ||
-- }, header)) | ||
|
||
for letter = start, stop do | ||
if letter ~= 0x3A2 then -- invalid capital greek letter | ||
local row = {} | ||
local char = luautf8.char(letter) | ||
for _, variant in ipairs(variants) do | ||
local cell = SU.ast.createCommand("cell", { | ||
halign = "center", | ||
}, function () | ||
return SILE.processString(mathvariant(variant, char), "xml") | ||
end) | ||
table.insert(row, cell) | ||
end | ||
local row = SU.ast.createStructuredCommand("row", {}, row) | ||
table.insert(t, row) | ||
end | ||
end | ||
t = SU.ast.createStructuredCommand("ptable", { | ||
cols = string.rep(szcols, ncols, " "), | ||
-- header = true | ||
}, t) | ||
return t | ||
end | ||
|
||
SILE.call("par") | ||
SILE.call("noindent") | ||
local fontSz = SILE.settings:get("font.size") | ||
local mathSz = SILE.settings:get("math.font.size") | ||
SILE.call("font", { size = "0.6em" }) | ||
SILE.settings:set("math.font.size", SILE.settings:get("font.size")) | ||
SILE.process({ build_table(0x41, 0x41 + 25, letter_variants) }) | ||
SILE.process({ build_table(0x61, 0x61 + 25, letter_variants) }) | ||
SILE.process({ build_table(0x30, 0x30 + 9, number_variants) }) | ||
-- greek upper | ||
SILE.process({ build_table(0x391, 0x391 + 24, greek_variants) }) | ||
-- greek lower | ||
SILE.process({ build_table(0x3b1, 0x3b1 + 24, greek_variants) }) | ||
SILE.call("font", { size = fontSz }) | ||
SILE.settings:set("math.font.size", mathSz) | ||
SILE.call("indent") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.