Repository navigation
Correct math unparsing - #7865
Conversation
804b39a to
7cdb8b0
Compare
|
One interesting note is that the new --- math-call-symbol-named-argument eval ---
// Error: 10-18 named-argument syntax can only be used with functions
// Hint: 3-6 `phi` is not a function
// Hint: 10-18 to render the colon as text, escape it: `alpha\: y`
$ phi(x, alpha: y) $I tested, and this renders great on the command line, but it may be worth opening an issue in the WebApp repo if it doesn't render well there. error: named-argument syntax can only be used with functions
┌─ <stdin>:1:9
│
1 │ $ phi(x, alpha: y) $
│ --- ^^^^^^^^
│ │
│ `phi` is not a function
│
= hint: to render the colon as text, escape it: `alpha\: y` |
Aware of that! It's not yet well-handled in the dev version on the web app, but we want to deal with that before the next release.
The hint in |
laurmaedje
left a comment
There was a problem hiding this comment.
Thanks for your work on this! It's apparent that you paid a lot of attention to the details. The approach seems very solid to me, I just have a few comments on a few design decisions and on a few edge cases in behavior.
| drain_into_array(&mut pos, start, self.span()); | ||
| } | ||
|
|
||
| named.extend(pos); |
There was a problem hiding this comment.
since this changes the order, I wonder whether the order of named vs pos arguments is currently observable other than via repr. maybe actually not. but either way, we'd probably not want to give any guarantees on that anyway.
cea12d3 to
cf4cf19
Compare
|
Updates!
|
cf4cf19 to
632e146
Compare
|
Great! I'll take a look at the updates soon. I merged #7897, so you might want to rebase math-syntax and this off of main and I can then reset |
632e146 to
8d62fbb
Compare
laurmaedje
left a comment
There was a problem hiding this comment.
As discussed, I still had some pending comments, but we basically discussed everything syncly already, so this is just for completeness.
On the core logic in call.rs, the changes look fine to me. I'd take one last look once we have finalized the error messages and hints, but otherwise it should be fine.
Let me know if further input from my side is needed!
e1f7194 to
c78e183
Compare
4c10172 to
ab061d0
Compare
|
Thank you! |
commit 65301b2 Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Date: Fri Jun 5 00:57:12 2026 +0000 build: update tinymist to 0.14.23 commit 3ac7c69 Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Date: Thu Jun 4 23:30:34 2026 +0000 build: update tinymist to 0.14.23-rc1 commit 4f5efbf Author: paran3xus <[email protected]> Date: Thu Jun 4 12:41:19 2026 +0000 feat: add compatibility for typst/typst#7865 and typst/typst#8116 commit cb25b2e Author: paran3xus <[email protected]> Date: Sat May 16 10:06:29 2026 +0000 fix: adapt typstyle-consistency to typst/typst#7964 commit ae25cb3 Author: paran3xus <[email protected]> Date: Sat May 16 10:06:22 2026 +0000 fix: adapt today to typst/typst#7691 commit c5702de Author: paran3xus <[email protected]> Date: Sat May 16 05:14:33 2026 +0000 build: patch typst-bundle commit aeffa37 Author: paran3xus <[email protected]> Date: Fri May 15 05:09:16 2026 +0000 build: bump tinymist-world to nightly (remote branch) commit 8ea80b1 Author: paran3xus <[email protected]> Date: Thu May 14 05:08:26 2026 +0000 build: bump typst to nightly (local patch) a
This PR is part of the Typst 0.15 nightly cleanup stack. It sits on top of the path-model group and keeps this slice focused on analyzer, query, debug, lint, eval, and typlite API adaptation. ## Upstream Typst Changes - [`typst/typst#7542`](typst/typst#7542) changes function internals. Tinymist updates signature, definition, hover, and rename paths that inspect function internals. - [`typst/typst#7543`](typst/typst#7543) moves call sites toward `to_element`-style element handling. Tinymist updates field access, completion kind inference, and syntax type checking accordingly. - [`typst/typst#7808`](typst/typst#7808) changes parameter metadata. Tinymist updates signature help, built-in type metadata, scope completion, and type completion to the new parameter representation. - [`typst/typst#8215`](typst/typst#8215) requests the standard library from `World` once upfront. Tinymist updates tracked values, upstream helpers, global analysis, DAP request evaluation, and eval engine construction to use the preloaded library path. - [`typst/typst#7865`](typst/typst#7865), [`typst/typst#8116`](typst/typst#8116), and `typst/typst@5326cd297` adjust math call, math field, and prime syntax. Tinymist updates syntax matchers, coverage instrumentation, debugger instrumentation, lint behavior, expression parsing, and query fixtures. - [`typst/typst#7490`](typst/typst#7490) and `typst/typst@cfdd4238b` change font metadata APIs. Tinymist updates document metrics and symbol glyph handling. - `typst/typst@0f04fd176` changes diagnostic hints into spanned values. Tinymist updates diagnostic hint rendering. - [`typst/typst#7897`](typst/typst#7897) introduces import item placeholders and related attach/text API changes. Tinymist updates import completions and math text/attach matching. - Typst 0.15 makes `typst::ROUTINES` private, adds the library argument to `typst_eval::eval`, and protects engine introspection. Tinymist updates `typst-shim` eval for both nightly and default feature builds. ## Tinymist Changes - Ports analysis and query code to the updated function, element, parameter, font, and math syntax APIs. - Updates debug coverage and debugger instrumentation for the new math call/field syntax shapes. - Updates lint behavior so function-call and math-call handling stay aligned. - Updates DAP and `crityp` to the preloaded engine library path. - Updates `typst-shim` eval and syntax compatibility modules so both `nightly` and default feature builds compile against the current Typst 0.15 dependency set. - Refreshes targeted query and typlite fixtures affected by these API and syntax behavior changes. --------- Co-authored-by: paran3xus <[email protected]>
This PR is part of the Typst 0.15 nightly cleanup stack. It sits on top of the path-model group and keeps this slice focused on analyzer, query, debug, lint, eval, and typlite API adaptation. - [`typst/typst#7542`](typst/typst#7542) changes function internals. Tinymist updates signature, definition, hover, and rename paths that inspect function internals. - [`typst/typst#7543`](typst/typst#7543) moves call sites toward `to_element`-style element handling. Tinymist updates field access, completion kind inference, and syntax type checking accordingly. - [`typst/typst#7808`](typst/typst#7808) changes parameter metadata. Tinymist updates signature help, built-in type metadata, scope completion, and type completion to the new parameter representation. - [`typst/typst#8215`](typst/typst#8215) requests the standard library from `World` once upfront. Tinymist updates tracked values, upstream helpers, global analysis, DAP request evaluation, and eval engine construction to use the preloaded library path. - [`typst/typst#7865`](typst/typst#7865), [`typst/typst#8116`](typst/typst#8116), and `typst/typst@5326cd297` adjust math call, math field, and prime syntax. Tinymist updates syntax matchers, coverage instrumentation, debugger instrumentation, lint behavior, expression parsing, and query fixtures. - [`typst/typst#7490`](typst/typst#7490) and `typst/typst@cfdd4238b` change font metadata APIs. Tinymist updates document metrics and symbol glyph handling. - `typst/typst@0f04fd176` changes diagnostic hints into spanned values. Tinymist updates diagnostic hint rendering. - [`typst/typst#7897`](typst/typst#7897) introduces import item placeholders and related attach/text API changes. Tinymist updates import completions and math text/attach matching. - Typst 0.15 makes `typst::ROUTINES` private, adds the library argument to `typst_eval::eval`, and protects engine introspection. Tinymist updates `typst-shim` eval for both nightly and default feature builds. - Ports analysis and query code to the updated function, element, parameter, font, and math syntax APIs. - Updates debug coverage and debugger instrumentation for the new math call/field syntax shapes. - Updates lint behavior so function-call and math-call handling stay aligned. - Updates DAP and `crityp` to the preloaded engine library path. - Updates `typst-shim` eval and syntax compatibility modules so both `nightly` and default feature builds compile against the current Typst 0.15 dependency set. - Refreshes targeted query and typlite fixtures affected by these API and syntax behavior changes. --------- Co-authored-by: paran3xus <[email protected]>
This PR is part of the Typst 0.15 nightly cleanup stack. It sits on top of the path-model group and keeps this slice focused on analyzer, query, debug, lint, eval, and typlite API adaptation. - [`typst/typst#7542`](typst/typst#7542) changes function internals. Tinymist updates signature, definition, hover, and rename paths that inspect function internals. - [`typst/typst#7543`](typst/typst#7543) moves call sites toward `to_element`-style element handling. Tinymist updates field access, completion kind inference, and syntax type checking accordingly. - [`typst/typst#7808`](typst/typst#7808) changes parameter metadata. Tinymist updates signature help, built-in type metadata, scope completion, and type completion to the new parameter representation. - [`typst/typst#8215`](typst/typst#8215) requests the standard library from `World` once upfront. Tinymist updates tracked values, upstream helpers, global analysis, DAP request evaluation, and eval engine construction to use the preloaded library path. - [`typst/typst#7865`](typst/typst#7865), [`typst/typst#8116`](typst/typst#8116), and `typst/typst@5326cd297` adjust math call, math field, and prime syntax. Tinymist updates syntax matchers, coverage instrumentation, debugger instrumentation, lint behavior, expression parsing, and query fixtures. - [`typst/typst#7490`](typst/typst#7490) and `typst/typst@cfdd4238b` change font metadata APIs. Tinymist updates document metrics and symbol glyph handling. - `typst/typst@0f04fd176` changes diagnostic hints into spanned values. Tinymist updates diagnostic hint rendering. - [`typst/typst#7897`](typst/typst#7897) introduces import item placeholders and related attach/text API changes. Tinymist updates import completions and math text/attach matching. - Typst 0.15 makes `typst::ROUTINES` private, adds the library argument to `typst_eval::eval`, and protects engine introspection. Tinymist updates `typst-shim` eval for both nightly and default feature builds. - Ports analysis and query code to the updated function, element, parameter, font, and math syntax APIs. - Updates debug coverage and debugger instrumentation for the new math call/field syntax shapes. - Updates lint behavior so function-call and math-call handling stay aligned. - Updates DAP and `crityp` to the preloaded engine library path. - Updates `typst-shim` eval and syntax compatibility modules so both `nightly` and default feature builds compile against the current Typst 0.15 dependency set. - Refreshes targeted query and typlite fixtures affected by these API and syntax behavior changes. --------- Co-authored-by: paran3xus <[email protected]>
This is now a normal PR targeting
mainPart of the Math Syntax RefactorThis PR is part of the exhaustive math syntax refactor. It should be considered exploratory, and not necessarily a final decision, even if merged to the
math-syntaxbranch. Non-specific feedback for this change should go in one of its related issues.As a quick refresher, recall these existing features of math arguments:
$func(, , , )$$mat(1, , ; ,2, ; , ,3;)$$func(..spread, .. not-spread)$$func(named-param: value, not-named : X)$This PR implements correct math unparsing by rewriting the entire math function call infrastructure and refactoring how we evaluate method function calls. It adds two new SyntaxKinds to distinguish math calling and math arguments, and now handles two-dimensional arguments in evaluation rather than parsing.
With my prior PR, #7742, this will fully resolve #7274.
#7524 is somewhat related, but is not resolved by this PR, although
$sin(#1)$does now work.The first commit adds and updates many test cases for math function calls that will be improved in the final commit (although the test ordering in that file is still quite messy). The second commit moves some code in
call.rsaround to improve locality, which I prefer instead of putting allimpl Traitblocks before all free functions. Finally, the third commit implements everything and updates the tests. I apologize that it is quite large, but everything in it depends on everything else, so one-commit it shall stay.What is unparsing?
In Typst's math mode, we allow
$vec(1, 2)$to call themath.vecfunction, but we also allow$pi(1, 2)$to render as the symbolpinext to(1, 2)as content. These two examples are syntactically indistinguishable, so we parse them into the same syntax tree and interpret that tree at runtime as either function arguments or content based on the type of the callee. To avoid parsing while evaluating, we currently fully parse the argument list as though we would call a function, and if we end up needing to render arguments as content, we "unparse" the argument structure and build content by manually inserting commas between arguments and wrapping in parentheses.However, the old approach is wildly incomplete code-wise and suffers from architectural choices that make unparsing, named/spread argument syntax, and two-dimensional arguments fragile.
In the old approach:
$pi(1; 2)$$pi(x: y)$$pi(1, ..#none, 3)$only renders one comma between1and3#repr($pi(, | ,)$)vs.#repr($pi (, | ,)$)$mat(1, delim: "[", 2;)$and$mat(1, 2; 3, 4, delim: "[")$$mat(..#(delim: "["), 1, 2; 3, 4)$$sin(#1)$would always fail because we try to cast them to content instead of displaying them like we do for$#1$This PR makes almost all of these work correctly and produce the output you would expect.
The two exceptions are that we error (with useful hints) if we would unparse a call that uses either spread argument sytnax or named argument syntax (
$ pi(..items) pi(param: y) $). This is because these features resemble code mode too closely and it would be confusing if this sytnax was allowed to be used with non-functions. However, this still follows the rules from above, where adding a single space before the colon or after the two dots will allow unparsing.One thing that is not changing in this PR is that semicolons that directly follow embedded code expressions in arguments still attach to the code instead of creating two-dimensional arguments, e.g.
$mat(#"abc"; #"def"; ;)$only has one row. This may change, but not in this PR.