import { Atom , ToLatexOptions } from '../core/atom-class' ; import { Box } from '../core/box' ; import { Context } from '../core/context' ; import { convertGlueToEm } from '../core/registers-utils' ; import { Glue , Style } from '../public/core' ; export class SpacingAtom extends Atom { private readonly width ? : Glue ; constructor ( command , style , width ? ) { super ( 'spacing' , { command , style } ) ; this . width = width ; } render ( _context ) { let result ; if ( this . width ) { result = new Box ( null , { classes : 'mspace' } ) ; result . left = convertGlueToEm ( this . width ) ; } else { const spacingCls = { '\\qquad' : 'qquad' , '\\quad' : 'quad' , '\\enspace' : 'enspace' , '\\;' : 'thickspace' , '\\:' : 'mediumspace' , '\\,' : 'thinspace' , '\\!' : 'negativethinspace' , } [ this . command ! ] ?? 'mediumspace' ; result = new Box ( null , { classes : spacingCls } ) ; } if ( this . caret ) result . caret = this . caret ; return result ; } serialize ( _options ) { let result = this . command ?? '' ; if ( this . command === '\\hspace' || this . command === '\\hspace*' ) { if ( Number . isFinite ( this . width ) ) { result += `{${ this . width }em'}` ; } else { result += `{0pt}` ; } } else { if ( Number . isFinite ( this . width ) ) { result += ` ${ this . width }em` ; } } return result ; } }