Skip to content
Talk to an engineerRequest access

MathTheme

Colours, fonts and per-class styles for every formula below it in the tree.

E = mc² in indigo, with the m in bold orange and c² on a light cyan background

MathTheme sets defaults for the formulas below it — Math, MathSpan and the formulas of MathText. Read the nearest one with MathTheme.of(context); MathThemeData.copyWith returns a copy with fields replaced.

Field What it sets
color Formula colour. Wins over the text style’s colour, so set it per light and dark theme.
errorColor Colour of parse errors drawn in place.
placeholderColor Colour of placeholders for unfinished input.
selectionColor Selection highlight. Defaults to the ambient DefaultSelectionStyle.
classColors Colours for parts marked \htmlClass{name}{…}, by class name.
classStyles Full styles per class name (MathClassStyle: colour, background, bold, scale). A colour here wins over classColors.
font The math font. Defaults to the bundled Latin Modern Math.
fallbackFonts Fonts tried, in order, for symbols the math font lacks.
debugOverlay Draws every item’s box, the baseline, italic corrections and break points.

Mark parts with \htmlClass{name}{…} (or \class{name}{…}) and style them by name. MathClassStyle.scale changes the part’s size relative to the formula, and is applied at layout, so the formula makes room for it.

For fonts — the math font, symbol fallbacks and the text fonts — see Styling and fonts.

Sets MathThemeData for the formulas below it.

More about MathTheme
MathTheme(
data: const MathThemeData(classColors: {'step': Colors.teal}),
child: Math.tex(r'x = \htmlClass{step}{\frac{b}{a}}'),
)
Constructor Description
MathTheme({key, required data, required child}) Creates a theme.
Field Type Default Description
data MathThemeData required The theme.
Member Type Description
static of(BuildContext context) MathThemeData The nearest theme’s data, or defaults.

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.

Constructor Description
MathThemeData({…}) Creates theme data; null fields fall back to the text style and the widgets’ defaults.
MathThemeData: more
const MathThemeData({
this.color,
this.errorColor,
this.placeholderColor,
this.selectionColor,
this.classColors = const {},
this.classStyles = const {},
this.font,
this.fallbackFonts = const [],
this.debugOverlay = false,
})
Field Type Default Description
color Color? Colour of formulas (default: the text style’s colour).
errorColor Color? Colour of parse errors drawn in place.
placeholderColor Color? Colour of placeholders (unfinished input, empty editor slots).
selectionColor Color? Selection highlight (default: DefaultSelectionStyle).
classColors Map<String, Color> const {} Colours for parts marked \htmlClass{name}{…} (or \class{name}{…}), by class name — for example a “step” colour in a worked solution. Like KaTeX, \htmlClass needs ParseOptions(trust: true) (or a trust callback allowing it).
classStyles Map<String, MathClassStyle> const {} Full styles (colour, background, bold, size) per class name; a colour here wins over classColors.
font MathFont? The math font (default: the bundled Latin Modern Math).
fallbackFonts List<MathFont> const [] Fonts for symbols the math font lacks, tried in order (see MathFont.symbols).
debugOverlay bool false Draw every item’s box, the baseline, italic corrections and break points, for debugging layout.
Member Type Description
resolvedClassStyles Map<String, MathClassStyle> classStyles with classColors folded in.
copyWith({…}) MathThemeData A copy with the given fields replaced.
apply(LayoutOptions options) LayoutOptions options with this theme’s error and placeholder colours and class sizes.
copyWith: more
MathThemeData copyWith({
Color? color,
Color? errorColor,
Color? placeholderColor,
Color? selectionColor,
Map<String, Color>? classColors,
Map<String, MathClassStyle>? classStyles,
MathFont? font,
List<MathFont>? fallbackFonts,
bool? debugOverlay,
})

How parts marked \htmlClass{name}{…} look.

Constructor Description
MathClassStyle({color, background, bold = false, scale = 1}) Creates a class style; null or default fields change nothing.
Field Type Default Description
color Color? Ink colour.
background Color? Fill behind the part.
bold bool false Thicker glyphs.
scale double 1 Size relative to the surrounding formula (applied in layout).