mathpix-markdown-it 2.0.35 → 2.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -1
- package/doc/changelog.md +32 -0
- package/es5/browser/add-speech.js +1 -0
- package/es5/browser/auto-render.js +33 -0
- package/es5/bundle.js +1 -1
- package/es5/index.js +1 -1
- package/lib/browser/add-speech.d.ts +17 -0
- package/lib/browser/add-speech.js +97 -0
- package/lib/browser/add-speech.js.map +1 -0
- package/lib/browser/auto-render.d.ts +20 -0
- package/lib/browser/auto-render.js +319 -0
- package/lib/browser/auto-render.js.map +1 -0
- package/lib/browser/utils.d.ts +4 -0
- package/lib/browser/utils.js +11 -0
- package/lib/browser/utils.js.map +1 -0
- package/lib/markdown/common/convert-math-to-html.d.ts +4 -1
- package/lib/markdown/common/convert-math-to-html.js +174 -93
- package/lib/markdown/common/convert-math-to-html.js.map +1 -1
- package/lib/markdown/highlight/highlight-math-token.js +5 -3
- package/lib/markdown/highlight/highlight-math-token.js.map +1 -1
- package/lib/mathjax/index.d.ts +6 -0
- package/lib/mathjax/index.js +103 -33
- package/lib/mathjax/index.js.map +1 -1
- package/lib/mathpix-markdown-model/index.d.ts +1 -0
- package/lib/mathpix-markdown-model/index.js +1 -0
- package/lib/mathpix-markdown-model/index.js.map +1 -1
- package/lib/sre/index.d.ts +8 -0
- package/lib/sre/index.js +38 -20
- package/lib/sre/index.js.map +1 -1
- package/lib/sre/sre-browser.d.ts +16 -0
- package/lib/sre/sre-browser.js +26 -1
- package/lib/sre/sre-browser.js.map +1 -1
- package/lib/styles/index.js +1 -1
- package/lib/styles/index.js.map +1 -1
- package/package.json +2 -2
- package/pr-specs/2026-01-html-math-output-options.md +529 -0
package/README.md
CHANGED
|
@@ -691,6 +691,127 @@ import {
|
|
|
691
691
|
<img width="370" alt="Screen Shot 2022-05-03 at 17 21 50" src="https://user-images.githubusercontent.com/32493105/166471623-fd3f6a5b-84e4-4d43-afcd-0384e83eb2df.png">
|
|
692
692
|
|
|
693
693
|
|
|
694
|
+
## Output Format
|
|
695
|
+
|
|
696
|
+
The `output_format` option in `TOutputMath` controls which math format is placed in the HTML output. This is useful for optimizing file size or delegating rendering to the client.
|
|
697
|
+
|
|
698
|
+
| Value | Description |
|
|
699
|
+
|-------|-------------|
|
|
700
|
+
| `'svg'` (default) | Pre-rendered SVG with hidden format elements. Works offline, no client-side rendering needed. |
|
|
701
|
+
| `'mathml'` | Native `<math>` elements only. Smaller file size, requires client-side rendering via `auto-render.js`. |
|
|
702
|
+
| `'latex'` | Raw LaTeX with original delimiters. Smaller file size, requires client-side rendering via `auto-render.js`. |
|
|
703
|
+
|
|
704
|
+
### Example usage
|
|
705
|
+
|
|
706
|
+
```js
|
|
707
|
+
const options = {
|
|
708
|
+
outMath: {
|
|
709
|
+
output_format: 'mathml', // or 'latex'
|
|
710
|
+
include_mathml: true,
|
|
711
|
+
include_latex: true,
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
const html = MathpixMarkdownModel.markdownToHTML('$x^2$', options);
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
When using `'mathml'` or `'latex'`, the server outputs minimal HTML containing only the raw format. Use the browser rendering script (`auto-render.js`) to transform this into the full structure with SVG and hidden formats.
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
## Browser Rendering Script (auto-render.js)
|
|
721
|
+
|
|
722
|
+
For `output_format: 'mathml'` or `output_format: 'latex'`, use the browser bundle to render math on the client side.
|
|
723
|
+
|
|
724
|
+
### Loading the script
|
|
725
|
+
|
|
726
|
+
```html
|
|
727
|
+
<script src="https://cdn.jsdelivr.net/npm/mathpix-markdown-it@latest/es5/browser/auto-render.js"></script>
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
### Usage
|
|
731
|
+
|
|
732
|
+
```js
|
|
733
|
+
// Render all math elements in a container
|
|
734
|
+
window.MathpixRender.renderMathInElement(document.getElementById('content'), {
|
|
735
|
+
outMath: {
|
|
736
|
+
output_format: 'svg',
|
|
737
|
+
include_svg: true,
|
|
738
|
+
include_mathml: true,
|
|
739
|
+
include_latex: true,
|
|
740
|
+
include_asciimath: true,
|
|
741
|
+
},
|
|
742
|
+
accessibility: {
|
|
743
|
+
assistive_mml: true,
|
|
744
|
+
include_speech: true,
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
### Configuration options
|
|
750
|
+
|
|
751
|
+
| Option | Type | Default | Description |
|
|
752
|
+
|--------|------|---------|-------------|
|
|
753
|
+
| `outMath` | `TOutputMath` | `{ output_format: 'svg', include_svg: true }` | Controls which hidden formats to generate. Set `include_mathml`, `include_latex`, `include_asciimath`, etc. to `true` to generate hidden format elements for context menu compatibility. |
|
|
754
|
+
| `accessibility.assistive_mml` | `boolean` | `true` | Add `<mjx-assistive-mml>` element for screen readers |
|
|
755
|
+
| `accessibility.include_speech` | `boolean` | `false` | Add `aria-label` with speech text (requires `assistive_mml: true`) |
|
|
756
|
+
|
|
757
|
+
### Accessibility behavior
|
|
758
|
+
|
|
759
|
+
The browser bundle uses a simplified accessibility configuration (different from the server-side [TAccessibility](#taccessibility) interface):
|
|
760
|
+
|
|
761
|
+
| Configuration | Result |
|
|
762
|
+
|---------------|--------|
|
|
763
|
+
| `{ assistive_mml: true, include_speech: true }` | `aria-label` attribute with speech text + `<mjx-assistive-mml>` element |
|
|
764
|
+
| `{ assistive_mml: true }` | `aria-labelledby` pointing to `<mjx-assistive-mml>` ID |
|
|
765
|
+
| No accessibility config | No accessibility attributes added |
|
|
766
|
+
|
|
767
|
+
The script automatically skips elements that have already been rendered.
|
|
768
|
+
|
|
769
|
+
**Note:** For server-side rendering accessibility, use the [TAccessibility](#taccessibility) interface with `assistiveMml` and `sre` options instead.
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
## Browser Speech Script (add-speech.js)
|
|
773
|
+
|
|
774
|
+
Use this script to add speech accessibility to math that was already rendered server-side as SVG with `assistiveMml: true` but without SRE speech. It loads SRE dynamically and adds `aria-label` attributes to existing `mjx-container` elements.
|
|
775
|
+
|
|
776
|
+
This is useful when you want fast server-side rendering without the SRE dependency, but still want speech accessibility on the client.
|
|
777
|
+
|
|
778
|
+
### Prerequisites
|
|
779
|
+
|
|
780
|
+
The rendered HTML must include `<mjx-assistive-mml>` elements (i.e., the server used `accessibility: { assistiveMml: true }`).
|
|
781
|
+
|
|
782
|
+
### Loading the script
|
|
783
|
+
|
|
784
|
+
```html
|
|
785
|
+
<script src="https://cdn.jsdelivr.net/npm/mathpix-markdown-it@latest/es5/browser/add-speech.js"></script>
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
By default, the script automatically processes `document.body` on `DOMContentLoaded`.
|
|
789
|
+
|
|
790
|
+
### Usage
|
|
791
|
+
|
|
792
|
+
```js
|
|
793
|
+
// Add speech to all rendered math in a specific container
|
|
794
|
+
window.MathpixSpeech.addSpeechToRenderedMath(document.getElementById('content'));
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
### Configuration
|
|
798
|
+
|
|
799
|
+
Set `window.MathpixSpeechConfig` before the script loads to customize behavior:
|
|
800
|
+
|
|
801
|
+
```js
|
|
802
|
+
window.MathpixSpeechConfig = {
|
|
803
|
+
container: document.getElementById('math-content') // defaults to document.body
|
|
804
|
+
};
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
### What it does
|
|
808
|
+
|
|
809
|
+
For each `mjx-container` element that does not already have an `aria-label`:
|
|
810
|
+
1. Extracts MathML from the `<mjx-assistive-mml>` child element
|
|
811
|
+
2. Generates speech text using SRE (Speech Rule Engine)
|
|
812
|
+
3. Sets `aria-label`, `role="math"`, and `tabindex="0"` on the container
|
|
813
|
+
|
|
814
|
+
|
|
694
815
|
# Documentation
|
|
695
816
|
|
|
696
817
|
## React components
|
|
@@ -818,6 +939,7 @@ The `MathpixMarkdown` React element accepts the following props:
|
|
|
818
939
|
|
|
819
940
|
| | type *`default`* | description |
|
|
820
941
|
|--------------------------|------------------------------|-------------------------------------------------------------------------------------------------------------------|
|
|
942
|
+
| `output_format` | `'svg' \| 'mathml' \| 'latex'` *`'svg'`* | Controls which math format is placed in HTML output. See [Output Format](#output-format) section. |
|
|
821
943
|
| `include_mathml` | boolean *`false`* | outputs mathml `<mathml style="display: none"><math>...</math></mathml>` |
|
|
822
944
|
| `include_mathml_word` | boolean *`false`* | outputs mathml_word `<mathmlword style="display: none"><math>...</math></mathmlword>` |
|
|
823
945
|
| `include_asciimath` | boolean *`false`* | outputs asciimath `<asciimath style="display: none">...</asciimath>` |
|
|
@@ -964,7 +1086,7 @@ const { loadSreAsync } = require('mathpix-markdown-it/lib/sre/sre-node');
|
|
|
964
1086
|
|
|
965
1087
|
```
|
|
966
1088
|
|
|
967
|
-
Then just pass the resulting value to `accessibility.
|
|
1089
|
+
Then just pass the resulting value to `accessibility.sre`
|
|
968
1090
|
```js
|
|
969
1091
|
accessibility: {
|
|
970
1092
|
assistiveMml: true, // assistive-mml will be added to mjx-container
|
package/doc/changelog.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# February 2026
|
|
2
2
|
|
|
3
|
+
## [2.0.36] - 16 February 2026
|
|
4
|
+
|
|
5
|
+
- Math Output Format:
|
|
6
|
+
- Added `output_format` option to `TOutputMath` to control which math format is placed in HTML output.
|
|
7
|
+
- `'svg'` (default): Pre-rendered SVG with hidden formats, works offline.
|
|
8
|
+
- `'mathml'`: Native `<math>` elements only, smaller file size, requires client-side rendering.
|
|
9
|
+
- `'latex'`: Raw LaTeX with original delimiters, smaller file size, requires client-side rendering.
|
|
10
|
+
|
|
11
|
+
- Browser Rendering Script (`auto-render.js`):
|
|
12
|
+
- New browser bundle for client-side math rendering at `es5/browser/auto-render.js`.
|
|
13
|
+
- Renders MathML or LaTeX content to SVG.
|
|
14
|
+
- Generates hidden format elements for context menu compatibility.
|
|
15
|
+
- Configurable accessibility support via `MathpixAccessibilityConfig`:
|
|
16
|
+
- `assistive_mml`: Add `<mjx-assistive-mml>` for screen readers.
|
|
17
|
+
- `include_speech`: Add `aria-label` with speech text.
|
|
18
|
+
|
|
19
|
+
- Browser Speech Script (`add-speech.js`):
|
|
20
|
+
- New browser bundle for adding speech to already-rendered SVG at `es5/browser/add-speech.js`.
|
|
21
|
+
- Use when SVG was rendered with `assistiveMml: true` but without `sre` (speech).
|
|
22
|
+
- Loads SRE dynamically and adds `aria-label`, `role="math"`, `tabindex` to `mjx-container` elements.
|
|
23
|
+
- Requires `mjx-assistive-mml` to be present in the rendered output.
|
|
24
|
+
- Exposes `window.MathpixSpeech.addSpeechToRenderedMath(container?)`.
|
|
25
|
+
|
|
26
|
+
- Accessibility:
|
|
27
|
+
- `mjx-assistive-mml` is no longer marked with `aria-hidden="true"` when accessibility options are enabled. Previously, the assistive MathML element was hidden from screen readers even when the user explicitly requested accessibility via `assistiveMml: true` or `sre`. Now, if any accessibility option is set, the MathML content is exposed to assistive technology — either via `aria-labelledby` (pointing to the assistive MML) or via `aria-label` (SRE speech text). This affects both server-side rendering (`addAriaToMathHTML`) and the new browser bundles.
|
|
28
|
+
|
|
29
|
+
- Fixes:
|
|
30
|
+
- Fixed centering issue for equations with numbering inside `.math-block[data-width="full"]`.
|
|
31
|
+
|
|
32
|
+
- Docs:
|
|
33
|
+
- Added implementation details in `pr-specs/2026-01-html-math-output-options.md`.
|
|
34
|
+
|
|
3
35
|
## [2.0.35] - 13 February 2026
|
|
4
36
|
|
|
5
37
|
- Tabular:
|