import type { RemoteVirtualKeyboardOptions , TextToSpeechOptions , } from './public/options' ; import type { ErrorListener , ParserErrorCode , MathfieldErrorCode , MacroDictionary , Registers , } from './public/core' ; import { Atom } from './core/atom-class' ; import { parseLatex } from './core/parser' ; import { adjustInterAtomSpacing , coalesce , makeStruts , Box } from './core/box' ; import { getMacros } from './core-definitions/definitions' ; import { AutoRenderOptionsPrivate , autoRenderMathInElement , } from './addons/auto-render' ; import MathLiveDebug , { asciiMathToLatex , latexToAsciiMath , } from './addons/debug' ; import { atomToSpeakableText } from './editor/atom-to-speakable-text' ; import { atomsToMathML } from './addons/math-ml' ; import './addons/definitions-metadata' ; import './editor/virtual-keyboard-commands' ; import { RemoteVirtualKeyboard } from './editor-mathfield/remote-virtual-keyboard' ; import { Context } from './core/context' ; import { DEFAULT_FONT_SIZE } from './core/font-metrics' ; import { l10n } from './editor/l10n' ; import { typeset } from './core/typeset' ; import { getDefaultRegisters } from './core/registers' ; import { isBrowser , throwIfNotInBrowser } from './common/capabilities' ; export { MathfieldElement } from './public/mathfield-element' ; import { version as computeEngineVersion } from '@cortex-js/compute-engine' ; export { serialize as serializeMathJson , parse as parseMathJson , } from '@cortex-js/compute-engine' ; export function makeSharedVirtualKeyboard ( options ) { new RemoteVirtualKeyboard ( options ) ; } export function convertLatexToMarkup ( text , options ? ) { options = options ?? { } ; options . mathstyle = options . mathstyle ?? 'displaystyle' ; let letterShapeStyle = options . letterShapeStyle ?? 'auto' ; if ( letterShapeStyle === 'auto' ) { letterShapeStyle = l10n . locale ! . startsWith ( 'fr' ) ? 'french' : 'tex' ; } options . macros = getMacros ( options ?. macros ) ; const root = new Atom ( 'root' , { mode : 'math' } ) ; root . body = typeset ( parseLatex ( text , { parseMode : 'math' , macros : options . macros , registers : options . registers , mathstyle : options . mathstyle , onError : options . onError , colorMap : options . colorMap , backgroundColorMap : options . backgroundColorMap , } ) , { registers : options . registers } ) ; const box = root . render ( new Context ( { macros : options . macros , registers : getDefaultRegisters ( ) , smartFence : false , renderPlaceholder : ( ) => new Box ( 0xa0 , { maxFontSize : 1.0 } ) , } , { fontSize : DEFAULT_FONT_SIZE , letterShapeStyle : letterShapeStyle , } , options . mathstyle ) ) ; if ( ! box ) return '' ; adjustInterAtomSpacing ( box ) ; coalesce ( box ) ; const wrapper = makeStruts ( box , { classes : 'ML__mathlive' } ) ; return wrapper . toMarkup ( ) ; } export function convertLatexToMathMl ( latex , options = { } ) { options . macros = getMacros ( options ?. macros ) ; return atomsToMathML ( parseLatex ( latex , { parseMode : 'math' , args : ( ) => '' , macros : options . macros , registers : options . registers , mathstyle : 'displaystyle' , onError : options . onError , colorMap : options . colorMap , backgroundColorMap : options . backgroundColorMap , } ) , options ) ; } export function convertLatexToSpeakableText ( latex , options = { } ) { options . macros = getMacros ( options ?. macros ) ; const atoms = parseLatex ( latex , { parseMode : 'math' , macros : options . macros , registers : options . registers , mathstyle : 'displaystyle' , onError : options . onError , colorMap : options . colorMap , backgroundColorMap : options . backgroundColorMap , } ) ; return atomToSpeakableText ( atoms , options as Required < TextToSpeechOptions > ) ; } export function renderMathInDocument ( options ? ) { throwIfNotInBrowser ( ) ; renderMathInElement ( document . body , options ) ; } function getElement ( element ) { if ( typeof element === 'string' && isBrowser ( ) ) { const result = document . getElementById ( element ) ; if ( result === null ) { throw new Error ( `The element with ID "${ element }" could not be found.` ) ; } return result ; } return typeof element === 'string' ? null : element ; } export function renderMathInElement ( element , options ? ) { const el = getElement ( element ) ; if ( ! el ) return ; options = options ?? { } ; options . renderToMarkup = options . renderToMarkup ?? convertLatexToMarkup ; options . renderToMathML = options . renderToMathML ?? convertLatexToMathMl ; options . renderToSpeakableText = options . renderToSpeakableText ?? convertLatexToSpeakableText ; autoRenderMathInElement ( el , options ) ; } export const version = { mathlive : '{{SDK_VERSION}}' , computeEngine : computeEngineVersion , } ; export const debug = { latexToAsciiMath , asciiMathToLatex , FUNCTIONS : MathLiveDebug . FUNCTIONS , MATH_SYMBOLS : MathLiveDebug . MATH_SYMBOLS , TEXT_SYMBOLS : MathLiveDebug . TEXT_SYMBOLS , ENVIRONMENTS : MathLiveDebug . ENVIRONMENTS , DEFAULT_KEYBINDINGS : MathLiveDebug . DEFAULT_KEYBINDINGS , getKeybindingMarkup : MathLiveDebug . getKeybindingMarkup , } ;