Configuring MathJax's SRE After it is Loaded in 4.0.0-beta.6

5 views
Skip to first unread message

Brian Richwine

unread,
Jun 18, 2024, 4:37:41 PMJun 18
to MathJax Development
Hi, I have a web application that allows users to get speech text from LaTeX, MathML, or AsciiMath. It allows users to select their desired SRE settings (domain, style, language, etc.) and then click "Convert" to get their input rendered by MathJax and to receive the speech text from the SRE: https://brichwin.pages.iu.edu/altMediaTools/m2st/math-to-speech-text.html

It works with MathJax version: 4.0.0-beta.3, but when I updated to MathJax version: 4.0.0-beta.6 I am having trouble programmatically configuring the SRE as each call to window.MathJax.typeset([containerElement]) appears to overwrite any changes to the SRE config with the MathJax menu settings.

I tried updating MathJax.config.options.sre.domain and related properties and then calling MathJax.startup.getComponents() instead of just calling window.MathJax._.a11y.sre.Sre.setupEngine(sreConfig) however the MathJax menu settings prevailed.

I need to be able to set the domain and style (e.g. domain:'clearspeak', style:'Fraction_GeneralEndFrac:Roots_RootEnd:Paren_Speak:AbsoluteValue_AbsEnd') as end users find setting the clearspeak preferences using the menu too confusing and cumbersome.

Is this still possible?

Thanks!
  Brian

Brian Richwine

unread,
Jun 18, 2024, 6:59:49 PMJun 18
to MathJax Development
Hi, again-

Is it expected that a call to mathml = MathJax.tex2mml(math_str, {display: true}) would reset the sreEngine's config to the settings in the MathJax menu?

If I do this:
    window.MathJax._.a11y.sre.Sre.setupEngine(sreConfig).then(() => {
        mathml = MathJax.tex2mml(math_str, {display: true})
        window.MathJax._.a11y.sre.Sre.sreReady().then(() => {
            console.log(window.MathJax._.a11y.sre.Sre.engineSetup())
            ASCIIout.innerText = window.MathJax._.a11y.sre.Sre.toSpeech(mathml)
            setTimeout(copyMostRecent, 100)
        })
    })
The speech text generated is according to the MathJax menu settings instead of the config in the sreConfig object. However, the following works as expected.
    mathml = MathJax.tex2mml(math_str, {display: true})
    window.MathJax._.a11y.sre.Sre.setupEngine(sreConfig).then(() => {
        window.MathJax._.a11y.sre.Sre.sreReady().then(() => {
            console.log(window.MathJax._.a11y.sre.Sre.engineSetup())
            ASCIIout.innerText = window.MathJax._.a11y.sre.Sre.toSpeech(mathml)
            setTimeout(copyMostRecent, 100)
        })
    })

Regardless, I got my app to work. Just thought this was an unexpected byproduct of of calling tex2mml.

Thanks for your great work!

Davide Cervone

unread,
Jun 21, 2024, 1:02:06 PMJun 21
to mathj...@googlegroups.com
> It works with MathJax version: 4.0.0-beta.3, but when I updated to MathJax version: 4.0.0-beta.6 I am having trouble programmatically configuring the SRE as each call to window.MathJax.typeset([containerElement]) appears to overwrite any changes to the SRE config with the MathJax menu settings.

Yes, SRE is reinitialized for every math item, which is probably a bit of overkill. While currently there is a single SRE instance, we anticipate having individual SRE instances on at least a document level, if not an expression level. That initialization of SRE was probably in anticipation of that (though it is not code that I wrote, so may be wrong about that).

> I tried updating MathJax.config.options.sre.domain and related properties and then calling MathJax.startup.getComponents() instead of just calling window.MathJax._.a11y.sre.Sre.setupEngine(sreConfig) however the MathJax menu settings prevailed.

The MathJax.config object is only used to initialize objects (like the MathDocument and the input and output jax), when they are created, and is not used after that, as the individual objects contain their own options objects. You would need to modify the MathJax.startup.document.options.sre object instead (and that is what I was going to recommend). This one is a bit complicated because it is also modified by the contextual menu code as the user matches changes to the menu items for the assistive tools, but for your example page, it might be sufficient and the menu can be ignored (or you could disable the contextual menu entirely). If you need to keep the menu in sync with the SRE settings, that can be done, but is more delicate.

Davide

Reply all
Reply to author
Forward
0 new messages