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
Equivalent of \let
via macros
options
#3737
Comments
Issue #3737 turned out to be how we handled the return value of `expandOnce`. We assumed that, if the return value isn't an `Array`, it's an `instanceof Token`. This isn't necessary true with a user's `macros` object, and given that we don't currently export `Token`, it's pretty difficult to bypass. Given that we never actually use the array return values from `expandOnce`, I changed the return value for `expandOnce` to either a `number` (to indicate the number of expanded tokens, so you could still look up the tokens in the stack if you wanted to) or `false` (to indicate no expansion happened). We can't use `0` for the latter because an actual expansion might result in zero tokens. The resulting code is arguably cleaner. I also documented that `macros` can have object expansions, and specified how to simulate `\let`. Fixes #3737
Is this fixed? |
No, it's not fixed yet in release. #3738 fixes it, but it's currently under review. Thanks for the reminder to respond to the review though. 🙂 |
@edemaine happy to help 😉 |
@MrOddlyFormal in case you're trying to use There's an undocumented |
* fix: Support `\let` via `macros` option Issue #3737 turned out to be how we handled the return value of `expandOnce`. We assumed that, if the return value isn't an `Array`, it's an `instanceof Token`. This isn't necessary true with a user's `macros` object, and given that we don't currently export `Token`, it's pretty difficult to bypass. Given that we never actually use the array return values from `expandOnce`, I changed the return value for `expandOnce` to either a `number` (to indicate the number of expanded tokens, so you could still look up the tokens in the stack if you wanted to) or `false` (to indicate no expansion happened). We can't use `0` for the latter because an actual expansion might result in zero tokens. The resulting code is arguably cleaner. I also documented that `macros` can have object expansions, and specified how to simulate `\let`. Fixes #3737 * Revise macros documentation according to comments
🎉 This issue has been resolved in version 0.16.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Describe the bug:
It's certainly not convenient to do the equivalent of
\let\Oldint=\int
via a user-constructuedmacros
option. In fact, it may not be possible.To Reproduce:
Steps to reproduce the behavior, in Node or browser console:
macros = {};
katex.renderToString("\\let\\Oldint=\\int\\def\\int{\\Oldint\\limits}", {macros, globalGroup: true});
Object.values(macros).forEach((val) => val.tokens.forEach((token) => delete token.loc))
— removeloc
pointers which prevent serializationconsole.log(JSON.stringify(macros))
→
{"\\Oldint":{"tokens":[{"text":"\\int","noexpand":true}],"numArgs":0,"unexpandable":false},"\\int":{"tokens":[{"text":"\\limits"},{"text":"\\Oldint"}],"numArgs":0,"delimiters":[[]]}}
katex.renderToString("\\int", {macros})
works finekatex.renderToString("\\int", {macros: {"\\Oldint":{"tokens":[{"text":"\\int","noexpand":true}],"numArgs":0,"unexpandable":false},"\\int":{"tokens":[{"text":"\\limits"},{"text":"\\Oldint"}],"numArgs":0,"delimiters":[[]]}}})
causes an infinite loop (!).Expected behavior:
Manually constructing the
macros
object in the same shape as produced by\let
should simulate the behavior of\let
.We might also want to document this shape, or otherwise make it easier to request
\let
behavior for built-in commands.Also, an infinite loop should not be possible, even with invalid
macros
input. I would expectmaxExpand
to hit a limit here if nothing else.Screenshots:
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
Additional context:
From #3736
The text was updated successfully, but these errors were encountered: