Skip to content

Instantly share code, notes, and snippets.

@dpvc
Last active August 21, 2020 19:45
Show Gist options
  • Save dpvc/15c2f7a1234e01a898c1a8127f1156e3 to your computer and use it in GitHub Desktop.
Save dpvc/15c2f7a1234e01a898c1a8127f1156e3 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Change Script Sizes</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("mml Jax Ready", function () {
var MML = MathJax.ElementJax.mml;
var math = MML.math.prototype.defaults;
var mstyle = MML.mstyle.prototype.defaults;
math.scriptsizemultiplier = mstyle.scriptsizemultiplier = .85;
});
</script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS_SVG"></script>
</head>
<body>
Math with less script size reduction:
$$
x^{x^{x^x}}
$$
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Change Script Sizes</title>
<script>
MathJax = {
startup: {
ready() {
const {MmlMath} = MathJax._.core.MmlTree.MmlNodes.math;
const {MmlMstyle} = MathJax._.core.MmlTree.MmlNodes.mstyle;
MmlMath.defaults.scriptsizemultiplier = MmlMstyle.defaults.scriptsizemultiplier = .85;
MathJax.startup.defaultReady();
}
}
}
</script>
<script type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>
</head>
<body>
Math with less script size reduction:
$$
x^{x^{x^x}}
$$
</body>
</html>
@dpvc
Copy link
Author

dpvc commented Aug 6, 2020

@philschatz, OK here's the way to do it.

First, make a directory extensions in the folder with your mathjax-node program, and place a file called scriptsizemultipler.js in it that contains

var path = require('path');
var mjAPI = require("./lib/main.js");

MathJax.Hub.Register.StartupHook("mml Jax Ready", function () {
  var MML = MathJax.ElementJax.mml;
  var math = MML.math.prototype.defaults;
  var mstyle = MML.mstyle.prototype.defaults;
  math.scriptsizemultiplier = mstyle.scriptsizemultiplier = .85;
});

MathJax.Ajax.loadComplete('[extensions]/scriptsizemultiplier.js');

Then in your mathjax-node application, use

var path = require('path');
var mjAPI = require('mathjax-node');

mjAPI.config({
  extensions: '[extensions]/scriptsizemultiplier.js',
  paths: {extensions: path.join(__dirname, 'extensions')}
});

This will load your extension from the extensions folder. Then your mjAPI.typeset() calls should use the modified script sizes.

Note that the file name used and the loadComplete() call must match up correctly. Let me know if you have any questions.

@philschatz
Copy link

Awesome, thank you! These different techniques are helpful to be able to get at MathJax internals with different permutations (browser/node and v2/3).

I notice they are given to users to provide workarounds before a new version is released. Is there a place that already has these techniques listed and if not, where would be the best place for me to add them? MathJax-docs, MathJax-demos-node, ... others?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment