diff --git a/src/editor/shortcuts.ts b/src/editor/shortcuts.ts index 8d96e6be6..e68762c15 100644 --- a/src/editor/shortcuts.ts +++ b/src/editor/shortcuts.ts @@ -102,7 +102,7 @@ function validateShortcut( export function getInlineShortcut( context: null | Atom[], s: string, - shortcuts?: InlineShortcutDefinitions + shortcuts: InlineShortcutDefinitions | undefined ): string { if (!shortcuts) return ''; return validateShortcut(context, shortcuts[s]); diff --git a/src/formats/atom-to-ascii-math.ts b/src/formats/atom-to-ascii-math.ts index 7a098a8fc..352cd4946 100644 --- a/src/formats/atom-to-ascii-math.ts +++ b/src/formats/atom-to-ascii-math.ts @@ -1,6 +1,6 @@ import { isArray } from '../common/types'; -import type { Atom } from '../core/atom'; +import { Atom } from '../core/atom'; import { GenfracAtom } from '../atoms/genfrac'; import { LeftRightAtom } from '../atoms/leftright'; import { ArrayAtom } from '../atoms/array'; @@ -61,10 +61,15 @@ const IDENTIFIERS = { '\\quad': ' ', '\\infty': 'oo', '\\R': 'RR', + '\\mathbb{R}': 'RR', '\\N': 'NN', + '\\mathbb{N}': 'NN', '\\Z': 'ZZ', + '\\mathbb{Z}': 'ZZ', '\\Q': 'QQ', + '\\mathbb{Q}': 'QQ', '\\C': 'CC', + '\\mathbb{C}': 'CC', '\\emptyset': 'O/', '\\varnothing': 'O/', '\\varDelta': 'Delta', @@ -210,6 +215,11 @@ export function atomToAsciiMath( if (command === '\\placeholder') return `(${atomToAsciiMath(atom.body, options)})`; + const latex = Atom.serialize([atom], { + expandMacro: false, + defaultMode: 'math', + }); + switch (atom.type) { case 'accent': const accent = { @@ -314,9 +324,11 @@ export function atomToAsciiMath( break; case 'mord': + if (IDENTIFIERS[latex]) return IDENTIFIERS[latex!]; result = IDENTIFIERS[command!] ?? command ?? + command ?? (typeof atom.value === 'string' ? atom.value : ''); if (result.startsWith('\\')) result += ' '; m = command ? command.match(/{?\\char"([\dabcdefABCDEF]+)}?/) : null; @@ -337,7 +349,11 @@ export function atomToAsciiMath( case 'mbin': case 'mrel': case 'minner': - result = IDENTIFIERS[command!] ?? OPERATORS[command!] ?? atom.value; + result = + IDENTIFIERS[latex] ?? + IDENTIFIERS[command!] ?? + OPERATORS[command!] ?? + atom.value; break; case 'mopen': @@ -400,7 +416,7 @@ export function atomToAsciiMath( break; case 'spacing': - result = IDENTIFIERS[command] ?? ' '; + result = IDENTIFIERS[latex] ?? IDENTIFIERS[command] ?? ' '; break; case 'enclose': @@ -417,6 +433,7 @@ export function atomToAsciiMath( case 'macro': result = + IDENTIFIERS[latex] ?? IDENTIFIERS[command] ?? OPERATORS[command] ?? atomToAsciiMath(atom.body, options); diff --git a/test/smoke/index.html b/test/smoke/index.html index 5781d41b9..52769a87e 100644 --- a/test/smoke/index.html +++ b/test/smoke/index.html @@ -41,8 +41,7 @@

Smoke Test

- \ddot{x}=\dddot{x}=\ddddot{x}=\vec{x} - + \begin{align}a + 1 & b + 234 \\ c + 1234 & d + 12345\end{align}