From 03abbeec6609d235632fd4471071508706dc3ee5 Mon Sep 17 00:00:00 2001 From: David Sampson Date: Sat, 5 Dec 2026 00:52:34 +1100 Subject: [PATCH 1/3] Fix MathJax bundle loading (#51) The MathJax config also dynamically loaded the bundle through a bare relative URL. On nested pages, that URL resolved relative to the generated HTML page instead of the resources folder; if it resolved, the bundle could be loaded twice. Keep the config limited to setting MathJax options and rely on docconvert's existing config-then-bundle script references, which use paths relative to each generated page. Add nested-page regression coverage for the resource paths, one bundle reference, and script order. Test: MATLAB MCP run of tests/tdocconvert.m (3 passed, 0 failed). --- tbx/docmaker/resources/mathjax-config.js | 8 ------ tests/tdocconvert.m | 31 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/tbx/docmaker/resources/mathjax-config.js b/tbx/docmaker/resources/mathjax-config.js index bab4657..8edb0e9 100644 --- a/tbx/docmaker/resources/mathjax-config.js +++ b/tbx/docmaker/resources/mathjax-config.js @@ -7,11 +7,3 @@ window.MathJax = { displayMath: [['$$', '$$']] } }; - -// Dynamically load MathJax -(function () { - const script = document.createElement('script'); - script.src = "tex-mml-chtml.js"; - script.async = true; - document.head.appendChild(script); -})(); diff --git a/tests/tdocconvert.m b/tests/tdocconvert.m index d6b8519..93415ec 100644 --- a/tests/tdocconvert.m +++ b/tests/tdocconvert.m @@ -48,6 +48,37 @@ function tLaTeXConversionProducesCorrectHTMLFile( testCase ) "docconvert did not preserve non-math content." ) end % tLaTeXConversionProducesCorrectHTMLFile + + function tMathJaxScriptsLoadOnceForNestedPages( testCase ) + + nestedFolder = fullfile( testCase.Folder, "guide" ); + mkdir( nestedFolder ) + markdownFile = fullfile( nestedFolder, "chapter.md" ); + copyfile( testCase.ExampleLaTeXFile, markdownFile ) + + output = docconvert( markdownFile, ... + "Root", testCase.Folder, "Interpreter", "latex" ); + html = fileread( output ); + + configFile = fullfile( testCase.Folder, ... + "resources", "mathjax-config.js" ); + config = fileread( configFile ); + testCase.verifyFalse( contains( config, "tex-mml-chtml.js" ), ... + "The MathJax configuration should not load the bundle." ) + + configPath = "../resources/mathjax-config.js"; + bundlePath = "../resources/tex-mml-chtml.js"; + testCase.verifyEqual( count( html, configPath ), 1, ... + "The MathJax configuration should be included once." ) + testCase.verifyEqual( count( html, bundlePath ), 1, ... + "The MathJax bundle should be included once." ) + + configIndex = strfind( html, configPath ); + bundleIndex = strfind( html, bundlePath ); + testCase.verifyLessThan( configIndex, bundleIndex, ... + "The MathJax configuration must precede the bundle." ) + + end % tMathJaxScriptsLoadOnceForNestedPages end % methods ( Test ) From fcc798c898cc085e869f14fc4d7922ed76bee7fd Mon Sep 17 00:00:00 2001 From: David Sampson Date: Sat, 5 Dec 2026 01:40:07 +1100 Subject: [PATCH 2/3] Disable MathJax accessibility worker in generated docs Configure MathJax's contextual menu to disable semantic enrichment, which also gates speech and braille processing and avoids loading the unbundled SRE worker. Add a nested demo page with inline and display math for browser inspection. --- demo/sub/math.md | 7 +++++++ tbx/docmaker/resources/mathjax-config.js | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 demo/sub/math.md diff --git a/demo/sub/math.md b/demo/sub/math.md new file mode 100644 index 0000000..f8b1ca3 --- /dev/null +++ b/demo/sub/math.md @@ -0,0 +1,7 @@ +# MathJax Browser Check + +Inline equation: $ \sin^2x + \cos^2x = 1 $. + +Display equation: + +$$ \int_{-\infty}^\infty f(x) dx = 1 $$ diff --git a/tbx/docmaker/resources/mathjax-config.js b/tbx/docmaker/resources/mathjax-config.js index 8edb0e9..33df857 100644 --- a/tbx/docmaker/resources/mathjax-config.js +++ b/tbx/docmaker/resources/mathjax-config.js @@ -5,5 +5,14 @@ window.MathJax = { tex: { inlineMath: [['$', '$']], displayMath: [['$$', '$$']] + }, + // Disable semantic enrichment and its dependent speech and braille + // features; DocMaker does not bundle the required SRE worker assets. + options: { + menuOptions: { + settings: { + enrich: false + } + } } }; From 49e39c4a7bbefe8707a29b324a1c251ddf24c5fa Mon Sep 17 00:00:00 2001 From: David Sampson Date: Sat, 5 Dec 2026 01:41:54 +1100 Subject: [PATCH 3/3] Add MathJax demo to MATLAB project Register the nested demo/sub/math.md fixture in the MATLAB project metadata so source-control project checks recognize the new file. --- .../ZOXg7QkiGzwIXBtR899wx7Qg9CQd.xml | 2 ++ .../ZOXg7QkiGzwIXBtR899wx7Qg9CQp.xml | 2 ++ .../mliwxxW4DJFMNwIku7VL4CQRIIYd.xml | 2 ++ .../mliwxxW4DJFMNwIku7VL4CQRIIYp.xml | 2 ++ .../6w5DYSNhgTDUpgeU0d-vjdTyxYYd.xml | 2 ++ .../6w5DYSNhgTDUpgeU0d-vjdTyxYYp.xml | 2 ++ 6 files changed, 12 insertions(+) create mode 100644 resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/ZOXg7QkiGzwIXBtR899wx7Qg9CQd.xml create mode 100644 resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/ZOXg7QkiGzwIXBtR899wx7Qg9CQp.xml create mode 100644 resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/mliwxxW4DJFMNwIku7VL4CQRIIYd.xml create mode 100644 resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/mliwxxW4DJFMNwIku7VL4CQRIIYp.xml create mode 100644 resources/project/aM_fJ0UXVwZfzE_yzKDyj7pVqZg/6w5DYSNhgTDUpgeU0d-vjdTyxYYd.xml create mode 100644 resources/project/aM_fJ0UXVwZfzE_yzKDyj7pVqZg/6w5DYSNhgTDUpgeU0d-vjdTyxYYp.xml diff --git a/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/ZOXg7QkiGzwIXBtR899wx7Qg9CQd.xml b/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/ZOXg7QkiGzwIXBtR899wx7Qg9CQd.xml new file mode 100644 index 0000000..4356a6a --- /dev/null +++ b/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/ZOXg7QkiGzwIXBtR899wx7Qg9CQd.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/ZOXg7QkiGzwIXBtR899wx7Qg9CQp.xml b/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/ZOXg7QkiGzwIXBtR899wx7Qg9CQp.xml new file mode 100644 index 0000000..01cb34e --- /dev/null +++ b/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/ZOXg7QkiGzwIXBtR899wx7Qg9CQp.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/mliwxxW4DJFMNwIku7VL4CQRIIYd.xml b/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/mliwxxW4DJFMNwIku7VL4CQRIIYd.xml new file mode 100644 index 0000000..4356a6a --- /dev/null +++ b/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/mliwxxW4DJFMNwIku7VL4CQRIIYd.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/mliwxxW4DJFMNwIku7VL4CQRIIYp.xml b/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/mliwxxW4DJFMNwIku7VL4CQRIIYp.xml new file mode 100644 index 0000000..82572dd --- /dev/null +++ b/resources/project/6w5DYSNhgTDUpgeU0d-vjdTyxYY/mliwxxW4DJFMNwIku7VL4CQRIIYp.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/resources/project/aM_fJ0UXVwZfzE_yzKDyj7pVqZg/6w5DYSNhgTDUpgeU0d-vjdTyxYYd.xml b/resources/project/aM_fJ0UXVwZfzE_yzKDyj7pVqZg/6w5DYSNhgTDUpgeU0d-vjdTyxYYd.xml new file mode 100644 index 0000000..4356a6a --- /dev/null +++ b/resources/project/aM_fJ0UXVwZfzE_yzKDyj7pVqZg/6w5DYSNhgTDUpgeU0d-vjdTyxYYd.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/resources/project/aM_fJ0UXVwZfzE_yzKDyj7pVqZg/6w5DYSNhgTDUpgeU0d-vjdTyxYYp.xml b/resources/project/aM_fJ0UXVwZfzE_yzKDyj7pVqZg/6w5DYSNhgTDUpgeU0d-vjdTyxYYp.xml new file mode 100644 index 0000000..00cea33 --- /dev/null +++ b/resources/project/aM_fJ0UXVwZfzE_yzKDyj7pVqZg/6w5DYSNhgTDUpgeU0d-vjdTyxYYp.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file