Skip to content

Commit de08725

Browse files
committed
refactor: upgrade to MathJax v4 for equation rendering
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: passed - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 1e92558 commit de08725

File tree

19 files changed

+509
-284
lines changed

19 files changed

+509
-284
lines changed

lib/node_modules/@stdlib/_tools/utils/tex-equation-to-svg/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var tex2svg = require( '@stdlib/_tools/utils/tex-equation-to-svg' );
4444

4545
#### tex2svg( str\[, options], clbk )
4646

47-
Converts a [TeX][tex] or [LaTeX][latex] `string` to an SVG.
47+
Converts a [TeX][tex] or [LaTeX][latex] string to an SVG.
4848

4949
```javascript
5050
var eqn = 'y = mx + b';
@@ -62,14 +62,13 @@ function clbk( error, svg ) {
6262
}
6363
```
6464

65-
The function accepts the following `options`:
65+
The function accepts the following options:
6666

6767
- **width**: container width in `ex` (used for linebreaking and tags). Default: `100`.
6868
- **ex**: `ex` size in pixels. Default: `6`.
69-
- **inline**: `boolean` indicating whether to format an input `string` as an inline equation. Default: `false`.
70-
- **linebreaks**: `boolean` indicating whether to perform linebreaking. Default: `true`.
69+
- **inline**: boolean indicating whether to format an input string as an inline equation. Default: `false`.
7170

72-
By default, the function formats an input `string` as a displayed equation. To format the `string` as a text (inline) equation, set the `inline` option to `true`.
71+
By default, the function formats an input string as a displayed equation. To format the string as a text (inline) equation, set the `inline` option to `true`.
7372

7473
```javascript
7574
var eqn = 'y = mx + b';
@@ -90,7 +89,7 @@ function clbk( error, svg ) {
9089

9190
#### tex2svg.factory( options )
9291

93-
Creates a reusable `function`.
92+
Creates a reusable function.
9493

9594
```javascript
9695
function clbk( error, svg ) {
@@ -112,7 +111,7 @@ convert( 'w = \\sum_{i=0}^{n} x_i', clbk );
112111
// ...
113112
```
114113

115-
The factory method accepts the same `options` as [`tex2svg()`](#tex2svg).
114+
The factory method accepts the same options as [`tex2svg()`](#tex2svg).
116115

117116
</section>
118117

@@ -144,6 +143,8 @@ The factory method accepts the same `options` as [`tex2svg()`](#tex2svg).
144143

145144
## Examples
146145

146+
<!-- eslint-disable @cspell/spellchecker -->
147+
147148
<!-- eslint no-undef: "error" -->
148149

149150
```javascript
@@ -186,9 +187,8 @@ Options:
186187
-h, --help Print this message.
187188
-V, --version Print the package version.
188189
--width width Container width in ex. Default: 100.
189-
--ex ex ex size in pixels. Default: 6.
190+
--ex ex ex size in pixels. Default: 8.
190191
--inline Format input equation as inline TeX.
191-
--no-linebreaks Disable linebreaking.
192192
```
193193

194194
</section>

lib/node_modules/@stdlib/_tools/utils/tex-equation-to-svg/bin/cli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ function main() {
6969
if ( flags.inline ) {
7070
opts.inline = flags.inline;
7171
}
72-
if ( flags.linebreaks === false ) {
73-
opts.linebreaks = false;
74-
}
7572
tex2svg( args[ 0 ], opts, clbk );
7673

7774
/**

lib/node_modules/@stdlib/_tools/utils/tex-equation-to-svg/docs/usage.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ Usage: tex2svg [options] <equation>
33

44
Options:
55

6-
-h, --help Print this message.
7-
-V, --version Print the package version.
8-
--width width Container width in ex. Default: 100.
9-
--ex ex ex size in pixels. Default: 6.
10-
--inline Format input equation as inline TeX.
11-
--no-linebreaks Disable linebreaking.
6+
-h, --help Print this message.
7+
-V, --version Print the package version.
8+
--width width Container width in ex. Default: 100.
9+
--ex ex ex size in pixels. Default: 8.
10+
--inline Format input equation as inline TeX.

lib/node_modules/@stdlib/_tools/utils/tex-equation-to-svg/etc/cli_opts.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"boolean": [
77
"help",
88
"version",
9-
"inline",
10-
"no-linebreaks"
9+
"inline"
1110
],
1211
"alias": {
1312
"help": [
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MAIN //
22+
23+
/**
24+
* Returns default options.
25+
*
26+
* @private
27+
* @returns {Object} default options
28+
*/
29+
function defaults() {
30+
return {
31+
'svg': {
32+
'display': true,
33+
'containerWidth': 100,
34+
'em': 16,
35+
'ex': 8,
36+
'scale': 1
37+
},
38+
'stripAttributes': true
39+
};
40+
}
41+
42+
43+
// EXPORTS //
44+
45+
module.exports = defaults;

lib/node_modules/@stdlib/_tools/utils/tex-equation-to-svg/lib/defaults.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/node_modules/@stdlib/_tools/utils/tex-equation-to-svg/lib/factory.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020

2121
// MODULES //
2222

23-
var mathjax = require( 'mathjax-node-sre' );
2423
var isFunction = require( '@stdlib/assert/is-function' );
2524
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2625
var format = require( '@stdlib/string/format' );
27-
var copy = require( '@stdlib/utils/copy' );
28-
var defaults = require( './defaults.json' );
26+
var defaults = require( './defaults.js' );
2927
var validate = require( './validate.js' );
28+
var MathJax = require( './mathjax' );
3029

3130

3231
// MAIN //
@@ -38,7 +37,6 @@ var validate = require( './validate.js' );
3837
* @param {PositiveInteger} [options.width=100] - container width in `ex`
3938
* @param {PositiveInteger} [options.ex=6] - `ex` size in pixels
4039
* @param {boolean} [options.inline=false] - specifies whether to format the input string as an inline equation
41-
* @param {boolean} [options.linebreaks=true] - enable linebreaking
4240
* @throws {TypeError} options argument must be an object
4341
* @throws {TypeError} must provide valid options
4442
* @returns {Function} function to convert a string to an SVG
@@ -60,16 +58,24 @@ var validate = require( './validate.js' );
6058
* }
6159
*/
6260
function factory( options ) {
61+
var sopts;
6362
var opts;
6463
var err;
65-
opts = copy( defaults );
66-
err = validate( opts, options );
64+
65+
opts = defaults();
66+
67+
sopts = opts.svg;
68+
err = validate( sopts, options );
6769
if ( err ) {
6870
throw err;
6971
}
70-
if ( opts.inline ) {
71-
opts.format = 'inline-TeX';
72-
delete opts.inline;
72+
if ( sopts.inline ) {
73+
sopts.display = false;
74+
delete sopts.inline;
75+
}
76+
if ( sopts.width ) {
77+
sopts.containerWidth = sopts.width;
78+
delete sopts.width;
7379
}
7480
return tex2svg;
7581

@@ -84,29 +90,15 @@ function factory( options ) {
8490
* @returns {void}
8591
*/
8692
function tex2svg( str, clbk ) {
93+
var mathjax;
8794
if ( !isString( str ) ) {
8895
throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );
8996
}
9097
if ( !isFunction( clbk ) ) {
9198
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) );
9299
}
93-
opts.math = str;
94-
mathjax.typeset( opts, done );
95-
/**
96-
* Callback invoked upon converting a string to SVG.
97-
*
98-
* @private
99-
* @param {Object} data - output
100-
* @returns {void}
101-
*/
102-
function done( data ) {
103-
var err;
104-
if ( data.errors ) {
105-
err = new Error( data.errors[ 0 ] );
106-
return clbk( err );
107-
}
108-
clbk( null, data.svg );
109-
}
100+
mathjax = new MathJax();
101+
mathjax.tex2svg( str, sopts, clbk );
110102
}
111103
}
112104

lib/node_modules/@stdlib/_tools/utils/tex-equation-to-svg/lib/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ var factory = require( './factory.js' );
3333
* @param {PositiveInteger} [options.width=100] - container width in `ex`
3434
* @param {PositiveInteger} [options.ex=6] - `ex` size in pixels
3535
* @param {boolean} [options.inline=false] - specifies whether to format the input string as an inline equation
36-
* @param {boolean} [options.linebreaks=true] - enable linebreaking
3736
* @param {Callback} clbk - callback to invoke once finished
3837
* @throws {TypeError} first argument must be a string
3938
* @throws {TypeError} options argument must be an object

0 commit comments

Comments
 (0)