val_latex_flutter library

Flutter rendering for val_latex.

import 'package:val_latex_flutter/val_latex_flutter.dart';

const Math.tex(r'x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}')

Layout is done by the pure-Dart core; this package shapes text runs with Flutter's text engine and paints the result in one render object.

Classes

AccentNode
An accent over or under a base: \hat, \widetilde, \overrightarrow, \utilde, and text accents.
Affine
An affine map (x, y) → (a·x + c·y + e, b·x + d·y + f).
AlignColumn
A content column: l, c or r, or a paragraph column p{w}, m{w}, b{w} whose text-mode cells break into lines width wide (aligned to the row at their top, middle or bottom line).
ArrayNode
A tabular structure: arrays, matrices, aligned equations, cases, CD.
ArrayRow
One row of an ArrayNode.
Box
A laid-out piece of a formula: a size and the items that paint it.
BraceNode
\overbrace / \underbrace and similar stretchy braces. A label is a script on the enclosing ScriptsNode.
BreakNode
A break opportunity or prohibition: \allowbreak, \nobreak, \penalty, \linebreak, \nolinebreak.
CdArrowNode
An arrow cell in a CD diagram: @>a>b>, @VVV, @=, @..
CellColorNode
\cellcolor / \rowcolor inside an array cell: a background fill.
ClassNode
Forces an atom class: \mathbin{…}, \mathrel{…}, \mathord{…}, \mathopen, \mathclose, \mathpunct, \mathinner.
ClosePath
Closes the current contour.
ColorNode
A colour change: \textcolor{c}{…} or \color{c} (rest of group).
ColumnSpec
One entry of an array column specification.
CompositeItem
Two groups of items composited: source onto backdrop by mode, the result over what is below (COLR v1 PaintComposite).
CubicTo
Cubic Bézier (CFF outlines).
DelimSizeNode
A delimiter of fixed size: \big(, \Biggr].
Diagnostic
A problem found while parsing.
DiagramArrow
An arrow of a DiagramNode: tikz-cd's \arrow[options] (or \ar).
DiagramLabel
A label on a DiagramArrow: "f", "f"', "f" near start.
DiagramNode
tikz-cd's tikzcd environment: a grid of objects and the arrows between them.
Dimension
A length such as -1.5em.
DisplayItem
Something to paint. Coordinates are in em of the base font size, x to the right, y down, origin on the formula's baseline at its left edge.
EmRect
An axis-aligned rectangle in em (x right, y down, origin on the formula's baseline at its left edge).
EncloseNode
A box around, through or behind content: \boxed, \fbox, \colorbox, \fcolorbox, \cancel, \bcancel, \xcancel, \sout, \cancelto, \angl, \phase, \longdiv, \textcircled.
EquationNumber
An equation number placed by the renderer at the margin.
ErrorNode
Input that could not be understood. The rest of the formula renders; this node shows raw in the error style.
ExtArrowNode
An extensible arrow with labels: \xrightarrow[below]{above}.
FallbackTextShaper
A pure-Dart shaper using the math font's own glyphs, one per grapheme.
Fill
How a FillItem is painted.
FillItem
A filled path (y down, em), optionally clipped to clip: colour-font glyphs (COLR) are made of these.
FontAxis
A design axis of a variable font (fvar): weight (wght), width (wdth), optical size (opsz)…, in the font's own user units.
FontNode
A font change: \mathbb{…}, \textbf{…}, \bf, \boldsymbol, \emph.
FracNode
A fraction or binomial.
GlyphBounds
An axis-aligned rectangle in font units, y up.
GlyphItem
A glyph of a math font, drawn from its outline.
GlyphMetrics
Size information for one glyph, in em.
GlyphPath
A glyph outline.
GraphicsNode
An image from \includegraphics (trusted input only).
HLine
A horizontal rule between rows.
HtmlNode
\htmlClass, \htmlId, \htmlStyle, \htmlData, \class: a hook the renderer maps to theme classes, ids or semantic tags.
ImageItem
An image (\includegraphics).
IncompleteNode
A placeholder for input that has not arrived yet: a missing argument at the end of input, or a half-typed command (\fra).
ItemInfo
Metadata every painted item carries back to the source.
LapNode
\llap, \rlap, \clap and their \math… forms: zero-width content overlapping its neighbours.
LatexCatalog
Every name val_latex understands, grouped by the table that defines it — for galleries, completion lists and documentation.
LatexColor
A colour, 8 bits per channel with alpha.
LayoutOptions
Options that affect layout.
LeftRightNode
\left … \middle … \right.
LinearFill
A linear gradient from (x0, y0) to (x1, y1) in gradient space, which transform maps to item coordinates.
LineBreakNode
\\ or \newline outside an environment: start a new line.
LineBreakOpportunity
A place where a line may (or must) break: before the code unit at offset.
LineItem
A stroked straight line (strikes, dashed table rules).
LineNode
\overline / \underline.
LineTo
Straight line.
LinkNode
\href{url}{…} and \url{…}.
MacroTable
Macro definitions with TeX group scoping.
Math
Renders a LaTeX formula.
MathBaseline
Reports baseline as its child's alphabetic baseline, so custom-painted formulas line up with text as Math.tex does.
MathCache
The parses and layouts Math widgets share, least recently used first out: a list scrolling formulas back into view does not lay them out again. One prepared formula per source, options and font; its layouts per width come from re-running only the line breaker.
MathChoiceNode
\mathchoice{D}{T}{S}{SS}: content chosen by the current style.
MathClassStyle
How parts marked \htmlClass{name}{…} look.
MathCopy
What is being copied, for a MathCopyFormat.
MathCopyFormat
What copying a selected formula gives: latex (the default) or delimitedLatex. A format is a function of the copied formula (MathCopy), so others can be written the same way.
MathDelimiter
A pair of math delimiters.
MathFont
A math font: an OpenType font with a MATH table, measured in em.
MathHighlight
A part of a formula to emphasise.
MathHit
What is under a point of a formula.
MathLayout
A laid-out formula.
MathLayoutView
Paints an already laid-out formula (for example one piece from layoutFormulaSegments) at the ambient text size and colour.
MathNode
A node of the math syntax tree.
MathPainter
Paints a MathLayout onto a canvas.
MathPart
A navigable part of a formula: a node and the parts inside it (a fraction's numerator and denominator, a root's radicand, a row's atoms), for screen-reader trees and keyboard navigation.
MathScanner
Finds formulas in text (like KaTeX's auto-render, in pure Dart).
MathSegment
A formula found in text.
MathSpan
Inline math inside Text.rich, aligned on the text baseline.
MathTap
A tap on a formula: the item under the finger and where it came from.
MathText
Text with formulas in it: The area is $\pi r^2$.
MathTextFonts
Which fonts text runs (\text{…}, non-math characters) use.
MathTheme
Sets MathThemeData for the formulas below it.
MathThemeData
How formulas look below a MathTheme: the colour (set it per light and dark theme), the error and placeholder colours, the selection colour, colours per \htmlClass / \class name, the math font, and a layout debug overlay.
MiddleNode
\middle delimiter inside a LeftRightNode.
MoveTo
Starts a new contour.
MultiColumnNode
\multicolumn{n}{spec}{body}: a cell spanning count columns.
MultiRowNode
multirow's \multirow[vpos]{rows}{width}[vmove]{text}: text set across several rows of a table, centred on them by default.
NamedInstance
A named instance of a variable font (fvar): "Bold", "Condensed Light"… and its axis values.
OpNode
A large operator: a symbol (\sum) or a name (\lim, \operatorname).
OverUnderNode
\overset, \underset, \stackrel: a base with material stacked above and/or below at script size.
ParagraphTextShaper
Measures text runs with Flutter's text engine, so every script shapes correctly: Arabic letters join, Indic clusters form, emoji sequences stay whole.
ParseOptions
Options that affect parsing. Layout options live elsewhere.
ParseResult
The outcome of parsing one formula.
PathCommand
A command of a glyph outline. Coordinates are in font units, y up.
PathItem
A general path (circles, rounded boxes, angle marks), already in item coordinates (em, y down).
PhantomNode
\phantom, \hphantom, \vphantom: invisible content that keeps some of its size.
PhysicsOptions
The physics package's options (\usepackage[…]{physics}), for ParseOptions.physics.
PreparedFormula
A formula laid out once, ready to be broken to any width: layoutAt re-runs only the line breaker (a widget resizing, a window dragged).
ProofStep
One inference of a ProofTreeNode (an axiom when it has no premises): \AxiomC{…}, \UnaryInfC{…}, \BinaryInfC{…}…
ProofTreeNode
bussproofs' prooftree environment: inference rules stacked into a tree, the conclusion at the bottom.
QuadTo
Quadratic Bézier (TrueType outlines).
RadialFill
A two-circle radial gradient in gradient space, which transform maps to item coordinates.
RaiseNode
\raisebox, \raise, \lower.
RectItem
A filled rectangle (fraction bars, radical overbars, rules, table lines).
ReflectNode
graphicx's \reflectbox (its argument is text, as a box's) and \mathreflectbox (math): content mirrored left to right.
RefNode
\ref{name} / \eqref{name}; resolved against a document at layout.
RenderMath
One render object per formula: sizes itself from a MathLayout, paints its display list, and takes part in text selection.
RenderMathBaseline
The render object of MathBaseline.
RowNode
An ordered list of nodes: the body of a group, an argument, a formula.
RuleNode
A filled rectangle: \rule[shift]{width}{height}.
ScriptsNode
A base with subscript and/or superscript, and optionally prescripts.
Segment
A piece of mixed text: plain text or a formula.
SelectionUnit
One selectable piece of a formula: a top-level node and where it is painted.
SeparatorColumn
A vertical rule between columns: | or :.
ShapedText
The measured size of a text run, in em of the run's own size.
SizeNode
\tiny … \Huge: the rest of the group at another size.
SmashNode
\smash: content whose height and/or depth count as zero.
SolidFill
One colour (null: the item's colour, or the current colour).
SourceSpan
A half-open range [start, end) of UTF-16 offsets into the parsed source.
SourceText
The source after normalization, with a map back to the original string.
SpaceNode
Explicit horizontal space.
SpacerColumn
@{…}: material replacing the inter-column space.
SqrtNode
A radical: \sqrt[index]{body}.
StyleNode
\displaystyle and friends: the rest of the group in another style.
SweepFill
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.
SymbolNode
One math-mode symbol: a letter, digit, operator or delimiter character.
TagForm
mathtools' \newtagform{name}[format]{left}{right}.
TagNode
\tag{…} / \tag*{…}.
TextFont
Font request for a text run.
TextGroupNode
Text mode: \text{…}, \mbox{…}, \hbox{…}. The body holds TextNode runs and math islands ($…$).
TextItem
A run of text, shaped by the renderer's text engine (or by the core's fallback, which then also supplies glyphs).
TextNode
A run of text-mode characters, shaped as one unit.
TextSegment
Plain text between formulas.
TextShaper
Measures text runs (\text{…}, non-math characters).
ThirdPartyNotice
Work by others that a package contains, and the notice its licence asks to go with it.
TrustContext
A request to use a feature gated by ParseOptions.trust.
VCenterNode
\vcenter: content centred on the math axis.
VerbNode
Verbatim text from \verb.

Enums

ArrayKind
The layout family of an ArrayNode.
AtomType
TeX's math atom classes (TeXbook ch. 17), which decide spacing.
CompositeMode
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.
DiagramLabelPlacement
Where a DiagramLabel sits relative to its arrow.
DiagramLine
How the line of a DiagramArrow is drawn.
DiagramTip
An arrow tip of a DiagramArrow, at its start or end.
DigitStyle
How numbers are written.
GradientExtend
How a gradient continues past its ends.
IncompleteStyle
How an incomplete (still streaming) part of a formula is shown.
LatexExtension
Optional command sets, enabled through ParseOptions.extensions.
LengthUnit
A unit of length.
LimitsMode
How limits are placed on a large operator.
LineBreaking
Where a formula may break across lines.
LineStyle
A column separator line style.
MathDirection
Reading direction of the math itself.
MathOverflow
What a formula does when it is wider than its space.
MathStyle
The four TeX math styles.
MissingGlyphs
What a symbol no math font has becomes.
ProofRule
How the line of a ProofStep is drawn.
Severity
How serious a Diagnostic is.
SpaceKind
Kind of SpaceNode.
SpeechLanguage
A language for spoken math.
SpeechVerbosity
How much structure speech announces.
Strict
What to do with input LaTeX would reject but we can still handle.
TextFamily
Text font families.
TextRunDirection
Base direction of text runs (\text{…}) — how neutral characters and mixed-direction words inside a run are ordered.

Constants

arabicOperatorNames → const Map<String, String>
Arabic names for common operators, as used in Arabic-language school mathematics (Mashriq conventions). Have a native reader check them for your audience; pass your own table to LayoutOptions.operatorNames.
mathEnvironments → const Set<String>
Environments recognised as display math without delimiters.
valLatexFlutterNotices → const List<ThirdPartyNotice>
The third-party notices of val_latex_flutter (THIRD_PARTY_NOTICES.md).
valLatexNotices → const List<ThirdPartyNotice>
The third-party notices of val_latex (THIRD_PARTY_NOTICES.md).
valLatexVersion → const String
The version of this package.

Functions

addThirdPartyNotices(String package, List<ThirdPartyNotice> notices) → void
Adds notices to Flutter's licence page under package.
decodeLayout(List<Object?> data, List<MathFont> fonts) → MathLayout
Rebuilds a layout from encodeLayout; fonts resolves font names (a name not found falls back to the first font).
deepSelectionUnits(ParseResult result, MathLayout layout) → List<SelectionUnit>
Every atom of the formula in reading order, those inside fractions, scripts and groups too, with their painted rectangles: finer units for selecting than selectionUnits. Nodes that paint nothing are left out.
encodeLayout(MathLayout layout) → List<Object?>
A layout as plain lists and numbers (fonts by name), cheap to send between isolates; decodeLayout rebuilds it with the receiver's fonts, so painters keep their per-font glyph caches.
hitTestLayout(MathLayout layout, double x, double y, {double slop = 0.05}) → MathHit?
The item under (x, y) em, preferring the smallest one; null when the point is on empty space.
isDefaultIgnorable(int cp) → bool
Whether cp is drawn as nothing: a default-ignorable code point (variation selectors, zero-width space and joiners, bidi controls, the invisible operators U+2061–U+2064, the byte order mark, tags), the soft hyphen, or a line or paragraph separator.
isRtlText(String text) → bool
Whether text reads right to left: its first strong character is Hebrew, Arabic, Syriac, Thaana, N'Ko or another right-to-left script (UAX #9 rule P2).
itemBounds(DisplayItem item) → EmRect
The painted extent of item, in em.
layoutFormula(ParseResult result, {LayoutOptions options = const LayoutOptions(), MathFont? font, TextShaper? shaper, List<MathFont> fallbackFonts = const []}) → MathLayout
Lays out a parsed formula.
layoutFormulaSegments(ParseResult result, {LayoutOptions options = const LayoutOptions(), MathFont? font, TextShaper? shaper, List<MathFont> fallbackFonts = const [], double? maxWidth}) → List<MathLayout>
Splits an inline formula into pieces at its TeX break points (after binary operators and relations, at \allowbreak, at spaces in \text), for placing in a wrapping paragraph one piece at a time.
layoutInBackground(String source, {ParseOptions parseOptions = const ParseOptions(), LayoutOptions layoutOptions = const LayoutOptions()}) → Future<MathLayout>
Parses and lays out source away from the calling isolate: on native platforms in a long-lived worker isolate (the font is parsed there once), on the web synchronously (no isolates there).
lineBreakClass(int cp) → String
The Line_Break class of cp (a name such as AL, ID, SP).
lineBreaks(String text) → List<LineBreakOpportunity>
Break opportunities inside text (never at 0; the end of the text is always a break and is not listed).
mathParts(ParseResult result) → List<MathPart>
The formula's top-level parts, each with its nested parts. Unbraced rows are flattened; a braced group of one node is that node; spaces and breaks are left out.
mathShaperFor(MathTextFonts fonts) → ParagraphTextShaper
The shaper Math widgets use for fonts, for laying out formulas outside a widget (e.g. with layoutFormulaSegments).
newMacroTable() → MacroTable
A macro table preloaded with the built-in macros, for sharing definitions across parseLatex calls.
nodeToLatex(MathNode node) → String
Writes one node as LaTeX (see toLatex).
parseLatex(String source, {ParseOptions options = const ParseOptions(), MacroTable? macros}) → ParseResult
Parses LaTeX math source.
prepareFormula(ParseResult result, {LayoutOptions options = const LayoutOptions(), MathFont? font, TextShaper? shaper, List<MathFont> fallbackFonts = const []}) → PreparedFormula
Prepares result for layout at several widths (see PreparedFormula); LayoutOptions.maxWidth is ignored in favour of layoutAt's width.
registerValLatexLicenses() → void
Adds the third-party notices of val_latex and val_latex_flutter (valLatexNotices, valLatexFlutterNotices) to Flutter's licence page (showLicensePage, LicenseRegistry).
renderLatex(String source, {ParseOptions parseOptions = const ParseOptions(), LayoutOptions layoutOptions = const LayoutOptions(), MathFont? font, TextShaper? shaper, MacroTable? macros, List<MathFont> fallbackFonts = const []}) → MathLayout
Parses and lays out source in one step.
selectedSpan(List<SelectionUnit> units, int lo, int hi) → SourceSpan
The source a selection of units from lo to hi (exclusive) stands for: when its ends sit in different groups, each end widens to the whole structure that holds it in their common group, so the source parses on its own.
selectionUnits(ParseResult result, MathLayout layout) → List<SelectionUnit>
The formula's top-level nodes with their painted rectangles, in source order. Nodes that paint nothing (spaces, \label) are left out.
stopBackgroundLayout() → void
Stops the worker isolate (a new one starts on the next call).
toLatex(ParseResult result, {bool ascii = false}) → String
Writes a parsed formula back as LaTeX.
toSpeech(ParseResult result, {SpeechLanguage language = SpeechLanguage.english, SpeechVerbosity verbosity = SpeechVerbosity.normal}) → String
Speaks a formula as text for screen readers and text-to-speech.

Typedefs

ColorStop = (double, LatexColor?)
One colour stop of a gradient; a null colour is the current colour.

Exceptions / Errors

LatexParseException
Thrown by parseLatex only when ParseOptions.throwOnError is set.