import { Atom , ToLatexOptions } from '../core/atom-class' ; import { Context } from '../core/context' ; import { Box } from '../core/box' ; export class MacroAtom extends Atom { macroLatex : string ; expand : boolean ; constructor ( macro , options ) { super ( 'macro' , { command : macro } ) ; this . body = options . body ; this . captureSelection = options . captureSelection ?? true ; this . macroLatex = macro + options . args ; this . expand = options . expand ?? false ; } serialize ( options ) { return options . expandMacro && this . expand ? this . bodyToLatex ( options ) : this . macroLatex ; } render ( context ) { const result = Atom . createBox ( context , this . body ) ; if ( ! result ) return null ; if ( this . caret ) result . caret = this . caret ; return this . bind ( context , result ) ; } }