RenderMath
The render object behind every formula widget — sizing from a MathLayout, painting, hit testing, selection and semantics.
Math and MathLayoutView draw each formula with one RenderMath;
MathSpan and MathText build Math widgets, so theirs do too. You rarely
need it directly: the widgets set its properties from their options. It is
exported for code that works at the render-object level, such as finding a
formula’s RenderMath in a test, or calling the static baselineOf for
custom layout.
To draw a formula on your own canvas instead, use
MathPainter.
API reference
Section titled “API reference”RenderMath
Section titled “RenderMath”One render object per formula: sizes itself from a MathLayout, paints
its display list, and takes part in text selection.
More about RenderMath
In display mode it takes the full available width, centres the formula
(or aligns it left with fleqn), and puts equation numbers at the
right margin (left with leqno, or in right-to-left math).
Inside a SelectionArea the formula is selected node by node (its
top-level atoms); copying gives the LaTeX source of what is selected.
| Constructor | Description |
|---|---|
RenderMath({…}) |
Creates a render object. |
RenderMath: more
RenderMath({ required MathLayout layout, required double fontSize, required Color color, required MathPainter painter, bool display = false, bool fleqn = false, bool leqno = false, ParseResult? result, List<MathHighlight> highlights = const [], String? semanticsLabel, void Function(MathTap tap)? onTap, Color selectionColor = const Color(0x6633B5E5), this.copyFormat = MathCopyFormat.latex, SelectionRegistrar? registrar, Map<String, MathClassStyle> classStyles = const {}, bool bold = false, double devicePixelRatio = 0, bool debugOverlay = false, void Function(MathTap tap)? onLongPress, this.onHover,})| Field | Type | Default | Description |
|---|---|---|---|
copyFormat |
MathCopyFormat |
MathCopyFormat.latex |
What copying a selection puts on the clipboard. |
onHover |
void Function(MathTap? tap)? |
Called with what the mouse is over as it moves (null when over empty space or after it leaves). | |
focusColor |
Color |
Colour of the keyboard-focus outline. |
| Member | Type | Description |
|---|---|---|
mathLayout |
MathLayout |
The formula. |
result |
ParseResult? |
The parse, used for selection and copying. |
fontSize |
double |
Pixels per em. |
color |
Color |
Colour for items without their own. |
painter |
MathPainter |
The painter. |
display |
bool |
Display mode: full width, equation numbers at the margin. |
fleqn |
bool |
Left-aligned display equations. |
leqno |
bool |
Equation numbers on the left. |
highlights |
List<MathHighlight> |
Parts of the formula to emphasise. |
setHighlights(List<MathHighlight> v, {Animation<double>? transition}) |
void |
Replaces the highlights; with transition (running 0 → 1), the old ones fade out as the new ones fade in, and a single highlight glides to its new place. |
semanticsLabel |
String? |
What screen readers say for the formula. |
selectionColor |
Color |
Colour of the selection highlight. |
onTap |
void Function(MathTap tap)? |
Called with what was tapped. |
onLongPress |
void Function(MathTap tap)? |
Called with what was long-pressed. |
classStyles |
Map<String, MathClassStyle> |
Styles for parts carrying these \htmlClass names (their sizes are applied in layout, through LayoutOptions.classScales). |
bold |
bool |
Thicken glyphs (the platform’s bold-text accessibility setting). |
devicePixelRatio |
double |
Device pixels per logical pixel. When positive, the formula’s origin and its thin rules snap to the device-pixel grid; 0 turns that off. |
focusSpan |
SourceSpan? |
The part keyboard navigation is on, outlined (null: none). |
debugOverlay |
bool |
Draw item boxes and the baseline. |
static numberGap = 1.0 |
Gap between a formula and its equation numbers, in em. | |
static baselineOf(MathLayout layout, double fontSize) |
double |
The distance from the top of a formula’s box to its baseline, in pixels: the taller of the formula and its equation numbers. |
hitAt(Offset local) |
MathHit? |
What is painted at local, or null. |
speechLanguage |
SpeechLanguage |
Language of the spoken labels: the formula’s (when semanticsLabel is null) and its parts’. |
speechVerbosity |
SpeechVerbosity |
Verbosity of the spoken labels. |
parts |
List<MathPart> |
The navigable parts that paint something. |