import { Atom , ToLatexOptions } from '../core/atom-class' ; import { Box , BoxType , makeSVGBox } from '../core/box' ; import { VBox } from '../core/v-box' ; import { Context , PrivateStyle } from '../core/context' ; import { makeNullDelimiter } from '../core/delimiters' ; export class OverunderAtom extends Atom { svgAbove ? : string ; svgBelow ? : string ; svgBody ? : string ; boxType : BoxType ; padded ? : boolean ; constructor ( command , options ) { super ( 'overunder' , { command , serialize : options . serialize , style : options . style , } ) ; this . skipBoundary = options . skipBoundary ?? true ; this . subsupPlacement = options . supsubPlacement ; this . body = options . body ; this . svgAbove = options . svgAbove ; this . svgBelow = options . svgBelow ; this . svgBody = options . svgBody ; this . above = options . above ; this . below = options . below ; this . boxType = options . boxType ?? 'mord' ; this . padded = options . padded ?? false ; } /**
     * Combine a base with an atom above and an atom below.
     *
     * See http://tug.ctan.org/macros/latex/required/amsmath/amsmath.dtx
     *
     * > \newcommand{\overset}[2]{\binrel@{#2}%
     * > \binrel@@{\mathop{\kern\z@#2}\limits^{#1}}}
     *
     */ render ( parentContext ) { let body = this . svgBody ? makeSVGBox ( this . svgBody ) : Atom . createBox ( parentContext , this . body , { newList : true } ) ; const annotationContext = new Context ( parentContext , this . style , 'scriptstyle' ) ; let above = null ; if ( this . svgAbove ) { above = makeSVGBox ( this . svgAbove ) ; } else if ( this . above ) { above = Atom . createBox ( annotationContext , this . above , { newList : true } ) ; } let below = null ; if ( this . svgBelow ) { below = makeSVGBox ( this . svgBelow ) ; } else if ( this . below ) { below = Atom . createBox ( annotationContext , this . below , { newList : true } ) ; } if ( this . padded ) { body = new Box ( [ makeNullDelimiter ( parentContext , 'mopen' ) , body , makeNullDelimiter ( parentContext , 'mclose' ) , ] , { newList : true } ) ; } let base = makeOverunderStack ( parentContext , { base : body , above , below , type : this . boxType === 'mbin' || this . boxType === 'mrel' ? this . boxType : 'mord' , } ) ; if ( ! base ) return null ; if ( this . subsupPlacement === 'over-under' ) { base = this . attachLimits ( parentContext , { base , type : base . type } ) ; } else { base = this . attachSupsub ( parentContext , { base } ) ; } if ( this . caret ) base . caret = this . caret ; return this . bind ( parentContext , base ) ; } } param nucleus param type function makeOverunderStack ( context , options ) { if ( ! options . base ) return null ; if ( ! options . above && ! options . below ) { const box = new Box ( options . base , { type : options . type } ) ; box . setStyle ( 'position' , 'relative' ) ; return box ; } let aboveShift = 0 ; if ( options . above ) { aboveShift = - options . above . depth + context . metrics . bigOpSpacing2 ; } let result = null ; const base = options . base ; const baseShift = 0 ; if ( options . below && options . above ) { const bottom = context . metrics . bigOpSpacing5 + options . below . height + options . below . depth + base . depth + baseShift ; result = new VBox ( { bottom , children : [ context . metrics . bigOpSpacing5 , { box : options . below , classes : [ 'ML__center' ] } , { box : base , classes : [ 'ML__center' ] } , aboveShift , { box : options . above , classes : [ 'ML__center' ] } , context . metrics . bigOpSpacing5 , ] , } ) ; } else if ( options . below ) { result = new VBox ( { top : base . height - baseShift , children : [ context . metrics . bigOpSpacing5 , { box : options . below , classes : [ 'ML__center' ] } , { box : base , classes : [ 'ML__center' ] } , ] , } ) ; } else if ( options . above ) { result = new VBox ( { bottom : base . depth + baseShift , children : [ { box : base , classes : [ 'ML__center' ] } , aboveShift , { box : options . above , classes : [ 'ML__center' ] } , context . metrics . bigOpSpacing5 , ] , } ) ; } return new Box ( result , { type : options . type } ) ; }