Skip to content

Commit 35d7ccc

Browse files
committed
test
1 parent b04f223 commit 35d7ccc

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/editor/shortcuts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function validateShortcut(
102102
export function getInlineShortcut(
103103
context: null | Atom[],
104104
s: string,
105-
shortcuts?: InlineShortcutDefinitions
105+
shortcuts: InlineShortcutDefinitions | undefined
106106
): string {
107107
if (!shortcuts) return '';
108108
return validateShortcut(context, shortcuts[s]);

src/formats/atom-to-ascii-math.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isArray } from '../common/types';
22

3-
import type { Atom } from '../core/atom';
3+
import { Atom } from '../core/atom';
44
import { GenfracAtom } from '../atoms/genfrac';
55
import { LeftRightAtom } from '../atoms/leftright';
66
import { ArrayAtom } from '../atoms/array';
@@ -61,10 +61,15 @@ const IDENTIFIERS = {
6161
'\\quad': ' ',
6262
'\\infty': 'oo',
6363
'\\R': 'RR',
64+
'\\mathbb{R}': 'RR',
6465
'\\N': 'NN',
66+
'\\mathbb{N}': 'NN',
6567
'\\Z': 'ZZ',
68+
'\\mathbb{Z}': 'ZZ',
6669
'\\Q': 'QQ',
70+
'\\mathbb{Q}': 'QQ',
6771
'\\C': 'CC',
72+
'\\mathbb{C}': 'CC',
6873
'\\emptyset': 'O/',
6974
'\\varnothing': 'O/',
7075
'\\varDelta': 'Delta',
@@ -210,6 +215,11 @@ export function atomToAsciiMath(
210215
if (command === '\\placeholder')
211216
return `(${atomToAsciiMath(atom.body, options)})`;
212217

218+
const latex = Atom.serialize([atom], {
219+
expandMacro: false,
220+
defaultMode: 'math',
221+
});
222+
213223
switch (atom.type) {
214224
case 'accent':
215225
const accent = {
@@ -314,9 +324,11 @@ export function atomToAsciiMath(
314324
break;
315325

316326
case 'mord':
327+
if (IDENTIFIERS[latex]) return IDENTIFIERS[latex!];
317328
result =
318329
IDENTIFIERS[command!] ??
319330
command ??
331+
command ??
320332
(typeof atom.value === 'string' ? atom.value : '');
321333
if (result.startsWith('\\')) result += ' ';
322334
m = command ? command.match(/{?\\char"([\dabcdefABCDEF]+)}?/) : null;
@@ -337,7 +349,11 @@ export function atomToAsciiMath(
337349
case 'mbin':
338350
case 'mrel':
339351
case 'minner':
340-
result = IDENTIFIERS[command!] ?? OPERATORS[command!] ?? atom.value;
352+
result =
353+
IDENTIFIERS[latex] ??
354+
IDENTIFIERS[command!] ??
355+
OPERATORS[command!] ??
356+
atom.value;
341357
break;
342358

343359
case 'mopen':
@@ -400,7 +416,7 @@ export function atomToAsciiMath(
400416
break;
401417

402418
case 'spacing':
403-
result = IDENTIFIERS[command] ?? ' ';
419+
result = IDENTIFIERS[latex] ?? IDENTIFIERS[command] ?? ' ';
404420
break;
405421

406422
case 'enclose':
@@ -417,6 +433,7 @@ export function atomToAsciiMath(
417433

418434
case 'macro':
419435
result =
436+
IDENTIFIERS[latex] ??
420437
IDENTIFIERS[command] ??
421438
OPERATORS[command] ??
422439
atomToAsciiMath(atom.body, options);

test/smoke/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ <h1>Smoke Test</h1>
4141
</ul>
4242
</header>
4343
<main>
44-
<math-field id="mf">\ddot{x}=\dddot{x}=\ddddot{x}=\vec{x}</math-field>
45-
<!-- <math-field id="mf">\begin{align}a + 1 & b + 234 \\ c + 1234 & d + 12345\end{align}</math-field> -->
44+
<math-field id="mf">\begin{align}a + 1 & b + 234 \\ c + 1234 & d + 12345\end{align}</math-field>
4645

4746
<!-- <math-field id="mf">a+\begin{matrix}[lc]x+1&2\\4&a+b+c+1234\end{matrix}+\alpha</math-field> -->
4847

0 commit comments

Comments
 (0)