Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ts/a11y/explorer/KeyExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ export class SpeechExplorer
creating an SVG version of the expression, and viewing various other
information.</p>

<p>Finally, selecting the "Insert Hidden MathML" item from the options
submenu will turn of MathJax's speech and Braille generation and
instead use visually hidden MathML that some screen readers can voice,
though support for this is not universal across all screen readers and
operating systems. Selecting speech or Braille generation in their
submenus will remove the hidden MathML again.</p>

<p>For more help, see the <a
href="https://docs.mathjax.org/en/latest/basic/accessibility.html"
target="_blank">MathJax accessibility documentation.</a></p>
Expand Down
61 changes: 46 additions & 15 deletions ts/ui/menu/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,16 @@ export class Menu {
*/
protected setAssistiveMml(mml: boolean) {
this.document.options.enableAssistiveMml = mml;
if (mml) {
this.noRerender(() => {
if (this.settings.speech) {
this.menu.pool.lookup('speech').setValue(false);
}
if (this.settings.braille) {
this.menu.pool.lookup('braille').setValue(false);
}
});
}
if (!mml || MathJax._?.a11y?.['assistive-mml']) {
this.rerender();
} else {
Expand Down Expand Up @@ -1236,6 +1246,11 @@ export class Menu {
protected setSpeech(speech: boolean) {
this.enableAccessibilityItems('Speech', speech);
this.document.options.enableSpeech = speech;
if (speech && this.settings.assistiveMml) {
this.noRerender(() =>
this.menu.pool.lookup('assistiveMml').setValue(false)
);
}
if (!speech || MathJax._?.a11y?.explorer) {
this.rerender(STATE.COMPILED);
} else {
Expand All @@ -1249,6 +1264,11 @@ export class Menu {
protected setBraille(braille: boolean) {
this.enableAccessibilityItems('Braille', braille);
this.document.options.enableBraille = braille;
if (braille && this.settings.assistiveMml) {
this.noRerender(() =>
this.menu.pool.lookup('assistiveMml').setValue(false)
);
}
if (!braille || MathJax._?.a11y?.explorer) {
this.rerender(STATE.COMPILED);
} else {
Expand Down Expand Up @@ -1381,24 +1401,24 @@ export class Menu {
* Reset all menu settings to the (page) defaults
*/
protected resetDefaults() {
Menu.loading++; // pretend we're loading, to suppress rerendering for each variable change
const pool = this.menu.pool;
const settings = this.defaultSettings;
for (const name of Object.keys(settings) as (keyof MenuSettings)[]) {
const variable = pool.lookup(name);
if (variable) {
if (variable.getValue() !== settings[name]) {
variable.setValue(settings[name] as string | boolean);
const item = (variable as any).items[0];
if (item) {
item.executeCallbacks_();
this.noRerender(() => {
const pool = this.menu.pool;
const settings = this.defaultSettings;
for (const name of Object.keys(settings) as (keyof MenuSettings)[]) {
const variable = pool.lookup(name);
if (variable) {
if (variable.getValue() !== settings[name]) {
variable.setValue(settings[name] as string | boolean);
const item = (variable as any).items[0];
if (item) {
item.executeCallbacks_();
}
}
} else if (Object.hasOwn(this.settings, name)) {
(this.settings as any)[name] = settings[name];
}
} else if (Object.hasOwn(this.settings, name)) {
(this.settings as any)[name] = settings[name];
}
}
Menu.loading--;
});
this.rerender(STATE.COMPILED);
}

Expand Down Expand Up @@ -1694,6 +1714,17 @@ export class Menu {
}
}

protected noRerender(exec: () => void) {
Menu.loading++; // pretend we're loading, to suppress rerendering durring exec() call
try {
exec();
Menu.loading--;
} catch (err) {
Menu.loading--; // make sure this resets if there is an error
throw err;
}
}

/**
* Copy the serialzied MathML to the clipboard
*/
Expand Down