Skip to content

Commit 1ee8483

Browse files
authored
Merge pull request #391 from mathjax/134
[main] add option for custom path variables
2 parents 725c7d9 + d2065e6 commit 1ee8483

5 files changed

Lines changed: 44 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ The `config` method is used to set _global_ configuration options. Its default o
6363
undefinedCharError: false, // determines whether "unknown characters" (i.e., no glyph in the configured fonts) are saved in the error array
6464
extensions: '', // a convenience option to add MathJax extensions
6565
fontURL: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/fonts/HTML-CSS', // for webfont urls in the CSS for HTML output
66+
paths: {}, // configures custom path variables (e.g., for third party extensions, cf. test/config-third-party-extensions.js)
6667
MathJax: { } // standard MathJax configuration options, see https://docs.mathjax.org for more detail.
6768
}
6869
```

lib/main.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var displayMessages = false; // don't log Message.Set() calls
4040
var displayErrors = true; // show error messages on the console
4141
var undefinedChar = false; // unknown characters are not saved in the error array
4242
var extensions = ''; // no additional extensions used
43+
var paths = {}; // additional paths (for third party extensions)
4344
var fontURL = ''; // location of web fonts for CHTML
4445

4546
var defaults = {
@@ -156,6 +157,11 @@ function ConfigureMathJax() {
156157
AuthorInit: function () {
157158
MathJax = window.MathJax;
158159

160+
// Add custom paths to configuration
161+
for (let key in paths) {
162+
MathJax.Ajax.config.path[key] = paths[key];
163+
}
164+
159165
delete MathJax.Hub.config.styles; // don't need any styles
160166
MathJax.Hub.Startup.MenuZoom = function () {}; // don't load menu or zoom code
161167
MathJax.Extension.MathEvents = {
@@ -324,7 +330,7 @@ function ConfigureMathJax() {
324330
this.d = this.D = (bbox.height + bbox.y)*scale;
325331
}
326332
});
327-
333+
328334
//
329335
// Don't have mglyph load images
330336
//
@@ -515,7 +521,7 @@ function ConfigureMathJax() {
515521
});
516522
}
517523
};
518-
524+
519525
if (extensions) {
520526
//
521527
// Parse added extensions list and add to standard ones
@@ -958,6 +964,7 @@ exports.config = function (config) {
958964
if (config.displayErrors != null) {displayErrors = config.displayErrors}
959965
if (config.undefinedCharError != null) {undefinedChar = config.undefinedCharError}
960966
if (config.extensions != null) {extensions = config.extensions}
967+
if (config.paths != null) {paths = config.paths}
961968
if (config.fontURL != null) {fontURL = config.fontURL}
962969
if (config.MathJax) {
963970
// strip MathJax config blocks to avoid errors

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/assets/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MathJax.Hub.Register.StartupHook("TeX Jax Ready", function () {
2+
MathJax.InputJax.TeX.Definitions.Add({
3+
macros: {
4+
test: ["Macro", "\text{This is a Test}"]
5+
}
6+
});
7+
});
8+
9+
MathJax.Ajax.loadComplete("[test]/test.js");
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var tape = require('tape');
2+
var mjAPI = require("../lib/main.js");
3+
const path = require('path');
4+
5+
tape('Configuring third party extensions', function(t) {
6+
t.plan(1);
7+
var tex = '\\test';
8+
mjAPI.config( {
9+
extensions: '[test]/test.js',
10+
paths: {
11+
'test': path.join(__dirname,'assets/')
12+
}
13+
});
14+
mjAPI.start();
15+
mjAPI.typeset({
16+
math: tex,
17+
format: "TeX",
18+
mmlNode: true
19+
}, function(data) {
20+
t.notOk(data.errors, 'No error loading the extension');
21+
});
22+
});

0 commit comments

Comments
 (0)