Skip to content

Commit 33e6c58

Browse files
authored
Merge pull request #37 from mathjax/update_4.2.1
Update 3.2.1
2 parents a15f0a5 + f2a1925 commit 33e6c58

File tree

7 files changed

+106
-33
lines changed

7 files changed

+106
-33
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The examples below show how to use and configure MathJax components in your web
4545
* [tex-mml.html](tex-mml.html.md) ([View Demo](https://mathjax.github.io/MathJax-demos-web/tex-mml.html))
4646
* [mml-attribute.html](mml-attribute.html.md) ([View Demo](https://mathjax.github.io/MathJax-demos-web/mml-attribute.html))
4747
* [speech-tex-chtml.html](speech-tex-chtml.html.md) ([View Demo](https://mathjax.github.io/MathJax-demos-web/speech-tex-chtml.html))
48+
* [speech-explorer-tex.html](speech-explorer-tex.html.md) ([View Demo](https://mathjax.github.io/MathJax-demos-web/speech-explorer-tex.html))
4849

4950
### Customization
5051

@@ -55,6 +56,11 @@ The examples below show how to use and configure MathJax components in your web
5556
* [custom-component](custom-component/custom-component.html.md) ([View Demo](https://mathjax.github.io/MathJax-demos-web/custom-component/custom-component.html))
5657
* [custom-build](custom-build/custom-mathjax.html.md) ([View Demo](https://mathjax.github.io/MathJax-demos-web/custom-build/custom-mathjax.html))
5758

59+
### Speech Output Demo
60+
61+
* [convert-with-speech](speech-generator/convert-with-speech.html) A lab to explore all possible speech options in MathJax.
62+
63+
5864
## MathJax Component Files
5965

6066
MathJax version 3 has the ability to create MathJax "components" that can be dynamically loaded by MathJax as needed (much as could be done in version 2). This allows portions of MathJax to be bundled together into components that include most or all of what you need to run MathJax, but still allows less-used pieces to be loaded on demand later when needed. This is similar to v2's combined configuration files and TeX extensions.

speech-explorer-tex.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="x-ua-compatible" content="ie=edge">
6+
<meta name="viewport" content="width=device-width">
7+
<style>
8+
kbd {
9+
display: inline-block;
10+
padding: 3px 5px;
11+
font-size: 11px;
12+
line-height: 10px;
13+
color: #444d56;
14+
vertical-align: middle;
15+
background-color: #fafbfc;
16+
border: solid 1px #c6cbd1;
17+
border-bottom-color: #959da5;
18+
border-radius: 3px;
19+
box-shadow: inset 0 -1px 0 #959da5;
20+
}
21+
</style>
22+
<title>MathJax v3 with TeX input and HTML output with speech</title>
23+
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
24+
<script>
25+
MathJax = {
26+
loader: {load: ['a11y/sre']},
27+
options: {
28+
menuOptions: {
29+
settings: {
30+
explorer: true,
31+
assistiveMml: false
32+
}
33+
}
34+
},
35+
tex: {inlineMath: [['$', '$'], ['\\(', '\\)']]}
36+
};
37+
</script>
38+
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
39+
</head>
40+
<body>
41+
42+
<p>
43+
These expressions will have auto-generated speech attached for screen readers. Focus on a formula and press <kbd>Enter</kbd> to start exploration with the arrow keys.
44+
</p>
45+
46+
<p>
47+
When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
48+
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
49+
</p>
50+
51+
</body>
52+
</html>

speech-explorer-tex.html.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# [speech-expolrer-tex.html](https://mathjax.github.io/MathJax-demos-web/speech-explorer-tex.html)
2+
3+
This example shows how to enable MathJax's accessibility extension to attach speech to typeset math and enable interactive exploration of expressions.
4+
5+
The key lines are
6+
7+
``` html
8+
<script>
9+
MathJax = {
10+
loader: {load: ['a11y/sre']},
11+
options: {
12+
menuOptions: {
13+
settings: {
14+
explorer: true,
15+
assistiveMml: false
16+
}
17+
}
18+
},
19+
tex: {inlineMath: [['$', '$'], ['\\(', '\\)']]}
20+
};
21+
</script>
22+
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
23+
```
24+
25+
which causes the `a11y/sre` extension to be loaded, and modifies the menu settings to initialise the interactive explorer on page load. In addition we can switch off the assistive mml extension as it is no longer needed.
26+
27+
[Run the example](https://mathjax.github.io/MathJax-demos-web/speech-explorer-tex.html)

speech-generator/convert-with-speech.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
99
<script>
1010
MathJax = {
11-
loader: {load: ['input/asciimath', 'input/mml', 'input/tex', 'output/svg', 'sre/sre_browser']},
11+
loader: {load: ['input/asciimath', 'input/mml', 'input/tex', 'output/svg', 'a11y/sre']},
1212
tex: {inlineMath: [['$', '$'], ['\\(', '\\)']]},
1313
startup: {
1414
ready: function() {

speech-generator/convert-with-speech.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
let Convert = {};
2+
let SRE = null;
23

34
Convert.textAreas = {
45
input: null,
@@ -42,9 +43,9 @@ Convert.getElements = function() {
4243
};
4344

4445
Convert.setupSre = function() {
45-
for (let loc of sre.Variables.LOCALES) {
46+
for (let [loc, lang] of SRE.locales.entries()) {
4647
let option = document.createElement('option');
47-
option.innerHTML = loc.toUpperCase();
48+
option.innerHTML = lang;
4849
option.setAttribute('value', loc);
4950
if (loc === 'en') {
5051
option.setAttribute('selected', true);
@@ -55,6 +56,7 @@ Convert.setupSre = function() {
5556
};
5657

5758
Convert.init = function() {
59+
SRE = MathJax._.a11y.sre.Sre;
5860
Convert.getElements();
5961
Convert.setupSre();
6062
};
@@ -63,7 +65,7 @@ Convert.init = function() {
6365
Convert.setPreferences = function(locale) {
6466
Convert.divs.preferences.innerHTML = '';
6567
Convert.state.preferences = [];
66-
let prefs = sre.ClearspeakPreferences.getLocalePreferences()[locale];
68+
let prefs = SRE.clearspeakPreferences.getLocalePreferences()[locale];
6769
if (!prefs) {
6870
Convert.state.clearspeak = false;
6971
Convert.textAreas.clearspeak.innerHTML = '';
@@ -128,40 +130,31 @@ Convert.setPreferences = function(locale) {
128130

129131

130132
Convert.updatePreferences = async function(locale) {
131-
sre.System.getInstance().setupEngine({locale: locale});
132-
let promise = new Promise((resolve) => {
133-
const checkSre = function() {
134-
if (sre.Engine.isReady()) {
135-
resolve();
136-
} else {
137-
setTimeout(checkSre, 100);
138-
}};
139-
checkSre();
140-
});
141-
return promise.then(() => {Convert.setPreferences(locale);});
133+
return SRE.setupEngine({locale: locale}).
134+
then(() => {Convert.setPreferences(locale);});
142135
};
143136

144137

145-
Convert.computeClearspeak = function() {
146-
Convert.textAreas.clearspeak.innerHTML =
147-
Convert.computeSpeech('clearspeak', Convert.state.preferences.map((x) => x.value).join(':'));
138+
Convert.computeClearspeak = async function() {
139+
return Convert.computeSpeech(
140+
Convert.textAreas.clearspeak, 'clearspeak',
141+
Convert.state.preferences.map((x) => x.value).join(':'));
148142
};
149143

150144

151-
Convert.computeMathspeak = function() {
152-
Convert.textAreas.mathspeak.innerHTML =
153-
Convert.computeSpeech('mathspeak', Convert.selectors.style.value);
145+
Convert.computeMathspeak = async function() {
146+
return Convert.computeSpeech(
147+
Convert.textAreas.mathspeak, 'mathspeak', Convert.selectors.style.value);
154148
};
155149

156150

157-
Convert.computeSpeech = function(domain, style) {
151+
Convert.computeSpeech = async function(node, domain, style) {
158152
let locale = Convert.selectors.locale.value;
159153
let modality = locale === 'nemeth' ? 'braille' : 'speech';
160-
sre.System.getInstance().setupEngine(
154+
return SRE.setupEngine(
161155
{locale: locale, domain: domain, modality: modality,
162156
style: style, markup: Convert.selectors.markup.value, pprint: true
163-
});
164-
return sre.System.getInstance().toSpeech(Convert.input2Mathml());
157+
}).then(() => node.innerHTML = SRE.toSpeech(Convert.input2Mathml()));
165158
};
166159

167160

@@ -191,9 +184,9 @@ Convert.radioValue = function(radios) {
191184
};
192185

193186

194-
Convert.convertExpression = function() {
187+
Convert.convertExpression = async function() {
195188
Convert.render();
196-
Convert.computeMathspeak();
189+
await Convert.computeMathspeak();
197190
if (Convert.state.clearspeak) {
198191
Convert.computeClearspeak();
199192
}

speech-tex-chtml.html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ The key lines are
2727
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
2828
```
2929

30-
which causes the `a11y/semantic-enrich` extension to be loaded, and modifies the enrich action to force the enrichment regardless of the settings in the contextual menu. The output jax will pick on on the speech text that is generated by the extension and create the proper tags and attributes for it to be picked up by screen readers.
30+
which causes the `a11y/semantic-enrich` extension to be loaded, and modifies the enrich action to force the enrichment regardless of the settings in the contextual menu. The output jax will pick up on the speech text that is generated by the extension and create the proper tags and attributes for it to be picked up by screen readers.
3131

3232
[Run the example](https://mathjax.github.io/MathJax-demos-web/speech-tex-chtml.html)

tex-mml.html.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ The key lines are
4747
(doc) => {for (math of doc.math) {MathJax.config.renderMathML(math, doc)}},
4848
(math, doc) => MathJax.config.renderMathML(math, doc)
4949
]
50-
},
51-
menuOptions: {
52-
settings: {
53-
assistiveMml: false
54-
}
5550
}
5651
},
5752
//

0 commit comments

Comments
 (0)