Math.tex constructor

Math.tex(
  1. String expression, {
  2. Key? key,
  3. MathStyle mathStyle = MathStyle.display,
  4. TextStyle? textStyle,
  5. OnErrorFallback onErrorFallback = defaultOnErrorFallback,
  6. TexParserSettings settings = const TexParserSettings(),
  7. double? textScaleFactor,
  8. MathOptions? options,
})

Math builder using a TeX string

expression will first be parsed under settings. Then the acquired SyntaxTree will be built under a specific options. If ParseException is thrown or a build error occurs, onErrorFallback will be displayed.

You can control the options via mathStyle and textStyle.

See alse:

Implementation

factory Math.tex(
  String expression, {
  Key? key,
  MathStyle mathStyle = MathStyle.display,
  TextStyle? textStyle,
  OnErrorFallback onErrorFallback = defaultOnErrorFallback,
  TexParserSettings settings = const TexParserSettings(),
  double? textScaleFactor,
  MathOptions? options,
}) {
  SyntaxTree? ast;
  ParseException? parseError;
  try {
    ast = SyntaxTree(greenRoot: TexParser(expression, settings).parse());
  } on ParseException catch (e) {
    parseError = e;
  } on Object catch (e) {
    parseError = ParseException('Unsanitized parse exception detected: $e.'
        'Please report this error with correponding input.');
  }
  return Math(
    key: key,
    ast: ast,
    parseError: parseError,
    options: options,
    onErrorFallback: onErrorFallback,
    mathStyle: mathStyle,
    textScaleFactor: textScaleFactor,
    textStyle: textStyle,
  );
}