Repository navigation
Conversation
|
Thanks for taking this on on such short notice! Comments
ContinuabilityBelow is a table of how different snippets behave in 0.13.1, main, this PR, and finally what my personal preference (given the constraint of consistency) would be. The difference compared to this PR is that the base determines continuability of attach elements instead of the last leaf.
Notes
|
|
I really don't understand why we want to keep the same frustrating behavior with fractions as we used to have for attachments. It's really the exact same problem. If anything, the thing that needs fixing is that It may interfere slightly less often, but it does interfere nonetheless. |
|
Closing for #7084. I'll open a new PR for the math parser cleanup commits that can happen later. |

This is a refactor of the existing math parser to enable parsing implicit math function calls for non-identifiers in new circumstances: for example, we currently parse
1/f(x)as1/(f(x)), but1/f'(x)as1/f' (x). This changes the latter to parse as1/(f'(x)).This is related to the recent precedence changes in math and PRs #7003 and #6442, but was particularly spurned by a discord discussion with Laurenz.
The way we do it is that instead of inferring an implict call by starting at a "continuable" node and encountering an opening delimiter, we now look backwards from every opening delimiter to see if the previous leaf node was continuable, then infer the implicit call. This was how I did this in the runtime math parser implementation, although it was easier then because we had a flat list of syntaxnodes instead of having to traverse the previous node's last child until we get a leaf.
However, after implementing it, I'm not certain this is entirely desirable. The original basis for this in the runtime math parser was mostly accidental, and I likely would have avoided this if I were thinking of it. That said, I can see some appeal, especially for simple cases like
f'(x)/g'(x), but it starts to get weird when things likesin^2(x)/cos^2(x)don't work.Being truly honest, I'd still prefer to parse fractions at a higher precedence than juxtaposition in general (e.g. require parentheses for even
f(x)/g(x)). I think it's more honest to what Typst is actually doing operationally, and I particularly think that it composes better when compared to some of the weird cases from implicit function calls. It makes for a simple rule. But it wouldn't really be ergonomic without runtime math parsing for true function calls, so I digress.Here's a reference of the added test before and after this change:
Note that only the final commit implements the change. The prior commits are cleanup of the existing code to make the final commit feasible. Note that the
MathPrimes+Bangrefactor commit is taken from #7003.I know this PR would be better if I could only include the final change, but it was actually incredibly tricky to get right, and cleaning up the parser's code significantly helped in getting it done. Part of what makes this change so tricky is that implicit function calls in math act like a special kind of juxtaposition operator, but the current parser doesn't have any notion of a juxtaposition operator at all (as opposed to my runtime math parser), so adding just a touch of that understanding without refactoring everything required a lot of precision. I do think it's correct, but I'm only confident in saying so because I could analyse the cleaner code.