@@ -16,30 +16,43 @@ interface MathJaxTexConfig {
1616}
1717
1818interface MathJaxConfig {
19+ loader ?: {
20+ load ?: string [ ] ;
21+ } ;
1922 tex ?: MathJaxTexConfig ;
2023 options ?: {
2124 enableMenu ?: boolean ;
2225 enableExplorer ?: boolean ;
26+ enableAssistiveMml ?: boolean ;
2327 } ;
2428 startup ?: {
2529 ready ?: ( ) => void ;
2630 defaultReady ?: ( ) => void ;
31+ document ?: MathJaxDocument ;
2732 } ;
2833 chtml ?: {
2934 fontURL ?: string ;
3035 } ;
3136}
3237
38+ interface MathJaxDocument {
39+ assistiveMml ?: ( ) => {
40+ updateDocument ?: ( ) => unknown ;
41+ } ;
42+ }
43+
3344interface MathJaxInstance {
3445 version ?: string ;
3546 tex ?: MathJaxTexConfig ;
3647 options ?: {
3748 enableMenu ?: boolean ;
3849 enableExplorer ?: boolean ;
50+ enableAssistiveMml ?: boolean ;
3951 } ;
4052 startup : {
4153 ready ?: ( ) => void ;
4254 defaultReady : ( ) => void ;
55+ document ?: MathJaxDocument ;
4356 } ;
4457 typesetPromise ?: ( elements ?: Element [ ] ) => Promise < void > ;
4558}
@@ -71,6 +84,9 @@ function ensureMathjaxLoaded(options: MathjaxOptions): Promise<void> {
7184 const { useSingleDollar = false , accessibility = true , loadFonts = true , srcUrl } = options ;
7285
7386 const config : MathJaxConfig = {
87+ loader : {
88+ load : accessibility ? [ 'a11y/assistive-mml' ] : [ ] ,
89+ } ,
7490 tex : {
7591 packages : [ 'base' , 'ams' , 'autoload' ] ,
7692 macros : {
@@ -83,6 +99,7 @@ function ensureMathjaxLoaded(options: MathjaxOptions): Promise<void> {
8399 options : {
84100 enableMenu : accessibility ,
85101 enableExplorer : accessibility ,
102+ enableAssistiveMml : accessibility ,
86103 } ,
87104 startup : {
88105 ready : ( ) => {
@@ -124,6 +141,20 @@ function ensureMathjaxLoaded(options: MathjaxOptions): Promise<void> {
124141 return mathjaxLoading ;
125142}
126143
144+ function attachAssistiveMml ( ) : void {
145+ const mathDocument = window . MathJax ?. startup ?. document ;
146+
147+ if ( typeof mathDocument ?. assistiveMml !== 'function' ) {
148+ return ;
149+ }
150+
151+ try {
152+ mathDocument . assistiveMml ( ) . updateDocument ?.( ) ;
153+ } catch ( error ) {
154+ console . warn ( '[mathjax-renderer] Failed to attach assistive MathML:' , error ) ;
155+ }
156+ }
157+
127158/**
128159 * Create a MathJax-based math renderer
129160 *
@@ -155,6 +186,7 @@ export function createMathjaxRenderer(
155186 }
156187
157188 await window . MathJax . typesetPromise ( [ element ] ) ;
189+ attachAssistiveMml ( ) ;
158190 } ;
159191}
160192
0 commit comments