Mathjax typesetting not adding aria label to the mjx-container element

72 views
Skip to first unread message

Ron George Pile

unread,
Dec 13, 2023, 2:41:13 PM12/13/23
to mathja...@googlegroups.com
I'm using Mathjax from the tex-svg cdn of version 4.0.0.beta.4, but I've faced some inconsistency with typesetting. 

Whenever I typeset Math with MathJax.tex2svg() function, an aria-label gets added to the mjx-container element. This is useful for me because screen readers can automatically read this along with the text surrounding it.  However, when I typeset through ` await MathJax.typesetPromise()` or have an initial page typesetting when Mathjax loads, the mjx-container elements don't have the associated aria labels. Is this the default behavior? Should I add something to my Mathjax configuration?


I've attached screenshots of my Mathjax config. Any help would be appreciated


mjxConfig01.png
mjxConfig02.png

Ron George Pile

unread,
Dec 16, 2023, 7:00:44 AM12/16/23
to MathJax Users
After some digging, I found out that if I removed the "ui/lazy", component, then the typesetting would work as expected. Could someone explain as to why this was the case. I've gone through the Mathjax docs time and again but I'm at my wits end trying to understand this. I preferred to use this component because it promised performance through lazy typesetting, as mentioned in the docs

Best, 
Ron Pile

Davide Cervone

unread,
Dec 18, 2023, 11:24:47 AM12/18/23
to mathja...@googlegroups.com
It turns out that this is a bug.  The lazy extension requires the math on the page to be processed twice:  once to identify the math on the page, but not to typeset it, and once when it comes into view.  MathJax records the actions that have been taken for each math item (and for the document as a whole), so that they won't be repeated when new math is processed on the page.  The lady extension resets the "state" of the page when math needs to be reprocessed for actual typesetting. When the state is reset, the various actions are supposed to be reset as well.  The "attach-speech" action, however, was not being properly reset, and because the initial pass over the math doesn't typeset it, there was no speech text to attach, and the action was being recorded as having been performed, so when the typesetting was actually performed on a subsequent pass, MathJax though the speech was already attached, and so didn't try to do so again.

The actual error is in the a11y/semantic-enrich extension, which isn't resetting the attach-speech flag when the document state is being reset.  I will make a pull request to fix the problem in the next release.  In the meantime, here is a patch that you can use to overcome the problem.  Incorporate the following in your MathJax configuration:

MathJax = {
  startup: {
    ready() {
      const STATE = MathJax._.core.MathItem.STATE;
      MathJax.startup.extendHandler(handler => {
        handler.documentClass = class extends handler.documentClass {
          state(state, restore = false) {
            super.state(state, restore);
            if (state < STATE.ATTACHSPEECH) {
              this.processed.clear('attach-speech');
            }
          }
        }
        return handler;
      });
      MathJax.startup.defaultReady();
    }
  }
}

This will take care of resetting the attach-speech action when the state it reset, so that the correct speech will be added on the second pass that actually typesets the expression.

See if that doesn't do the trick for you.

Davide



-- 
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathjax-users/b35e91f1-6a71-42ea-8106-e9f17917b8f9n%40googlegroups.com.

Ron George Pile

unread,
Dec 24, 2023, 6:06:12 PM12/24/23
to MathJax Users
This worked like a charm!! Thank you Davide!!

Alex Edgcomb

unread,
Feb 29, 2024, 7:03:07 PMFeb 29
to MathJax Users
Davide,

Might you suggest a similar workaround for alpha.1? Like:

The beta.4 workaround doesn't quite work for alpha.1. Thank you!

Cheers,
Alex

Davide Cervone

unread,
Mar 1, 2024, 12:18:38 PMMar 1
to mathja...@googlegroups.com
It looks like the issue occurs when the menu handler tries to instantiate the document, but I really don't see why.

But if you add ", 20" to the extendHandler() call, that should cause the new handler to be the last one added, and that seems to work for me.  So use

MathJax = {
  startup: {
    ready() {
      const STATE = MathJax._.core.MathItem.STATE;
      MathJax.startup.extendHandler(handler => {
        handler.documentClass = class extends handler.documentClass {
          state(state, restore = false) {
            super.state(state, restore);
            if (state < STATE.ATTACHSPEECH) {
              this.processed.clear('attach-speech');
            }
          }
        }
        return handler;
      }, 20);
      MathJax.startup.defaultReady();
    }
  }
}

and see if that works for you.

Davide

--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages