Skip to content

Implement math.var to differentiate $a$ and $"a"$ in equations.#4638

Closed
wrzian wants to merge 6 commits intotypst:mainfrom
wrzian:var_elem
Closed

Implement math.var to differentiate $a$ and $"a"$ in equations.#4638
wrzian wants to merge 6 commits intotypst:mainfrom
wrzian:var_elem

Conversation

@wrzian
Copy link
Contributor

@wrzian wrzian commented Jul 29, 2024

This is a draft implementation of the math.var updates for semantically separating math variables from other text in equations.

This will close the ancient #274 and is the beginning of a solution for #254, #366, and #1125.

This removes the auto-italics correction on single-character text in math that is not a math.var element. However, my intent is that math layout will eventually be updated to only use the math font within math.var elements and use the document font for strings and normal content in math. That update will likely come in a later PR, and I would like to leave it as a separate discussion for now, see #366.

This is similar to PR #1779 by @damaxwell. However, with the updates to the layout system, I wasn't able to use much of that code at all and wrote most of this from scratch. That PR was closed for a number of open questions around show rules and regex replacement. This PR is focused mainly on fixing the auto-italics issue and leaving deeper language changes related to show-rules or new syntax for a later date.

There is still a lot to do and many details to fuss over, but the core has been implemented, and I'm happy to report only 4 tests are currently failing! There have been so many edge cases and horrible details in implementing this, but I'd love to nail the remaining ones down and maybe get this shipped for 0.12.

The four currently failing tests are the following:

  • math-attach-show-limit (tests/suite/math/attach.typ:106) and math-symbol-show-rule (tests/suite/math/interactions.typ:67)
    These two are related to show-rules on symbol elements in math not working at all right now.
  • enum-numbering-closure-nested-complex (tests/suite/model/enum.typ:86)
    This one is probably just weird behavior that we're going to ignore. But I'm really not sure what to do for it.
  • math-lr-color (tests/suite/math/delimited.typ:42)
    This is related to the semantic difference between math.var and text in general. Not sure what the resolution should be here, but requires some thought about how text and math.var are styled.

I'm not fully sure how to fix these right now, and would love any guidance or suggestions from others.
EDIT: fixed the remaining failures! Will add an explanation for the test updates below.

I'll also make a general call for help: I would love any help updating documentation around symbols/math.var or adding tests to var.typ. I'll be doing this myself as I can, but would appreciate any others chipping-in.

@wrzian wrzian changed the title Implement math.var to finally differentiate $a$ and $"a"$ in equations. Implement math.var to differentiate $a$ and $"a"$ in equations. Aug 7, 2024
@wrzian
Copy link
Contributor Author

wrzian commented Aug 7, 2024

I believe this also closes #3727. I'll double check when adding tests to var.typ.

@laurmaedje laurmaedje added the waiting-on-review This PR is waiting to be reviewed. label Aug 15, 2024
@wrzian wrzian force-pushed the var_elem branch 2 times, most recently from b4ee161 to 5f31dcc Compare September 13, 2024 04:23
@wrzian
Copy link
Contributor Author

wrzian commented Sep 13, 2024

Rebased onto main. Still need to document what the changes and tradeoffs are before review.

@laurmaedje
Copy link
Member

I'm sorry for completely ignoring this PR for months. It fell into the unforunate spot of being a very complex and intricate topic that is quite far removed from anything else I'd been thinking about at the time.

I took a look at the changes now and I must admit that I have a somewhat uneasy feeling about having a bool in symbol that states whether it came from math. It feels wrong somehow. What's your take on this particular change?

@laurmaedje laurmaedje removed the waiting-on-review This PR is waiting to be reviewed. label Nov 1, 2024
@wrzian wrzian force-pushed the var_elem branch 2 times, most recently from 14b0207 to e3d1be6 Compare November 3, 2024 20:03
@wrzian
Copy link
Contributor Author

wrzian commented Nov 5, 2024

No worries on the delay! This change is a necessary fix, but certainly not the most urgent. It's also been a while since I've touched this, but that's given me some time to cook.

I was able to rebase from shatter (this PR got hit hard). I've tried to keep the changes roughly the same so we have something to test with/discuss, but I do want to change the implementation.


Having rewritten most of the code again, I agree that just a bool in Symbol is probably not right. But I'm not certain what else i would do at the moment. It might function as a short term solution, but that will require better defining what we want out of the split to math.var.

@laurmaedje laurmaedje added the waiting-on-design This PR or issue is blocked by design work. label Nov 17, 2024
@laurmaedje
Copy link
Member

We should probably discuss this more on Discord.

@laurmaedje
Copy link
Member

Maybe some more direct discussion would be nice. How about having an actual Zoom or Discord design call about this sometime in January?

@wrzian
Copy link
Contributor Author

wrzian commented Jan 17, 2025

Rebased from main, but still need to fix a few things

Test intentionally had `math.var` layout behavior, but only by implicitly
having single characters in certain content -- updated by editing the code
to explicitly or implicitly call `math.var`. (implicitly by changing strings
to character escapes in equations)

```
math/alignment.typ:4       : math-align-weird
math/attach.typ:164        : math-attach-nested-base
math/delimited.typ:42      : math-lr-color
math/interactions.typ:92   : issue-math-realize-scripting
math/stretch.typ:57        : math-stretch-shorthand
math/text.typ:29           : math-optical-size-primes

foundations/content.typ:53 : content-fields-complex
model/enum.typ:86          : enum-numbering-closure-nested-complex
```

Test did not intend to use `math.var` behavior -- fixed by updating the
reference image
```
math/interactions.typ:15 : math-equation-auto-wrapping
math/mat.typ:109         : math-mat-align-implicit
math/mat.typ:117         : math-mat-align-explicit-left
math/mat.typ:101         : math-mat-align-explicit-alternating
math/mat.typ:125         : math-mat-align-explicit-right
math/vec.typ:13          : math-vec-align-explicit-alternating
```
@wrzian
Copy link
Contributor Author

wrzian commented Jan 18, 2025

Cleaned this pull request up for historical purposes, but we had our call and the resolution was to not create VarElem at the moment, but convert MathText kinds into a new SymbolElem that will be used for symbols going forward. We'll do the larger change of something like VarElem later, but SymbolElem should allow us to close #274.

Closing this for now and will open a new PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on-design This PR or issue is blocked by design work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants