Skip to content

KaTeX (2/n): Support horizontal and vertical offsets for spans #1452

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

rajveermalviya
Copy link
Member

Stacked on top of: #1408

Web Flutter
Screenshot 2025-04-01 at 22 08 22 Screenshot 2025-04-01 at 22 09 00

Related: #46

gnprice added 12 commits April 22, 2025 13:06
This way there's nothing that needs to happen at the bottom of the
loop, if any of the cases matched.
Conveniently, the two redundant rules say the exact same thing
when they apply.  So the first one has no effect, and we can
ignore it.
Before this change, all cases of this switch statement either
continue the loop, or throw, or set classFound to true.
The error therefore gets logged just if none of the cases matched.

So we can express the same behavior with a default case.
This makes the reasoning about these index values more local.
Like an early return, this (a) brings the consequence of the error
immediately next to the condition defining it, and (b) lets the normal
happy case continue vertically down without adding indentation.
Same motivation as in the parent commit.
Once the parsing is done, we want these to remain unchanged,
just like the other objects in the parse tree.

So, like ContentNode and its subclasses, make the class immutable.
The parser needs to mutate its own draft of what styles to apply
to a given span; but it can do that with its own local variables
corresponding to the fields, and construct a styles object at the
end of the loop.
This deduplicates the logic for the particular way that a list of
KaTeX nodes get combined into a single widget.
This makes it more uniform with our other content widgets.
Comment on lines +372 to +376
sealed class KatexNode extends ContentNode {
const KatexNode({super.debugHtmlNode});
}

class KatexSpanNode extends KatexNode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One point that I noticed while developing #1478 (and checking how my draft of that branch interacted with this PR): it'd be good for this commit:
e268041 content: Handle vertical offset spans in KaTeX content

to get split up like so:

  • First, an NFC prep commit introduces the distinction between KatexNode and KatexSpanNode. At this stage, the latter is the only subclass of the former.
  • Then another commit makes the substantive changes this commit is about, including introducing the sibling subclasses KatexVlistNode and KatexVlistRowNode.

One reason that'd be useful is that the split between KatexNode and KatexSpanNode is somewhat nontrivial in itself: some of the references to KatexNode continue to say KatexNode, while others switch to saying KatexSpanNode, so the commit is expressing meaningful information by its choices of which references go which way.

And rename previous type to KatexSpanNode, also while making it a
subtype of KatexNode.
Implement handling most common types of `vlist` spans.
Negative margin spans on web render to the offset being applied
to the specific span and all the adjacent spans, so mimic the
same behaviour here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants