import { Argument , defineFunction } from './definitions-utils' ; import type { Atom , ToLatexOptions } from '../core/atom-class' ; import { OperatorAtom } from '../core-atoms/operator' ; import { SurdAtom } from '../core-atoms/surd' ; import { GenfracAtom , GenfracOptions } from '../core-atoms/genfrac' ; import { DelimAtom } from '../core-atoms/delim' ; import { Style } from '../public/core' ; defineFunction ( [ 'arccos' , 'arcsin' , 'arctan' , 'arctg' , 'arcctg' , 'arg' , 'ch' , 'cos' , 'cosh' , 'cot' , 'coth' , 'ctg' , 'cth' , 'cotg' , 'csc' , 'cosec' , 'deg' , 'dim' , 'exp' , 'hom' , 'inf' , 'ker' , 'lg' , 'lb' , 'lg' , 'ln' , 'log' , 'Pr' , 'sec' , 'sh' , 'sin' , 'sinh' , 'sup' , 'tan' , 'tanh' , 'tg' , 'th' , ] , '' , { isFunction : true , createAtom : ( command , _args , style ) : Atom => new OperatorAtom ( command , command . slice ( 1 ) , { limits : 'adjacent' , isFunction : true , variant : 'main' , variantStyle : 'up' , style , } ) , } ) ; defineFunction ( [ 'liminf' , 'limsup' ] , '' , { createAtom : ( command , _args , style ) : Atom => new OperatorAtom ( command , { '\\liminf' : 'lim inf' , '\\limsup' : 'lim sup' } [ command ] ! , { limits : 'over-under' , variant : 'main' , style , } ) , } ) ; defineFunction ( [ 'lim' , 'mod' ] , '' , { createAtom : ( command , _args , style ) : Atom => new OperatorAtom ( command , command . slice ( 1 ) , { limits : 'over-under' , variant : 'main' , style , } ) , } ) ; defineFunction ( [ 'det' , 'max' , 'min' ] , '' , { isFunction : true , createAtom : ( command , _args , style ) : Atom => new OperatorAtom ( command , command . slice ( 1 ) , { limits : 'over-under' , isFunction : true , variant : 'main' , style , } ) , } ) ; defineFunction ( 'sqrt' , '[index:auto]{radicand:auto}' , { createAtom : ( command , args , style ) : Atom => new SurdAtom ( command , { body : args [ 1 ] as Atom [ ] , index : args [ 0 ] as Atom [ ] , style , } ) , } ) ; defineFunction ( [ 'frac' , 'dfrac' , 'tfrac' , 'cfrac' , 'binom' , 'dbinom' , 'tbinom' ] , '{numerator}{denominator}' , { createAtom : ( command , args , style ) : Atom => { const options = { style , } ; switch ( command ) { case '\\dfrac' : case '\\frac' : case '\\tfrac' : options . hasBarLine = true ; break ; case '\\atopfrac' : options . hasBarLine = false ; break ; case '\\dbinom' : case '\\binom' : case '\\tbinom' : options . hasBarLine = false ; options . leftDelim = '(' ; options . rightDelim = ')' ; break ; default : } switch ( command ) { case '\\dfrac' : case '\\dbinom' : options . mathstyleName = 'displaystyle' ; break ; case '\\tfrac' : case '\\tbinom' : options . mathstyleName = 'textstyle' ; break ; case '\\cfrac' : options . hasBarLine = true ; options . continuousFraction = true ; break ; default : } return new GenfracAtom ( command , args [ 0 ] as Atom [ ] , args [ 1 ] as Atom [ ] , options ) ; } , } ) ; defineFunction ( [ 'over' , 'atop' , 'choose' ] , '' , { infix : true , createAtom : ( command , args , style ) : Atom => { let leftDelim = undefined ; let rightDelim = undefined ; if ( command === '\\choose' ) { leftDelim = '(' ; rightDelim = ')' ; } return new GenfracAtom ( command , args [ 0 ] as Atom [ ] , args [ 1 ] as Atom [ ] , { hasBarLine : command === '\\over' , leftDelim , rightDelim , style , serialize : ( atom , options ) => `{${ atom . aboveToLatex ( options ) }${ atom . command } ${ atom . belowToLatex ( options ) }}` , } ) ; } , } ) ; defineFunction ( 'pdiff' , '{numerator}{denominator}' , { createAtom : ( command , args , style ) : Atom => new GenfracAtom ( command , args [ 0 ] as Atom [ ] , args [ 1 ] as Atom [ ] , { hasBarLine : true , numerPrefix : '\u2202' , denomPrefix : '\u2202' , style , } ) , } ) ; defineFunction ( [ 'sum' , 'prod' , 'bigcup' , 'bigcap' , 'coprod' , 'bigvee' , 'bigwedge' , 'biguplus' , 'bigotimes' , 'bigoplus' , 'bigodot' , 'bigsqcup' , 'smallint' , 'intop' , ] , '' , { createAtom : ( command , args , style ) : Atom => new OperatorAtom ( command , { coprod : '\u2210' , bigvee : '\u22C1' , bigwedge : '\u22C0' , biguplus : '\u2A04' , bigcap : '\u22C2' , bigcup : '\u22C3' , intop : '\u222B' , prod : '\u220F' , sum : '\u2211' , bigotimes : '\u2A02' , bigoplus : '\u2A01' , bigodot : '\u2A00' , bigsqcup : '\u2A06' , smallint : '\u222B' , } [ command . slice ( 1 ) ] ! , { isExtensibleSymbol : true , limits : 'auto' , variant : 'main' , style , } ) , } ) ; const EXTENSIBLE_SYMBOLS = { int : '\u222B' , iint : '\u222C' , iiint : '\u222D' , oint : '\u222E' , oiint : '\u222F' , oiiint : '\u2230' , intclockwise : '\u2231' , varointclockwise : '\u2232' , ointctrclockwise : '\u2233' , intctrclockwise : '\u2A11' , sqcup : '\u2294' , sqcap : '\u2293' , uplus : '\u228E' , wr : '\u2240' , amalg : '\u2A3F' , Cap : '\u22D2' , Cup : '\u22D3' , doublecap : '\u22D2' , doublecup : '\u22D3' , } ; defineFunction ( Object . keys ( EXTENSIBLE_SYMBOLS ) , '' , { createAtom : ( command , _args , style ) : Atom => new OperatorAtom ( command , EXTENSIBLE_SYMBOLS [ command . slice ( 1 ) ] , { limits : 'adjacent' , isExtensibleSymbol : true , style , variant : { '\u22D2' : 'ams' , '\u22D3' : 'ams' } [ EXTENSIBLE_SYMBOLS [ command . slice ( 1 ) ] ] , } ) , } ) ; defineFunction ( [ 'Re' , 'Im' ] , '' , { createAtom : ( command , _args , style ) : Atom => new OperatorAtom ( command , { '\\Re' : '\u211C' , '\\Im' : '\u2111' } [ command ] ! , { limits : 'adjacent' , style , isFunction : true , variant : 'fraktur' , } ) , } ) ; defineFunction ( 'middle' , '{:delim}' , { createAtom : ( command , args , style ) : Atom => new DelimAtom ( command , args [ 0 ] as string , { size : 1 , style } ) , } ) ;