Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Reset to defaults" Menu and Semantic Enrichment #3310

Open
jmegginson opened this issue Nov 19, 2024 · 1 comment
Open

"Reset to defaults" Menu and Semantic Enrichment #3310

jmegginson opened this issue Nov 19, 2024 · 1 comment
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around v4

Comments

@jmegginson
Copy link

Issue Summary

Activating Reset to defaults does not consistently set the MathJax configuration back to the default. When activated, collapsible math or Semantic Enrichment is obtrusively enabled and remains enabled indefinitely.

  1. When "reset to default" is pressed, the collapsible math setting becomes enabled indefinitely (see screenshot below).
  2. If a change is made in the a11y menu or subsequent activation of "reset to default" is pressed, the Math content disappears

Steps to Reproduce:

  1. When the page loads confirm that the default configuration is accurate (via MathJax Menu or via the DOM)
  2. Open the MathJax Math Settings menu and activate "Reset to defaults"
  3. Observe that that collapsible math becomes enabled (and checked in the MathJax Menu)
  4. You can use the console to view the (default config) options as indicated below:

image screenshot of console with collapsible set to false but collapsible math is active in the browser

It is my understanding that resetting to "default" settings via the MathJax menu should always reset to options in the configuration noted below.

Technical details:

  • MathJax Version: 4.0.0-beta.7
  • Math Rendering SVG
  • Windows 10 19045.5131
  • Chrome

I am using the following MathJax configuration via:

<script src="/mathjax/custom-mathjax-config.js" id="MathJax-Config-script"></script>

The Custom Config script contains:

options: {
	a11y:{
		braille: true,
		speech: false, //we generate our own aria-label to match the alttext attribute of math element
		subtitles:false,
		viewBraille: false,
	},
	menuOptions:{
		settings:{
			assistiveMml: true,
			collapsible: false
		}
	}
 
  },

If menuOptions.settings.enrich is set to false within the configuration, the Semantic Enrichment menu item remains enabled along with Collapsible Math when the steps above are followed.

@dpvc dpvc added Accepted Issue has been reproduced by MathJax team v4 labels Nov 20, 2024
@dpvc
Copy link
Member

dpvc commented Nov 20, 2024

OK, I was able to track down the problem, and it is a little bit complicated. When the reset menu item is selected, the menu goes through the settings and tries to return them to their original settings for the page. Unfortunately, the list of original settings turns out to be incomplete (the a11y settings aren't included, because they are actually stored in a different component, and it isn't always available when the menu starts up). When those settings are reset, they end up getting undefined values. One unexpected consequence of that is triggered when the highlight item is reset. Since that value should be one of None, Hover, or Flame, setting it to undefined means that tests for which of those values it is don't work properly. In particular, the Hover and Flame values require the collapsibility extension, and when the highlight value is not None, the menu code loads that. That ends up turning on the collapsible setting, which is why you are seeing it active after the reset.

The issue with the pre-rendering has to do with a promise that is not being properly initialized during the initial typesetting of the page.

Both use issues can be worked around with the following configuration:

MathJax = {
  options: {
    a11y:{
      subtitles: false,
      viewBraille: false,
    },
    menuOptions: {
      settings: {
        braille: true,
        speech: false, //we generate our own aria-label to match the alttext attribute of math element
        enrich: false,
      }
    }
  },
  startup: {
    ready() {
      MathJax.startup.defaultReady();
      MathJax.startup.rerenderPromise = MathJax.startup.promise;
      const menu = MathJax.startup.document.menu;
      menu.defaultSettings = 
        Object.assign({},
          menu.document.options.a11y, 
          MathJax.config.options.a11y,
          menu.defaultSettings
        );
    }
  }
}
</script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.7/tex-svg.js"></script>
</head>
<body>

$$x+y\over z-1$$

</body>
</html>

Note that I have moved the speech and brailleoptions to themenuOptions.settings` block. Although they exist in both options blocks, when the menu code is included in the MathJax component, the menu option takes precedence. That probably needs to be straightened out, but that's the current situation.

I will make a PR to handle both the issues you have raised.

@dpvc dpvc added the Code Example Contains an illustrative code example, solution, or work-around label Nov 20, 2024
dpvc added a commit to mathjax/MathJax-src that referenced this issue Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around v4
Projects
None yet
Development

No branches or pull requests

2 participants