\set{ causes an error
Issue Summary
I have tried it on Obsidian, overleaf and a blank document and \set{ throws an exception instead of returning html with error code.
(For other error latex { for example it gives back html so I presume this is a bug?)
Steps to Reproduce:
- For the html document
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script
src="https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js"
defer
></script>
</head>
<body></body>
</html>
(what vscode gave me as template)
2. in the console, execute the command await window.MathJax.tex2chtmlPromise("\\set{")
3. get the error
Uncaught (in promise) TypeError: can't access property "isInferred", t is null
appendChild https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
setChildren https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
setChildren https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
setChildren https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
createNode https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
create https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
compile https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
compile https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
methodActions https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
renderConvert https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
convert https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
convert https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
convertPromise https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
Rn https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
Rn https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
convertPromise https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
e https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
r https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
promise callback*r https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
e https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
promise callback*e https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
In https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
convertPromise https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
_readyPromise https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
promise callback*whenReady https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
convertPromise https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
<anonymous> https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js:1
<anonymous> debugger eval code:2
<anonymous> debugger eval code:3
[tex-mml-chtml.js:1:174878](https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js)
As you see in the picture await window.MathJax.tex2chtmlPromise("{") does give html even though there is a syntax error.
I am not a developer using mathjax, but a user of Obsidian 1.9.12 and overleaf,
so excuses if this covered in the documentation but I couldn't find anything
Technical details:
- MathJax Version: 4.0/3.2
- Client OS: fedora 41 kde 6.4/ windows 10 22H2
- electron: 37.3.1 (
console.log(process.versions.electron;gave that as output in obsidian) - Firefox/librewolf 143.0-1
I am using the following MathJax configuration:
MathJax = {
...
};
and loading MathJax via
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
See example above and I don't know the environment of obsidian and overleaf
Supporting information:
see above and I don't know the configuration of overleaf and obsidian.
Thanks for the error report. The handling of misbalanced braces for \set and some other macros in the braket package is not correct. Have made a PR to correct the situation, which will be in the next release.
In the meantime, you can incorporate
MathJax = {
loader: {
'[tex]/braket': {
ready() {
const BraketMethods = MathJax._.input.tex.braket.BraketMethods.default;
const braket = function (parser, name, open, close, stretchy, barmax, space = false) {
const i = parser.i;
parser.GetArgument(name);
parser.i = i;
return BraketMethods.Braket(parser, name, open, close, stretchy, barmax, space);
};
const {MapHandler} = MathJax._.input.tex.MapHandler;
const map = MapHandler.getMap('Braket-macros');
['set', 'braket', 'Set', 'Braket'].forEach((name) => map.lookup(name)._func = braket);
},
},
},
};
into your MathJax configuration (or add it if you don't have one).