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 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
b42f784
content test [nfc]: Use const for math block tests
rajveermalviya Apr 24, 2025
4231608
content test [nfc]: Enable skips in testParseExample and testParse
gnprice May 29, 2025
04a3d25
content [nfc]: Inline _logError in _KatexParser._parseSpan
rajveermalviya May 8, 2025
e2022de
content [nfc]: Refactor _KatexParser._parseChildSpans to take list of…
rajveermalviya May 8, 2025
82c6b01
content: Populate `debugHtmlNode` for KatexNode
rajveermalviya May 27, 2025
b6da144
content [nfc]: Reintroduce KatexNode as a base sealed class
rajveermalviya Apr 24, 2025
c8f7d0b
content: Ignore more KaTeX classes that don't have CSS definition
rajveermalviya May 19, 2025
51fb5f5
content: Handle 'mspace' and 'msupsub' KaTeX CSS classes
rajveermalviya May 19, 2025
db0c1d8
content [nfc]: Remove the `inline` property in _Katex widget
rajveermalviya May 19, 2025
0bf40b8
content: Support parsing and handling inline styles for KaTeX content
rajveermalviya Apr 1, 2025
0434863
content: Scale inline KaTeX content based on the surrounding text
rajveermalviya Apr 22, 2025
d81008f
content: Handle 'strut' span in KaTeX content
rajveermalviya May 29, 2025
532b324
content: Handle positive margin-right and margin-left in KaTeX spans
rajveermalviya May 19, 2025
fef8a60
content: Handle 'top' property in KaTeX span inline style
rajveermalviya May 19, 2025
2c5a28c
content: Handle vertical offset spans in KaTeX content
rajveermalviya Apr 1, 2025
7d76da7
content: Error message for unexpected CSS class in vlist inner span
rajveermalviya Jun 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions lib/model/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,12 @@ abstract class MathNode extends ContentNode {
}
}

class KatexNode extends ContentNode {
const KatexNode({
sealed class KatexNode extends ContentNode {
const KatexNode({super.debugHtmlNode});
}

class KatexSpanNode extends KatexNode {
Comment on lines +372 to +376
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.

const KatexSpanNode({
required this.styles,
required this.text,
required this.nodes,
Expand Down Expand Up @@ -402,6 +406,55 @@ class KatexNode extends ContentNode {
}
}

class KatexStrutNode extends KatexNode {
const KatexStrutNode({
required this.heightEm,
required this.verticalAlignEm,
super.debugHtmlNode,
});

final double heightEm;
final double? verticalAlignEm;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DoubleProperty('heightEm', heightEm));
properties.add(DoubleProperty('verticalAlignEm', verticalAlignEm));
}
}

class KatexVlistNode extends KatexNode {
const KatexVlistNode({
required this.rows,
super.debugHtmlNode,
});

final List<KatexVlistRowNode> rows;

@override
List<DiagnosticsNode> debugDescribeChildren() {
return rows.map((row) => row.toDiagnosticsNode()).toList();
}
}

class KatexVlistRowNode extends ContentNode {
const KatexVlistRowNode({
required this.verticalOffsetEm,
required this.node,
super.debugHtmlNode,
});

final double verticalOffsetEm;
final KatexSpanNode node;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DoubleProperty('verticalOffsetEm', verticalOffsetEm));
}
}

class MathBlockNode extends MathNode implements BlockContentNode {
const MathBlockNode({
super.debugHtmlNode,
Expand Down
Loading