MathSpan
A formula inside Text.rich, sitting on the text baseline, with taps, hover and copy like Math.

import 'package:flutter/widgets.dart';import 'package:val_latex_flutter/val_latex_flutter.dart';
/// Formulas inside a paragraph, sitting on the text baseline.Widget example() => Text.rich( TextSpan( children: [ const TextSpan(text: 'A circle of radius '), MathSpan(r'r'), const TextSpan(text: ' has area '), MathSpan(r'\pi r^2'), const TextSpan(text: ' and circumference '), MathSpan(r'2\pi r'), const TextSpan(text: ', so their ratio is '), MathSpan(r'\frac{r}{2}'), const TextSpan(text: '.'), ], ),);MathSpan is a WidgetSpan holding a Math.tex in text style, aligned on
the alphabetic baseline, so it lines up with the words around it. Its
constructor is not const.
const style = TextStyle(fontSize: 18);
Text.rich( TextSpan( style: style, children: [ const TextSpan(text: 'Area '), MathSpan(r'\pi r^2', style: style), ], ),)- Size and colour come from
style, merged over the ambientDefaultTextStyle. The span is not scaled a second time by the paragraph’s text scaler. - Taps:
onTap,onLongPressandonHoverreport the part under the pointer as aMathTap, as onMath. WithonTaporonLongPressthe mouse cursor is a click cursor unless you passmouseCursor. - Screen readers hear
semanticsLabel, or the formula spoken. - Copy: inside a
SelectionArea, copying gives the LaTeX source, or whatcopyFormatmakes of it. - Unfinished input is an error, as on
Math.tex; passparseOptions: ParseOptions(streaming: true)for input still arriving.
A span does not break across lines: a long inline formula in a narrow
paragraph overflows its line. For paragraphs whose formulas should wrap with
the words, use MathText.
API reference
Section titled “API reference”MathSpan
Section titled “MathSpan”Inline math inside Text.rich, aligned on the text baseline.
More about MathSpan
Text.rich(TextSpan(children: [ const TextSpan(text: 'Area '), MathSpan(r'\pi r^2'),]))onTap, onLongPress and onHover report the node under the pointer,
as on Math.onTap. mouseCursor and semanticsLabel mean what they do
on TextSpan: the cursor defaults to a click cursor when the span has
onTap or onLongPress.
Creates an inline formula.
MathSpan( String tex, { TextStyle? style, ParseOptions parseOptions = const ParseOptions(streaming: false), MathTextFonts textFonts = MathTextFonts.latinModern, MacroTable? macros, void Function(MathTap tap)? onTap, void Function(MathTap tap)? onLongPress, void Function(MathTap? tap)? onHover, MouseCursor? mouseCursor, String? semanticsLabel, MathCopyFormat copyFormat = MathCopyFormat.latex,})The other parameters mean what they mean on Math.