Default components / Code & math

Display LaTeX

Renders display math enclosed by \[ and \] as a standalone math widget.

LatexMathMultiLineboth componentLatexStylelatexBuilder

What it renders

Live Flutter preview

Starting the Flutter widget

Rendering this component with gpt_markdown…

This is the real GptMarkdown Flutter widget, rendered with the exact Markdown input shown here.

Markdown input

input.md
1\[\int_0^1 x^2\,dx = \frac{1}{3}\]

Default behavior

Runtime behavior

Display math is treated as a block and can optionally scroll horizontally when the expression is too wide.

Accessibility note

Prefer a short nearby textual explanation for essential equations.

Theming & styling

Theme layering guide

LatexStyle is the component's appearance surface. Set only the values you need; style-sheet values merge field-by-field with the active theme and package defaults.

Style classAvailable fields
LatexStyletextStyle · padding · backgroundColor · borderRadius · scrollBlockHorizontally
display-latex_style.dart
1GptMarkdown( 2 markdown, 3 styleSheet: const GptMarkdownStyleSheet( 4 latex: LatexStyle( 5 scrollBlockHorizontally: true, 6 padding: EdgeInsets.symmetric(vertical: 8), 7 borderRadius: Radius.circular(6), 8 ), 9 ), 10)

App-wide or scoped theme

theme.dart
1GptMarkdownThemeData( 2 brightness: Brightness.light, 3 styleSheet: const GptMarkdownStyleSheet( 4 latex: LatexStyle( 5 // Set only the values your app needs. 6 ), 7 ), 8)

Builders & callbacks

latexBuilder

Widget Function(BuildContext context, String tex, TextStyle textStyle, bool inline)

Use this only when the default widget structure is no longer the right shape. The resolved style or configuration is passed where applicable.

Full builder and callback signatures

Safely override the default

A custom component list replaces a default list entirely. Put your matching component first, then append the package defaults so every other Markdown feature continues to render.

keep_defaults.dart
1// This component participates in BOTH parser registries. 2// Passing either list replaces that registry, so preserve both default lists. 3GptMarkdown( 4 markdown, 5 components: [ 6 MyLatexMathMultiLineOverride(), 7 ...MarkdownComponent.globalComponents, 8 ], 9 inlineComponents: [ 10 MyLatexMathMultiLineOverride(), 11 ...MarkdownComponent.inlineComponents, 12 ], 13)
Custom component guide

Related components