Repository navigation
Expand file tree
/
Copy pathGenerateUnicodeTable.js
More file actions
62 lines (51 loc) · 1.65 KB
/
Copy pathGenerateUnicodeTable.js
File metadata and controls
62 lines (51 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { writeFile } from 'fs/promises';
import { biblatex } from "unicode2latex";
const FILE_URL = 'https://raw.githubusercontent.com/latex3/unicode-math/master/unicode-math-table.tex';
const res = await fetch(FILE_URL);
const text = await res.text();
const symbols = {};
const accents = {};
const lines = text.split('\n');
let numUnicodeMath = 0;
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('%')) continue;
// Match lines like: \UnicodeMathSymbol{"00021}{\mathexclam }{\mathclose}{exclamation mark}%
const match = trimmed.match(/\\UnicodeMathSymbol\{"([0-9A-Fa-f]+)\}\{(\\\w+)\s+\}\{\\(\w+).*/);
if (match) {
const codepointHex = match[1];
const latexCmd = match[2];
const category = match[3];
const char = String.fromCodePoint(parseInt(codepointHex, 16));
if (category === 'mathaccent' || category === 'mathaccentwide') {
if (!accents[char]) {
accents[char] = latexCmd;
numUnicodeMath++;
}
} else {
if (!symbols[char]) {
symbols[char] = latexCmd;
numUnicodeMath++;
}
}
}
}
let numUnicode2Latex = 0;
let numBoth = 0;
for (const [symbol, data] of Object.entries(biblatex.base)) {
if (data.math) {
if (!symbols[symbol]) {
symbols[symbol] = data.math;
numUnicode2Latex++;
} else {
numBoth++;
}
}
}
console.log('Symbols from unicode-math:', numUnicodeMath);
console.log('Symbols from unicode2latex:', numUnicode2Latex);
console.log('Symbols from both (unicode-math preferred):', numBoth);
await writeFile('Common/Unicode.ts', `const UNICODE_MATH = ${JSON.stringify({
accents,
symbols
})};\n`);