| 1 |
local date = '2026-03-24' |
| 2 |
local version = 'v0.8' |
| 3 |
|
| 4 |
local fmt = string.format |
| 5 |
|
| 6 |
local copyright_notice = string.gsub(fmt([[ |
| 7 |
Copyright (C) 2024-%s |
| 8 |
The LaTeX Project and any individual authors listed elsewhere |
| 9 |
in this file. |
| 10 |
|
| 11 |
this file may be distributed and/or modified under the |
| 12 |
conditions of the LaTeX Project Public License, either version 1.3c |
| 13 |
of this license or (at your option) any later version. |
| 14 |
The latest version of this license is in |
| 15 |
https://www.latex-project.org/lppl.txt |
| 16 |
and version 1.3c or later is part of all distributions of LaTeX |
| 17 |
version 2008 or later. |
| 18 |
]], os.date'%Y'), '[^\n]*', '%%%% %0') .. '\n' |
| 19 |
|
| 20 |
local function generate_fd(writer, family_spec) |
| 21 |
writer(copyright_notice) |
| 22 |
writer(fmt("\\ProvidesFile{tu%s.fd}\n", family_spec.family)) |
| 23 |
writer(fmt(" [%s %s NFSS font definitions for %s]\n", family_spec.date, family_spec.version, family_spec.name)) |
| 24 |
writer(fmt("\\DeclareFontFamily{TU}{%s}{}\n", family_spec.family)) |
| 25 |
for _, shape in ipairs(family_spec.shapes) do |
| 26 |
writer(fmt("\\DeclareFontShape{TU}{%s}{%s}{%s}%%\n", family_spec.family, shape.series, shape.style or 'n')) |
| 27 |
writer(fmt(" {<-> \\UnicodeFontFile{%s}{%s}}{}\n", shape.filename, shape.features)) |
| 28 |
end |
| 29 |
|
| 30 |
if family_spec.scriptfamily then |
| 31 |
writer(fmt("\n\\DeclareMathScriptfontMapping{TU}{%s}{TU}{%s}{TU}{%s}", family_spec.family, family_spec.scriptfamily, family_spec.scriptscriptfamily)) |
| 32 |
end |
| 33 |
writer(fmt("\n\\endinput\n")) |
| 34 |
end |
| 35 |
|
| 36 |
local function generate_sty(writer, family_spec) |
| 37 |
writer(copyright_notice) |
| 38 |
writer(fmt("\\ProvidesPackage{%s}\n", family_spec.package)) |
| 39 |
writer(fmt(" [%s %s lua-unicode-math support package for %s]\n", family_spec.date, family_spec.version, family_spec.name)) |
| 40 |
writer(fmt("\\RequirePackage{lua-unicode-math}\n", family_spec.package)) |
| 41 |
for _, shape in ipairs(family_spec.shapes) do |
| 42 |
if shape.version then |
| 43 |
writer(fmt("\\SetSymbolFont {lummain}{%s}{TU}{%s}{%s}{%s}\n", shape.version, family_spec.family, shape.series, shape.style or 'n')) |
| 44 |
else |
| 45 |
writer(fmt("\\DeclareSymbolFont {lummain}{TU}{%s}{%s}{%s}\n", family_spec.family, shape.series, shape.style or 'n')) |
| 46 |
end |
| 47 |
end |
| 48 |
end |
| 49 |
|
| 50 |
local function write_fd(family_spec) |
| 51 |
local filename = string.format('tu%s.fd', family_spec.family) |
| 52 |
os.remove(filename) -- Ignore errors since the file might not exist yet |
| 53 |
local f = assert(io.open(filename, 'w')) |
| 54 |
generate_fd(function(str) assert(f:write(str)) end, family_spec) |
| 55 |
assert(f:close()) |
| 56 |
end |
| 57 |
|
| 58 |
local function write_sty(family_spec) |
| 59 |
local filename = string.format('%s.sty', family_spec.package) |
| 60 |
os.remove(filename) -- Ignore errors since the file might not exist yet |
| 61 |
local f = assert(io.open(filename, 'w')) |
| 62 |
generate_sty(function(str) assert(f:write(str)) end, family_spec) |
| 63 |
assert(f:close()) |
| 64 |
end |
| 65 |
|
| 66 |
local function add_feature(shapes, feature) |
| 67 |
local target = {} |
| 68 |
for i, shape in ipairs(shapes) do |
| 69 |
target[i] = { |
| 70 |
series = shape.series, |
| 71 |
style = shape.style, |
| 72 |
filename = shape.filename, |
| 73 |
features = shape.features .. feature, |
| 74 |
} |
| 75 |
end |
| 76 |
return target |
| 77 |
end |
| 78 |
|
| 79 |
local DEFAULT_FEATURES = 'mode=base;script=math;language=dflt;' |
| 80 |
local function simple_shapes(filename, fakebold) |
| 81 |
return {{ |
| 82 |
series = 'm', |
| 83 |
filename = filename, |
| 84 |
features = DEFAULT_FEATURES, |
| 85 |
}, fakebold and { |
| 86 |
series = 'b', |
| 87 |
filename = filename, |
| 88 |
features = fmt('%sembolden=%s;', DEFAULT_FEATURES, fakebold), |
| 89 |
version = 'bold', |
| 90 |
} or nil} |
| 91 |
end |
| 92 |
local function simple_and_bold(filename, bold_filename) |
| 93 |
return {{ |
| 94 |
series = 'm', |
| 95 |
filename = filename, |
| 96 |
features = DEFAULT_FEATURES, |
| 97 |
}, { |
| 98 |
series = 'b', |
| 99 |
filename = bold_filename, |
| 100 |
features = DEFAULT_FEATURES, |
| 101 |
version = 'bold', |
| 102 |
}} |
| 103 |
end |
| 104 |
|
| 105 |
local fonts = { |
| 106 |
{ |
| 107 |
family = 'lmm', |
| 108 |
name = "Latin Modern Math", |
| 109 |
package = 'lmodern', |
| 110 |
shapes = simple_shapes('latinmodern-math', 3), |
| 111 |
}, |
| 112 |
{ |
| 113 |
family = 'ncmm', |
| 114 |
name = "New Computer Modern Math", |
| 115 |
package = 'newcomputermodern', |
| 116 |
shapes = simple_and_bold('NewCMMath-Book', 'NewCMMath-Bold'), |
| 117 |
}, |
| 118 |
{ |
| 119 |
family = 'ncmsm', |
| 120 |
name = "New Computer Modern Sans Math", |
| 121 |
package = 'newcomputermodernsans', |
| 122 |
shapes = simple_shapes('NewCMSansMath-Regular', 3), |
| 123 |
}, |
| 124 |
{ |
| 125 |
family = 'stix2-math', |
| 126 |
name = "STIX2", |
| 127 |
package = 'stix2', |
| 128 |
shapes = simple_shapes('STIXTwoMath-Regular', 3), |
| 129 |
}, |
| 130 |
{ |
| 131 |
family = 'xits-math', |
| 132 |
name = "XITS", |
| 133 |
package = 'xits', |
| 134 |
shapes = simple_and_bold('XITSMath-Regular', 'XITSMath-Bold'), |
| 135 |
}, |
| 136 |
{ |
| 137 |
family = 'tg-pagella-math', |
| 138 |
name = "TeX Gyre Pagella Math", |
| 139 |
package = 'pagella', |
| 140 |
shapes = simple_shapes('texgyrepagella-math', 3), |
| 141 |
}, |
| 142 |
{ |
| 143 |
family = 'tg-dejavu-math', |
| 144 |
name = "TeX Gyre DejaVu Math", |
| 145 |
package = 'dejavu', |
| 146 |
shapes = simple_shapes('texgyredejavu-math', 3), |
| 147 |
}, |
| 148 |
{ |
| 149 |
family = 'tg-bonum-math', |
| 150 |
name = "TeX Gyre Bonum Math", |
| 151 |
package = 'bonum', |
| 152 |
shapes = simple_shapes('texgyrebonum-math', 3), |
| 153 |
}, |
| 154 |
{ |
| 155 |
family = 'tg-schola-math', |
| 156 |
name = "TeX Gyre Schola Math", |
| 157 |
package = 'schola', |
| 158 |
shapes = simple_shapes('texgyreschola-math', 3), |
| 159 |
}, |
| 160 |
{ |
| 161 |
family = 'tg-termes-math', |
| 162 |
name = "TeX Gyre Termes Math", |
| 163 |
package = 'termes', |
| 164 |
shapes = simple_shapes('texgyretermes-math', 3), |
| 165 |
}, |
| 166 |
{ |
| 167 |
family = 'fira-math', |
| 168 |
name = "Fira Math", |
| 169 |
package = 'fira', |
| 170 |
shapes = simple_shapes('FiraMath-Regular', 3), |
| 171 |
}, |
| 172 |
{ |
| 173 |
family = 'gfsneohellenic-math', |
| 174 |
name = "GFS Neohellenic Math", |
| 175 |
package = 'gfsneohellenic', |
| 176 |
shapes = simple_shapes('GFSNeohellenicMath', 3), |
| 177 |
}, |
| 178 |
{ |
| 179 |
family = 'erewhon-math', |
| 180 |
name = "Erewhon Math", |
| 181 |
package = 'erewhon', |
| 182 |
shapes = simple_and_bold('Erewhon-Math', 'Erewhon-Math-Bold'), |
| 183 |
}, |
| 184 |
{ |
| 185 |
family = 'xcharter-math', |
| 186 |
name = "XCharter Math", |
| 187 |
package = 'xcharter', |
| 188 |
shapes = simple_and_bold('XCharter-Math', 'XCharter-Math-Bold'), |
| 189 |
}, |
| 190 |
{ |
| 191 |
family = 'concmath', |
| 192 |
name = "Concrete Math", |
| 193 |
package = 'concrete', |
| 194 |
shapes = simple_and_bold('Concrete-Math', 'Concrete-Math-Bold'), |
| 195 |
}, |
| 196 |
{ |
| 197 |
family = 'euler-math', |
| 198 |
name = "Euler Math", |
| 199 |
package = 'euler', |
| 200 |
shapes = simple_shapes('Euler-Math', 3), |
| 201 |
}, |
| 202 |
{ |
| 203 |
family = 'arsenal-math', |
| 204 |
name = "Arsenal Math", |
| 205 |
package = 'arsenal', |
| 206 |
shapes = simple_and_bold('ArsenalMath-Sans', 'ArsenalMath-SansBold'), |
| 207 |
}, |
| 208 |
{ |
| 209 |
family = 'asana-math', |
| 210 |
name = "Asana Math", |
| 211 |
package = 'asana', |
| 212 |
shapes = simple_shapes('Asana-Math', 3), |
| 213 |
}, |
| 214 |
{ |
| 215 |
family = 'garamond-math', |
| 216 |
name = "Garamond Math", |
| 217 |
package = 'garamond', |
| 218 |
shapes = simple_shapes('Garamond-Math', 3), |
| 219 |
}, |
| 220 |
{ |
| 221 |
family = 'lete-sans-math', |
| 222 |
name = "Lete Sans Math", |
| 223 |
package = 'lete-sans', |
| 224 |
shapes = simple_and_bold('LeteSansMath', 'LeteSansMath-Bold'), |
| 225 |
}, |
| 226 |
{ |
| 227 |
family = 'luciole-math', |
| 228 |
name = "Luciole Math", |
| 229 |
package = 'luciole', |
| 230 |
shapes = simple_and_bold('Luciole-Math', 'Luciole-Math-Bold'), |
| 231 |
}, |
| 232 |
{ |
| 233 |
family = 'oldstandard-math', |
| 234 |
name = "Old Standard Math", |
| 235 |
package = 'oldstandard', |
| 236 |
shapes = simple_shapes('OldStandard-Math', 3), |
| 237 |
}, |
| 238 |
{ |
| 239 |
family = 'plex-math', |
| 240 |
name = "IBM Plex Math", |
| 241 |
package = 'plex', |
| 242 |
shapes = simple_shapes('IBMPlexMath-Regular', 3), |
| 243 |
}, |
| 244 |
{ |
| 245 |
family = 'libertinus-math', |
| 246 |
name = "Libertinus Math", |
| 247 |
package = 'libertinus', |
| 248 |
shapes = simple_shapes('LibertinusMath-Regular', 3), |
| 249 |
}, |
| 250 |
{ |
| 251 |
family = 'kpmath-sans', |
| 252 |
name = "KpMath Sans", |
| 253 |
package = 'kpmath-sans', |
| 254 |
shapes = simple_and_bold('KpMath-Sans', 'KpMath-SansBold'), |
| 255 |
}, |
| 256 |
} |
| 257 |
|
| 258 |
for _, data in ipairs(fonts) do |
| 259 |
local scriptfamily = fmt('%s-sf', data.family) |
| 260 |
local scriptscriptfamily = fmt('%s-ssf', data.family) |
| 261 |
write_sty { |
| 262 |
family = data.family, |
| 263 |
date = date, |
| 264 |
version = version, |
| 265 |
name = data.name, |
| 266 |
package = 'lum-' .. data.package, |
| 267 |
shapes = data.shapes, |
| 268 |
} |
| 269 |
write_fd { |
| 270 |
family = data.family, |
| 271 |
date = date, |
| 272 |
version = version, |
| 273 |
name = data.name, |
| 274 |
scriptfamily = scriptfamily, |
| 275 |
scriptscriptfamily = scriptscriptfamily, |
| 276 |
shapes = data.shapes, |
| 277 |
} |
| 278 |
write_fd { |
| 279 |
family = scriptfamily, |
| 280 |
date = date, |
| 281 |
version = version, |
| 282 |
name = fmt("%s Script", data.name), |
| 283 |
shapes = add_feature(data.shapes, 'ssty=1;'), |
| 284 |
} |
| 285 |
write_fd { |
| 286 |
family = scriptscriptfamily, |
| 287 |
date = date, |
| 288 |
version = version, |
| 289 |
name = fmt("%s Subscript", data.name), |
| 290 |
shapes = add_feature(data.shapes, 'ssty=2;'), |
| 291 |
} |
| 292 |
print(fmt("%s & lum-%s \\\\", data.name, data.package)) |
| 293 |
end |