What a MathLayout paints — every display item class, the fills, transforms and source metadata they carry, and the path commands of glyph outlines.
renderLatex and layoutFormula return a MathLayout whose items are
the display list: everything there is to paint. Items are positioned in em
of the base font size, x to the right and y down, with the origin on the
formula’s baseline at its left edge; multiply by the font size for pixels.
An item’s color is null when it takes the renderer’s current colour, and
its info (an ItemInfo) ties it back to the source: the span and the
stable id of the node that produced it.
In Flutter, MathPainter paints the list.
Anywhere else, read it yourself. DisplayItem is sealed, so a switch can
match every item class:
final layout =renderLatex(r'\frac{a}{b} + \sqrt{x}');
for (final item in layout.items) {
switch (item) {
caseGlyphItem(:final x, :final y, :final size):
print('glyph at ($x, $y), scale $size'); // outline: item.outline
caseRectItem(:final x, :final y, :final width, :final height):
print('rule $x$y$width × $height');
casePathItem(:final commands):
print('path of ${commands.length} commands');
default:
print(item.runtimeType);
}
}
A GlyphItem’s outline is a GlyphPath in font units with y up: scale
it by size / font.unitsPerEm, flip y, and move it to (x, y). Path
commands in items (PathItem, FillItem) are already in em with y down.
A laid-out piece of a formula: a size and the items that paint it.
More about Box
All lengths are in em of the base font size. height is above the
baseline, depth below it (both usually ≥ 0). Items are positioned
relative to the box origin: left edge, on the baseline, y down.
Metadata whose nodeId is computed by nodeId when first read: numbering every node of a formula costs more than laying it out, and most items are never asked for their id.
Field
Type
Default
Description
span
SourceSpan?
Source span of the node that produced the item.
classes
List<String>
const []
\htmlClass / \class names in effect.
link
String?
\href target in effect.
island
int?
Items sharing an island id keep their left-to-right order when a formula is mirrored for right-to-left math (numbers, Latin names).
Whether the glyph has a direction (delimiters, radicals, ∑, arrows, <…) and is drawn mirrored in right-to-left math.
flipped
bool
false
Draw mirrored left-to-right: the outline is reflected about the middle of the glyph’s advance.
Member
Type
Description
outline
GlyphPath
The outline in font units, y up. To paint: scale by size / font.unitsPerEm, flip y, and move to (x, y); when flipped, also reflect x within the advance (x' = advance - x).
A general path (circles, rounded boxes, angle marks), already in item
coordinates (em, y down).
Constructor
Description
PathItem(commands, {…})
Creates a path.
PathItem.glyph(GlyphSource source, {…})
A glyph’s outline under source’s transform (a turned, reflected, scaled or stretched letter), filled; source is kept so a renderer that draws glyphs itself can draw the glyph rather than the path.
PathItem: more
constPathItem(
this.commands, {
this.stroke,
this.fill =false,
this.source,
LatexColor? color,
ItemInfo info =ItemInfo.none,
})
PathItem.glyph: more
PathItem.glyph(
GlyphSourcethis.source, {
LatexColor? color,
ItemInfo info =ItemInfo.none,
})
Field
Type
Default
Description
source
GlyphSource?
required
The glyph this path is the outline of, when it is exactly one filled glyph outline; null for anything drawn. Either may be drawn: they are the same shape.
A run of text, shaped by the renderer’s text engine (or by the core’s
fallback, which then also supplies glyphs).
Constructor
Description
TextItem(text, font, x, y, size, width, {…})
Creates a text run.
TextItem: more
constTextItem(
this.text,
this.font,
this.x,
this.y,
this.size,
this.width, {
this.glyphs,
this.rtl,
this.reflected =false,
LatexColor? color,
ItemInfo info =ItemInfo.none,
})
Field
Type
Default
Description
reflected
bool
false
Drawn mirrored left to right about the middle of its width (\reflectbox).
rtl
bool?
Base direction of the run’s paragraph: true right-to-left, false left-to-right, null from its first strong character (LayoutOptions.textDirection).
text
String
required
The text.
font
TextFont
required
Requested font.
x
double
required
Left.
y
double
required
Baseline.
size
double
required
Scale: 1 = base font size.
width
double
required
Measured width.
glyphs
List<DisplayItem>?
What the pure-Dart shaper drew for the run, positioned relative to its origin: glyphs, and for colour fonts (emoji) FillItems and ImageItems; null when the host shaper measured the run.
A sweep (conic) gradient around (cx, cy) in gradient space, from
startAngle to endAngle (radians, counter-clockwise from +x with
y up, as in fonts), which transform maps to item coordinates.
How a CompositeItem’s source combines with its backdrop: the
Porter-Duff operators and the blend modes of CSS compositing, in the
order of COLR v1’s CompositeMode.
Value
Description
clear
Nothing.
src
The source only.
dest
The backdrop only.
srcOver
The source over the backdrop.
destOver
The backdrop over the source.
srcIn
The source where the backdrop is.
destIn
The backdrop where the source is.
srcOut
The source where the backdrop is not.
destOut
The backdrop where the source is not.
srcAtop
The source where the backdrop is, over the backdrop.
destAtop
The backdrop where the source is, over the source.
xor
Each where the other is not.
plus
The sum of both.
screen
Blend modes (source over, its colour blended with the backdrop’s).