-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
\mmlToken does not evaluate TeX in its argument #2706
Comments
You are correct that the argument to It is also true that \let\vec=\boldsymbol would do what you need. (Or MathJax = {
tex: {
macros: {
vec: ['\\boldsymbol{#1}', 1]
}
}
}; |
The I'm trying to get an ISO 80000-2 style, which would look something like this (with a custom definition of \newcommand{\vec}[1]{\ifstrequal{#1}{\nabla}{\mmlToken{mo}[mathvariant="bold"]{\unicode{x2207}}}{\mmlToken{mi}[mathvariant="bold-italic"]{#1}}}
\newcommand{\tens}[1]{\mmlToken{mi}[mathvariant="bold-sans-serif"]{#1}} That is, vectors should be bold-italic and operators like Your suggestion of |
I believe that is exactly what the MathJax = {
loader: {load: ['[tex]/physics']},
tex: {
packages: {'[+]': ['physics']},
physics: {
arrowdel: true
}}
}; and you can then get the gradient operator with \[\grad\] Note that the |
@zorkow, I think he wants the nabla without an arrow, so
It should produce the same thing as the original symbol, but in bold, so if it was italic before it would be bold italic, and if was upright, it would just be bold.
In TeX,
The symbols in the Math Aphanumeric Symbols unicode block specify both a character and its weight and style, and the MathML standard explicitly states that these should not be affected by
I can mark this as a feature request, if you want, but it is not likely to be something we pursue (though it could be a community contribution). As I mentioned above, the contents of a token element must be text, not other MathML elements, and "evaluating ... as TeX" in MathJax means converting to MathML. With the definition from lwarp, |
Thanks for the explanations.
I guess it should be restricted to TeX elements that translate into a single Unicode code point, e.g. |
That's even easier, as it should already work now. The |
That would work, but another option would be to redefine MathJax = {
tex: {packages: {'[+]': ['mmltoken-update']}},
startup: {
ready() {
const {Configuration} = MathJax._.input.tex.Configuration;
const {CommandMap} = MathJax._.input.tex.SymbolMap;
const BaseMethods = MathJax._.input.tex.base.BaseMethods.default;
const mmlSymbol = {
nabla: '\u2207',
alpha: '\u03B1',
beta: '\u03B2',
gamma: '\u03B3',
/* etc. */
};
const mmlSymbolRE = new RegExp(`\\\\(${Object.keys(mmlSymbol).join('|')})`, 'g');
new CommandMap('mmltoken-update', {
mmlToken: 'MmlToken'
}, {
MmlToken(parser, name) {
const kind = parser.GetArgument(name);
const attr = parser.GetBrackets(name, '');
const text = parser.GetArgument(name)
.replace(mmlSymbolRE, (match, c) => mmlSymbol[c])
.replace(
/\\unicode\{(.*?)\}/g,
(match, n) => String.fromCodePoint(n.charAt(0) === 'x' ? parseInt(n.slice(1), 16) : parseInt(n))
);
parser.string = `{${kind}}[${attr}]{${text}}`;
parser.i = 0;
BaseMethods.MmlToken(parser, name);
}
});
Configuration.create('mmltoken-update', {
handler: {macro: ['mmltoken-update']}
});
MathJax.startup.defaultReady();
}
}
} you can fill in the rest of the On the other hand, you might want to redefine MathJax = {
tex: {packages: {'[+]': ['bold-vec']}},
startup: {
ready() {
const {Configuration} = MathJax._.input.tex.Configuration;
const {CommandMap} = MathJax._.input.tex.SymbolMap;
const mmlSymbol = {
nabla: '\u2207',
alpha: '\u03B1',
beta: '\u03B2',
gamma: '\u03B3',
/* etc. */
};
const mmlSymbolRE = new RegExp(`\\\\(${Object.keys(mmlSymbol).join('|')})`, 'g');
new CommandMap('bold-vec', {
vec: 'BoldVector'
}, {
BoldVector(parser, name) {
const base = parser.GetArgument(name)
.replace(mmlSymbolRE, (match, c) => mmlSymbol[c])
.replace(
/\\unicode\{(.*?)\}/g,
(match, n) => String.fromCodePoint(n.charAt(0) === 'x' ? parseInt(n.slice(1), 16) : parseInt(n))
);
const [kind, mathvariant] = (base === '\u2207' ? ['mo', 'bold'] : ['mi', 'bold-italic']);
parser.Push(parser.create('token', kind, {mathvariant}, base));
}
});
Configuration.create('bold-vec', {
handler: {macro: ['bold-vec']}
});
MathJax.startup.defaultReady();
}
}
} should do the trick. |
Thanks, your redefined |
Issue Summary
The
\mmlToken
macro cannot be used to wrap TeX into custom MathML. It can currently only be used to wrap plain text.Steps to Reproduce:
Here is sample code and a screenshot. The first and third line render as expected because they are plain (Latin and Greek) text, while the second line leaks TeX code to the page. I would expect lines two and three to look identical.
Technical details:
Notes
@dpvc's answers in #2671 and #2595 led me to
\mmlToken
. The documentation on it is somewhat sparse.I assume this can be worked around by implementing a custom
\vec
macro on the JavaScript level, but I have not succeeded at doing that. My TeX code is coming from an external source and I can't easily change that to deliverα
instead of\alpha
, so I need to get the formatting right via MathJax.The text was updated successfully, but these errors were encountered: