From 9bcacb6d0384f50a568fff89e9d3faf74262e7c3 Mon Sep 17 00:00:00 2001 From: jmnote Date: Fri, 9 Oct 2026 01:55:54 +0900 Subject: [PATCH] Add $wgSmjExplorerEnabled, off by default MathJax 4 enriches formulas for its accessibility explorer, so a click selects and highlights a symbol. Turn semantic enrichment off by default (menuOptions.settings.enrich); readers can enable it from the MathJax menu, and sites can enable it for everyone with $wgSmjExplorerEnabled. --- README.md | 1 + docs/configuration.md | 17 +++++++++++++++++ extension.json | 4 ++++ includes/Hooks.php | 5 +++-- resources/ext.SimpleMathJax.js | 12 ++++++++++-- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a8ee0d83..853e5a23 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ wfLoadExtension( 'SimpleMathJax' ); | `$wgSmjCdnVersion` | `'4'` | MathJax version to load from the CDN | `'4.1.3'` | | `$wgSmjScale` | `1` | `MathJax.chtml.scale` | `1.5` | | `$wgSmjEnableMenu` | `true` | `MathJax.options.enableMenu` | `false` | +| `$wgSmjExplorerEnabled` | `false` | Whether to enable MathJax's accessibility explorer (click/keyboard exploration, speech, Braille) | `true` | | `$wgSmjDelimitersEnabled` | `false` | Whether to also scan for bare delimiters (e.g. `$...$`) outside ``/`` | `true` | | `$wgSmjDelimitersInlineMath` | `[]` | Inline math delimiter pairs | `[['$','$']]` | | `$wgSmjDelimitersDisplayMath` | `[]` | Display math delimiter pairs | `[['$$','$$']]` | diff --git a/docs/configuration.md b/docs/configuration.md index ec06761d..90a0a818 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -14,6 +14,7 @@ and examples. Upgrading from before 1.0.0? See the | `$wgSmjCdnVersion` | `'4'` | MathJax version to load from the CDN | | `$wgSmjScale` | `1` | `MathJax.chtml.scale` | | `$wgSmjEnableMenu` | `true` | `MathJax.options.enableMenu` | +| `$wgSmjExplorerEnabled` | `false` | Whether to enable MathJax's accessibility explorer (click/keyboard exploration, speech, Braille) | | `$wgSmjDelimitersEnabled` | `false` | Whether to also scan for bare delimiters (e.g. `$...$`) outside ``/`` | | `$wgSmjDelimitersInlineMath` | `[]` | Inline math delimiter pairs, e.g. `[['$','$']]` | | `$wgSmjDelimitersDisplayMath` | `[]` | Display math delimiter pairs, e.g. `[['$$','$$']]` | @@ -80,6 +81,22 @@ wfLoadExtension( 'SimpleMathJax' ); $wgSmjEnableMenu = false; ``` +### `$wgSmjExplorerEnabled` + +MathJax 4 enriches each formula with semantic information for its +accessibility explorer. With it on, clicking a formula selects and +highlights a symbol, arrow keys move through the expression, and screen +readers get spoken and Braille output. SimpleMathJax turns this off by +default so a click does not select part of a formula. Readers can still +enable it per browser from the MathJax menu (right-click, Accessibility). + +To enable it for everyone: + +```php +wfLoadExtension( 'SimpleMathJax' ); +$wgSmjExplorerEnabled = true; +``` + ### `$wgSmjDelimitersEnabled` By default, `$wgSmjDelimitersEnabled` is `false`, so only TeX wrapped in diff --git a/extension.json b/extension.json index 8064a377..62ee6e56 100644 --- a/extension.json +++ b/extension.json @@ -45,6 +45,10 @@ "value": true, "description": "Whether to enable MathJax context menu" }, + "SmjExplorerEnabled": { + "value": false, + "description": "Whether to enable MathJax's accessibility explorer (semantic enrichment: click/keyboard exploration with highlighting, speech and Braille)" + }, "SmjAllowedAttributes": { "value": [], "description": "Generic HTML attributes to carry over from / to the output " diff --git a/includes/Hooks.php b/includes/Hooks.php index 91c0687e..10586f5c 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -16,7 +16,7 @@ class Hooks { private static string $ignoreHtmlClass = ''; public static function onParserFirstCallInit( Parser $parser ) { - global $wgOut, $wgSmjCdnEnabled, $wgSmjCdnVersion, $wgSmjEnableMenu, + global $wgOut, $wgSmjCdnEnabled, $wgSmjCdnVersion, $wgSmjEnableMenu, $wgSmjExplorerEnabled, $wgSmjDelimitersEnabled, $wgSmjDelimitersInlineMath, $wgSmjDelimitersDisplayMath, $wgSmjIgnoreHtmlClass, $wgSmjScale, $wgSmjAllowedAttributes, $wgSmjRevisionOverrides; @@ -30,6 +30,7 @@ public static function onParserFirstCallInit( Parser $parser ) { "wgSmjIgnoreHtmlClass" => $wgSmjIgnoreHtmlClass, "wgSmjScale" => $wgSmjScale, "wgSmjEnableMenu" => $wgSmjEnableMenu, + "wgSmjExplorerEnabled" => $wgSmjExplorerEnabled, "wgSmjAllowedAttributes" => $wgSmjAllowedAttributes, ]; @@ -38,7 +39,7 @@ public static function onParserFirstCallInit( Parser $parser ) { $clientConfigVars = [ "wgSmjCdnEnabled", "wgSmjCdnVersion", "wgSmjDelimitersEnabled", "wgSmjDelimitersInlineMath", "wgSmjDelimitersDisplayMath", - "wgSmjIgnoreHtmlClass", "wgSmjScale", "wgSmjEnableMenu" ]; + "wgSmjIgnoreHtmlClass", "wgSmjScale", "wgSmjEnableMenu", "wgSmjExplorerEnabled" ]; foreach ( $clientConfigVars as $varname ) { $wgOut->addJsConfigVars( $varname, $config[$varname] ); } diff --git a/resources/ext.SimpleMathJax.js b/resources/ext.SimpleMathJax.js index cb36f9dc..27e76e52 100644 --- a/resources/ext.SimpleMathJax.js +++ b/resources/ext.SimpleMathJax.js @@ -14,7 +14,8 @@ var defaults = { wgSmjDelimitersInlineMath: [], wgSmjDelimitersDisplayMath: [], wgSmjIgnoreHtmlClass: 'mathjax_ignore|comment|diff-(context|addedline|deletedline)', - wgSmjScale: 1 + wgSmjScale: 1, + wgSmjExplorerEnabled: false }; function config(name) { @@ -144,7 +145,14 @@ function ensureLoaded() { }, options: { ignoreHtmlClass: config('wgSmjIgnoreHtmlClass'), - processHtmlClass: "mathjax_process|smj-container" + processHtmlClass: "mathjax_process|smj-container", + // Semantic enrichment drives MathJax 4's explorer: a click selects and + // highlights a symbol. Readers can still turn it on from the menu. + menuOptions: { + settings: { + enrich: config('wgSmjExplorerEnabled') + } + } }, chtml: { scale: config('wgSmjScale'),