11import { isArray } from '../common/types' ;
22
3- import type { Atom } from '../core/atom' ;
3+ import { Atom } from '../core/atom' ;
44import { GenfracAtom } from '../atoms/genfrac' ;
55import { LeftRightAtom } from '../atoms/leftright' ;
66import { 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 ( / { ? \\ c h a r " ( [ \d a b c d e f A B C D E F ] + ) } ? / ) : 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 ) ;
0 commit comments