Way to force MathJax.tex2svgPromise to return a SVG output instead of CHTML?

8 views
Skip to first unread message

Brian Richwine

unread,
Jan 20, 2026, 2:10:24 AMJan 20
to MathJax Development
Hi,

I'm enjoying MathJax 4.1.0! 

Is there a way to get tex2svgPromise to always render svg output without altering the user's settings in local storage before initializing MathJax?

I'm using the window.MathJax.tex2svgPromise(tex, options) function from a web page and expected it to always return a container with one or more SVGs in it. However, the user's settings from other pages on the site apparently override my config and unexpectedly, tex2svgPromise is returning a container with CHTML rendering:

chtml_from_tex2svgPromise.png

Here is the URL I'm loading and the config I'm using.

    window.MathJax = {
      loader: { load: ["[tex]/mhchem"] },
      tex: { packages: { "[+]": ["mhchem"] } },
      svg: { fontCache: "none" },
      options: {
        enableMenu: false,
        menuOptions: {
          settings: {
            renderer: "SVG",
            enrich: false,
            speech: false,
            braille: false,
            collapsible: false,
            assistiveMml: false,
          },
        },
      },
    };

Thanks for any help!

Brian Richwine

unread,
Jan 20, 2026, 12:32:55 PMJan 20
to MathJax Development
I've read through the documentation and am left wondering:
  • What's the relationship between start.output and options.menuOptions.settings.renderer when used in the MathJax config
  • How do I know if a change I'm making to a MathJax object/setting affects the user's sticky/persistent settings? I'd like to avoid changing their settings as well as avoid their settings.
  • If I create a new MathJax document, is that isolated from the user's sticky settings (immune and I cannot change their settings)?
I guess I'm wondering how I can create a web app that runs MathJax in the browser but doesn't want the user to have affect over MathJax settings nor should the app alter their settings. 

Sorry for all the questions. If you don't have time to answer them I understand.

-Brian

Davide Cervone

unread,
Jan 21, 2026, 7:58:03 AM (14 days ago) Jan 21
to mathj...@googlegroups.com
Is there a way to get tex2svgPromise to always render svg output without altering the user's settings in local storage before initializing MathJax?

You are correct that tex2svgPromise() will produce whatever format is currently set in the MathJax.startup.document, so if the user changes that via the contextual menu, it will not produce the expected format.

Here is a configuration that you can use to make sure it does produce SVG output:

  MathJax = {
    startup: {
      ready() {
        MathJax.startup.defaultReady();
        MathJax.tex2svgPromise = (math, options) => {
          return MathJax.whenReady(() => {
            const doc = MathJax.startup.document;
            const jax = doc.outputJax
            doc.outputJax = doc.menu.jax.SVG;
            return doc.convertPromise(math, { ...options, format: 'TeX' })
              .then((svg) => {doc.outputJax = jax; return svg})
              .catch((err) => {doc.outputJax = jax; throw err});
          });
        }
      }
    }
  }

There is one potential pitfall, here, which is that if the SVG processing requires a dynamically loaded file (like a TeX extension or a font data file), and the user switches the renderer while MathJax is waiting for that component to load, then the result would be using the newly selected renderer (and the renderer would be reset afterward, losing the user's changed setting).  That is unlikely to occur, but is a possibility.  If you need to prevent that, it could be done with a bit more work.

Davide

Davide Cervone

unread,
Jan 21, 2026, 8:27:01 AM (14 days ago) Jan 21
to mathj...@googlegroups.com
  • What's the relationship between start.output and options.menuOptions.settings.renderer when used in the MathJax config
MathJax.startup.output will be the renderer in force when MatghJax starts up.  Usually that is the renderer selected by the component loaded (e.g., SVG for tex-sig.js), but it will be the  option.menuIOptions.settings.renderer instance if that option is set, unless the user has previously changed the renderer using the contextual menu and reloaded the page, in which case it will be the user's selected renderer.  So the upshot is, MathJax.startup.output will be the user's selected renderer when the page is loaded (if they changed it), otherwise it will be the renderer from the menuOptions.settings, if there is one specified, otherwise it will be the default renderer from the components that are loaded.

  • How do I know if a change I'm making to a MathJax object/setting affects the user's sticky/persistent settings? I'd like to avoid changing their settings as well as avoid their settings.
User menu settings will override your menuOptions settings if they make changes via the contextual menu.  The user's settings are saved by the menu code, and that only occurs when the user changes a menu setting.  In general, your settings won't be saved unless you change MathJax.startup.document.menu.options on the fly (don't do that), and the user makes a change to some other menu settings themselves.

  • If I create a new MathJax document, is that isolated from the user's sticky settings (immune and I cannot change their settings)?
It is possible to create a new MathDocument using new instances of input and output jax, and load include the menu code.  It would even be possible to share the input jax with he original document, so that definitions, equation numbers, etc. would be shared.  But you would not be able to use MathJax.tex2svgPromise or the other MathJax methods, as those are tied to the original document, so you would have to call the new document's convertPromise() method directly.  I haven't done it, but it could probably be made to work.

I guess I'm wondering how I can create a web app that runs MathJax in the browser but doesn't want the user to have affect over MathJax settings nor should the app alter their settings. 

I'm a little unclear about what you want.  When would be user's settings be used, then?  Why have user settings at all in this case?  If you are ignoring their settings, why are you concerned about altering them?

Davide


Reply all
Reply to author
Forward
0 new messages