Skip to content
Talk to an engineerRequest access

Migrating from flutter_math_fork

Switch by changing one import, see what the compatibility layer maps and ignores, then move to the native API.

pubspec.yaml
dependencies:
# flutter_math_fork: ^0.7.4
val_latex_flutter: ^0.1.4
// import 'package:flutter_math_fork/flutter_math.dart';
import 'package:val_latex_flutter/flutter_math_compat.dart';

Math.tex, SelectableMath.tex, MathStyle, MathOptions, FontOptions, MathSize, TexParserSettings, Strict, OnErrorFallback, FlutterMathException, ParseException and BuildException keep their flutter_math_fork shapes, backed by val_latex. Every command KaTeX 0.19 and flutter_math_fork define is defined in val_latex too, except flutter_math_fork’s \cursor.

flutter_math_fork With the compat import
MathStyle.display (the default) Display style, set inline — as wide as the formula, not a full-width block.
MathStyle.text, script, scriptscript The formula wrapped in \textstyle, \scriptstyle or \scriptscriptstyle.
Cramped styles Rendered like the uncramped style.
MathOptions.fontSize × sizeUnderTextStyle, color The formula’s size and colour. Passing options overrides mathStyle and textStyle, and turns off the platform text scale.
A bold mathFontOptions weight (600 or more) The formula wrapped in \boldsymbol{…}.
FontOptions.fontFamily, fontShape, fallback Ignored: formulas use val_latex’s math font, Latin Modern Math by default.
TexParserSettings (displayMode, macros, maxExpand, strict, strictFun, globalGroup, colorIsTextColor) Mapped to ParseOptions. Unfinished input is an error, as in flutter_math_fork.
TexParserSettings.throwOnError Ignored: errors go to onErrorFallback.
onErrorFallback Called with a ParseException holding the first error’s message. The default shows the message as selectable text.
SelectableMath.tex A Math inside its own SelectionArea, or the enclosing one. Copying gives the LaTeX source.
textScaleFactor Overrides the platform text scale.

texBreak() is not provided, and the compat Math.tex does not wrap. In the native API display formulas wrap by themselves, and MathText wraps inline formulas with the text.

The compat layer exists to get you running; the native API (package:val_latex_flutter/val_latex_flutter.dart) is where wrapping, taps, highlights, keyboard navigation, theming and streaming live.

import 'package:val_latex_flutter/val_latex_flutter.dart';
Math.tex(tex) // inline style
Math.tex(tex, displayMode: true) // display: full width, numbered
Math.tex(tex, displayMode: true, block: false) // display style, inline box
MathSpan(tex) // inside Text.rich
MathText(r'Area $\pi r^2$ …', streaming: true) // text with formulas

Differences you will notice:

  • Errors render in place, in red, instead of replacing the whole formula; pass onError to replace it.
  • Unfinished input (\frac{a) is an error in Math.tex and MathSpan, as in flutter_math_fork. For text still arriving, use MathText(streaming: true), or ParseOptions(streaming: true) on one formula, and it renders what exists.
  • \text{…} is shaped as a run by Flutter’s text engine: Arabic, Indic scripts and emoji work.
  • More LaTeX: \tag, align, gather, multline, \DeclareMathOperator, \multicolumn, chemistry, units and more — see Supported LaTeX.
  • Metrics follow Latin Modern Math, not the KaTeX fonts, so sizes differ slightly; see Differences from KaTeX.

flutter_math_fork’s Math widget, backed by val_latex.

Constructor Description
Math.tex(expression, {…}) Renders expression.
Math.tex: more
const Math.tex(
this.expression, {
super.key,
this.mathStyle = MathStyle.display,
this.textStyle,
this.onErrorFallback = defaultOnErrorFallback,
this.settings = const TexParserSettings(),
this.textScaleFactor,
this.options,
})
Field Type Default Description
expression String required TeX source.
mathStyle MathStyle MathStyle.display Style (display style is set inline, not as a full-width block).
textStyle TextStyle? Size and colour.
onErrorFallback OnErrorFallback defaultOnErrorFallback Shown instead of the formula when it has errors.
settings TexParserSettings const TexParserSettings() Parser settings.
textScaleFactor double? Overrides the platform text scale.
options MathOptions? Explicit options; override mathStyle and textStyle.
Member Type Description
static defaultOnErrorFallback(FlutterMathException error) Widget flutter_math_fork’s default fallback: the error message.

flutter_math_fork’s SelectableMath: a Math inside its own SelectionArea (or the enclosing one); copying gives the LaTeX source.

Constructor Description
SelectableMath.tex(expression, {…}) Renders expression.
SelectableMath.tex: more
const SelectableMath.tex(
super.expression, {
super.key,
super.mathStyle,
super.textStyle,
super.onErrorFallback,
super.settings,
super.textScaleFactor,
super.options,
})

flutter_math_fork’s rendering options.

Constructor Description
MathOptions({…}) Creates options.
MathOptions: more
const MathOptions({
this.style = MathStyle.display,
this.color = Colors.black,
this.sizeUnderTextStyle = MathSize.normalsize,
this.textFontOptions,
this.mathFontOptions,
double? fontSize,
this.logicalPpi,
})
Field Type Default Description
style MathStyle MathStyle.display Style.
color Color Colors.black Colour.
sizeUnderTextStyle MathSize MathSize.normalsize Size relative to fontSize.
textFontOptions FontOptions? Text font request.
mathFontOptions FontOptions? Math font request.
fontSize double Base font size in logical pixels.
logicalPpi double? Ignored.

flutter_math_fork’s styles. Cramped variants render like their uncramped style.

Value Description
display Display style.
displayCramped Display style, cramped.
text Text style.
textCramped Text style, cramped.
script Script style.
scriptCramped Script style, cramped.
scriptscript Scriptscript style.
scriptscriptCramped Scriptscript style, cramped.

flutter_math_fork’s size names, relative to the text style’s size.

Value Description
tiny 0.5×.
size2 0.6×.
scriptsize 0.7×.
footnotesize 0.8×.
small 0.9×.
normalsize 1×.
large 1.2×.
Large 1.44×.
LARGE 1.728×.
huge 2.074×.
HUGE 2.488×.
Member Type Description
sizeMultiplier double Multiplier.

Font request (only the weight is honoured: bold math via \boldsymbol).

Constructor Description
FontOptions({…}) Creates font options.
FontOptions: more
const FontOptions({
this.fontFamily = 'Main',
this.fontWeight = FontWeight.normal,
this.fontShape = FontStyle.normal,
this.fallback = const [],
})
Field Type Default Description
fontFamily String 'Main' KaTeX font family name (ignored: val_latex uses its own fonts).
fontWeight FontWeight FontWeight.normal Weight; bold makes the formula bold.
fontShape FontStyle FontStyle.normal Shape (ignored).
fallback List<FontOptions> const [] Fallbacks (ignored).

flutter_math_fork’s parser settings.

Constructor Description
TexParserSettings({…}) Creates settings.
TexParserSettings: more
const TexParserSettings({
this.displayMode = false,
this.throwOnError = true,
this.macros = const {},
this.maxExpand = 1000,
this.strict = Strict.warn,
this.strictFun,
this.globalGroup = false,
this.colorIsTextColor = false,
})
Field Type Default Description
displayMode bool false Display mode.
throwOnError bool true Ignored: val_latex never throws; errors reach onErrorFallback.
macros Map<String, String> const {} Macro name → body.
maxExpand int 1000 Expansion limit.
strict Strict Strict.warn Strictness.
strictFun Strict Function(String code, String message, Object? token)? Per-case strictness.
globalGroup bool false Definitions persist across formulas.
colorIsTextColor bool false \color takes an argument.

How strictly LaTeX-incompatible input is treated.

Value Description
ignore Accept silently.
warn Accept and warn.
error Reject.
function Decide per case with TexParserSettings.strictFun.

Builds a widget to show when a formula cannot be rendered.

typedef OnErrorFallback = Widget Function(FlutterMathException errmsg);