Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
arnog committed Jan 29, 2025
1 parent b04f223 commit 35d7ccc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/editor/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
23 changes: 20 additions & 3 deletions src/formats/atom-to-ascii-math.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand All @@ -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':
Expand Down Expand Up @@ -400,7 +416,7 @@ export function atomToAsciiMath(
break;

case 'spacing':
result = IDENTIFIERS[command] ?? ' ';
result = IDENTIFIERS[latex] ?? IDENTIFIERS[command] ?? ' ';
break;

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

case 'macro':
result =
IDENTIFIERS[latex] ??
IDENTIFIERS[command] ??
OPERATORS[command] ??
atomToAsciiMath(atom.body, options);
Expand Down
3 changes: 1 addition & 2 deletions test/smoke/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ <h1>Smoke Test</h1>
</ul>
</header>
<main>
<math-field id="mf">\ddot{x}=\dddot{x}=\ddddot{x}=\vec{x}</math-field>
<!-- <math-field id="mf">\begin{align}a + 1 & b + 234 \\ c + 1234 & d + 12345\end{align}</math-field> -->
<math-field id="mf">\begin{align}a + 1 & b + 234 \\ c + 1234 & d + 12345\end{align}</math-field>

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

Expand Down

0 comments on commit 35d7ccc

Please sign in to comment.