Skip to content

Commit 428272b

Browse files
authored
Merge pull request #1388 from mathjax/update/assistive-mml
Make assistive-mml unset speech/braille and vice-versa
2 parents e3bf19e + c084317 commit 428272b

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

ts/a11y/explorer/KeyExplorer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ export class SpeechExplorer
223223
creating an SVG version of the expression, and viewing various other
224224
information.</p>
225225
226+
<p>Finally, selecting the "Insert Hidden MathML" item from the options
227+
submenu will turn of MathJax's speech and Braille generation and
228+
instead use visually hidden MathML that some screen readers can voice,
229+
though support for this is not universal across all screen readers and
230+
operating systems. Selecting speech or Braille generation in their
231+
submenus will remove the hidden MathML again.</p>
232+
226233
<p>For more help, see the <a
227234
href="https://docs.mathjax.org/en/latest/basic/accessibility.html"
228235
target="_blank">MathJax accessibility documentation.</a></p>

ts/ui/menu/Menu.ts

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,16 @@ export class Menu {
12031203
*/
12041204
protected setAssistiveMml(mml: boolean) {
12051205
this.document.options.enableAssistiveMml = mml;
1206+
if (mml) {
1207+
this.noRerender(() => {
1208+
if (this.settings.speech) {
1209+
this.menu.pool.lookup('speech').setValue(false);
1210+
}
1211+
if (this.settings.braille) {
1212+
this.menu.pool.lookup('braille').setValue(false);
1213+
}
1214+
});
1215+
}
12061216
if (!mml || MathJax._?.a11y?.['assistive-mml']) {
12071217
this.rerender();
12081218
} else {
@@ -1236,6 +1246,11 @@ export class Menu {
12361246
protected setSpeech(speech: boolean) {
12371247
this.enableAccessibilityItems('Speech', speech);
12381248
this.document.options.enableSpeech = speech;
1249+
if (speech && this.settings.assistiveMml) {
1250+
this.noRerender(() =>
1251+
this.menu.pool.lookup('assistiveMml').setValue(false)
1252+
);
1253+
}
12391254
if (!speech || MathJax._?.a11y?.explorer) {
12401255
this.rerender(STATE.COMPILED);
12411256
} else {
@@ -1249,6 +1264,11 @@ export class Menu {
12491264
protected setBraille(braille: boolean) {
12501265
this.enableAccessibilityItems('Braille', braille);
12511266
this.document.options.enableBraille = braille;
1267+
if (braille && this.settings.assistiveMml) {
1268+
this.noRerender(() =>
1269+
this.menu.pool.lookup('assistiveMml').setValue(false)
1270+
);
1271+
}
12521272
if (!braille || MathJax._?.a11y?.explorer) {
12531273
this.rerender(STATE.COMPILED);
12541274
} else {
@@ -1381,24 +1401,24 @@ export class Menu {
13811401
* Reset all menu settings to the (page) defaults
13821402
*/
13831403
protected resetDefaults() {
1384-
Menu.loading++; // pretend we're loading, to suppress rerendering for each variable change
1385-
const pool = this.menu.pool;
1386-
const settings = this.defaultSettings;
1387-
for (const name of Object.keys(settings) as (keyof MenuSettings)[]) {
1388-
const variable = pool.lookup(name);
1389-
if (variable) {
1390-
if (variable.getValue() !== settings[name]) {
1391-
variable.setValue(settings[name] as string | boolean);
1392-
const item = (variable as any).items[0];
1393-
if (item) {
1394-
item.executeCallbacks_();
1404+
this.noRerender(() => {
1405+
const pool = this.menu.pool;
1406+
const settings = this.defaultSettings;
1407+
for (const name of Object.keys(settings) as (keyof MenuSettings)[]) {
1408+
const variable = pool.lookup(name);
1409+
if (variable) {
1410+
if (variable.getValue() !== settings[name]) {
1411+
variable.setValue(settings[name] as string | boolean);
1412+
const item = (variable as any).items[0];
1413+
if (item) {
1414+
item.executeCallbacks_();
1415+
}
13951416
}
1417+
} else if (Object.hasOwn(this.settings, name)) {
1418+
(this.settings as any)[name] = settings[name];
13961419
}
1397-
} else if (Object.hasOwn(this.settings, name)) {
1398-
(this.settings as any)[name] = settings[name];
13991420
}
1400-
}
1401-
Menu.loading--;
1421+
});
14021422
this.rerender(STATE.COMPILED);
14031423
}
14041424

@@ -1694,6 +1714,17 @@ export class Menu {
16941714
}
16951715
}
16961716

1717+
protected noRerender(exec: () => void) {
1718+
Menu.loading++; // pretend we're loading, to suppress rerendering durring exec() call
1719+
try {
1720+
exec();
1721+
Menu.loading--;
1722+
} catch (err) {
1723+
Menu.loading--; // make sure this resets if there is an error
1724+
throw err;
1725+
}
1726+
}
1727+
16971728
/**
16981729
* Copy the serialzied MathML to the clipboard
16991730
*/

0 commit comments

Comments
 (0)