Skip to content

Commit bb2a807

Browse files
Disable MathJax a11y speech worker in VS Code webview
The tex-svg combined component loads sre/speech-worker.js at runtime, but Vite only emits webview.js. Turn off speech/enrichment for editor preview. Co-authored-by: J. Simon Richard <jsimonrichard@gmail.com>
1 parent c6b2d22 commit bb2a807

4 files changed

Lines changed: 69 additions & 1 deletion

File tree

.changeset/latex-static-mathjax-import.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'vscode-prosemark-latex-integration': patch
33
---
44

5-
Load MathJax via a top-level static `import 'mathjax/tex-svg.js'` (peer dependency of `@prosemark/latex`) so Vite fully bundles it into the webview instead of deferring a dynamic import at setup time.
5+
Load MathJax via a top-level static `import 'mathjax/tex-svg.js'` (peer dependency of `@prosemark/latex`) so Vite fully bundles it into the webview instead of deferring a dynamic import at setup time. Disable MathJax a11y speech/enrichment so the combined `tex-svg` component does not try to load the separate `sre/speech-worker.js` file (not copied into the VS Code webview bundle).
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
interface MathJaxStartupDocument {
2+
options: {
3+
enableSpeech?: boolean;
4+
enableBraille?: boolean;
5+
enableEnrichment?: boolean;
6+
};
7+
}
8+
9+
interface MathJaxWithStartup {
10+
startup?: {
11+
promise?: Promise<void>;
12+
document?: MathJaxStartupDocument;
13+
};
14+
config?: {
15+
options?: {
16+
enableSpeech?: boolean;
17+
enableBraille?: boolean;
18+
enableEnrichment?: boolean;
19+
};
20+
};
21+
}
22+
23+
/** Ensure speech worker is not requested before math widgets render. */
24+
export async function disableMathJaxA11y(): Promise<void> {
25+
const mj = window.MathJax as MathJaxWithStartup | undefined;
26+
await mj?.startup?.promise;
27+
28+
const options = mj?.config?.options;
29+
if (options) {
30+
options.enableSpeech = false;
31+
options.enableBraille = false;
32+
options.enableEnrichment = false;
33+
}
34+
35+
const docOptions = mj?.startup?.document?.options;
36+
if (docOptions) {
37+
docOptions.enableSpeech = false;
38+
docOptions.enableBraille = false;
39+
docOptions.enableEnrichment = false;
40+
}
41+
}

apps/vscode-extensions/latex-integration/src/webview/main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import {
1212
latexMarkdownSyntaxTheme,
1313
} from '@prosemark/latex';
1414

15+
import './mathjax-preload';
1516
import './style.css';
1617

1718
// Peer dependency of @prosemark/latex; bundled into webview.js by Vite at build time.
1819
import 'mathjax/tex-svg.js';
1920

21+
import { disableMathJaxA11y } from './disable-mathjax-a11y';
22+
2023
const latexExtensions = [
2124
...latexMarkdownSyntaxTheme,
2225
...latexMarkdownEditorExtensions({
@@ -40,6 +43,7 @@ const procs: WebviewProcMap = {
4043
latexSetupDone = true;
4144

4245
try {
46+
await disableMathJaxA11y();
4347
appendToExtraCodeMirrorExtensions(view, latexExtensions);
4448
} catch (err: unknown) {
4549
console.error('[ProseMark] latex-integration setup failed', err);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* MathJax reads `window.MathJax` when `tex-svg.js` loads. This module must be
3+
* imported before `mathjax/tex-svg.js` so startup options are in place first.
4+
*
5+
* The combined `tex-svg` component includes a11y/speech and tries to load
6+
* `sre/speech-worker.js` as a separate web worker at runtime. VS Code webviews
7+
* only ship `webview.js`, so we disable speech/enrichment for editor preview.
8+
*/
9+
window.MathJax = {
10+
options: {
11+
skipStartupTypeset: true,
12+
enableSpeech: false,
13+
enableBraille: false,
14+
enableEnrichment: false,
15+
menuOptions: {
16+
settings: {
17+
enrich: false,
18+
speech: false,
19+
braille: false,
20+
},
21+
},
22+
},
23+
};

0 commit comments

Comments
 (0)