MathJax & Inputs
I am trying to receive text inputs with HTML when dealing with fractions and alignment of equations in MathJax. When I do this, the math typography doesn't work (as shown below). I
Solution 1:
MathJax won't process mathematics that contains HTML tags (other than <br>
and comments), so you are right that what you have done is not going to work. But there is a loophole that can be used to get input fields, as discussed in this post that uses the MathML <semantics>
tag to get HTML into the expression.
<script>
MathJax = {
tex: {packages: {'[+]': ['input']}},
startup: {
ready() {
const Configuration = MathJax._.input.tex.Configuration.Configuration;
const CommandMap = MathJax._.input.tex.SymbolMap.CommandMap;
const TEXCLASS = MathJax._.core.MmlTree.MmlNode.TEXCLASS;
new CommandMap('input', {input: 'Input'}, {
Input(parser, name) {
const xml = parser.create('node', 'XML');
const id = parser.GetBrackets(name, '');
const w = parser.GetBrackets(name, '5em');
const value = parser.GetArgument(name);
xml.setXML(MathJax.startup.adaptor.node('input', {
id: id, value: value, style: {width: w}, xmlns: 'http://www.w3.org/1999/xhtml'
}), MathJax.startup.adaptor);
xml.getSerializedXML = function () {
return this.adaptor.outerHTML(this.xml) + '</input>';
}
parser.Push(
parser.create('node', 'TeXAtom', [
parser.create('node', 'semantics', [
parser.create('node', 'annotation-xml', [
xml
], {encoding: 'application/xhtml+xml'})
])
], {texClass: TEXCLASS.ORD})
);
}
});
Configuration.create('input', {handler: {macro: ['input']}});
MathJax.startup.defaultReady();
}
}
};
</script>
<script id="MathJax-script" defer src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
$$ \int_{\input[sub][1em]{0}}^{\input[sup][1em]{1}} \input[integrand][10em]{}\, dx$$
This could be made into a formal extension, if you will be using it often.
Post a Comment for "MathJax & Inputs"