• Pure Dart: Compiles natively for all platforms without relying on WebViews or native platform channels.

Online Demo

Example

Render LaTeX

import 'package:latex_kit/latex_kit.dart';

Latex(
  r'\int_{a}^{b} f(x)\,dx',
  config: LatexConfig(fontSize: 20),
)

Interactive LaTeX Editor

import 'package:latex_kit/latex_kit.dart';
import 'package:latex_kit/render/editor/editor_state.dart';

LatexEditor(
  editorState: EditorState(
    r'\int_{a}^{b} f(x)\,dx',
  ),
)

Auto Wrap

import 'package:latex_kit/latex_kit.dart';

LatexAutoWrap(
  latex: r'x_1 + x_2 + x_3 + x_4 + x_5 + x_6 + x_7 + x_8 = y_1 + y_2 + y_3 + y_4',
)

🚀 Quick Start

Here is how easy it is to combine themes, highlights, and interactions into a single widget:

Latex(
  latex: 'E = mc^2 \\href{[https://example.com](https://example.com)}{[Learn More]}',
  config: LatexConfig(
    theme: LatexTheme.auto(), // Automatically adapts to system theme
    onHyperlinkClick: (url) => debugPrint('Clicked: $url'),
    highlight: HighlightConfig(
      ranges: [
        // Highlight by pattern
        HighlightRange(
          pattern: 'mc', 
          color: Color(0x4400AAFF),
          borderColor: Color(0xFF0088FF),
        ),
        // Or highlight by node index
        HighlightRange(
          nodeIndices: IntRange(0, 2),
          color: Color(0x33FF6600),
        ),
      ],
    ),
  ),
)

LaTeX Support (450+ Symbols)

Mathematical Expressions — Fractions, Roots, Binomials, Superscripts & Subscripts

Supports \frac, \dfrac, \tfrac, \cfrac, \genfrac, \splitfrac, \splitdfrac, \binom, \tbinom, \dbinom, along with TeX infix forms such as \over, \atop, \choose, and \above. Square roots, superscripts, and subscripts are also supported.

Symbol System (130+) — Greek Letters, Operators, Arrows, AMS Symbols
  • Greek Letters: Complete lowercase (α–ω, including \omicron), uppercase (Γ–Ω), KaTeX-style uppercase aliases (\Alpha, \Beta, \Epsilon, \Omicron), and variants (\epsilon/\varepsilon, \theta/\vartheta, \phi/\varphi, \varGamma\varOmega, etc.).
  • Operators: +, -, \times, \div, \pm, \mp, \cdot, \oplus, \otimes, and more.
  • Relations: =, \neq, <, >, \leq, \geq, \approx, \equiv, \sim, \coloneqq, \eqqcolon, etc.
  • Set Theory: \in, \notin, \subset, \cup, \cap, \emptyset, \mathbb{R}, etc.
  • Logic: \land, \lor, \neg, \Rightarrow, \Leftrightarrow, \forall, \exists.
  • Arrows: \to, \rightarrow, \leftarrow, \leftrightarrow, \Rightarrow, \hookrightarrow, harpoon arrows, and more.
  • Ellipsis: \ldots, \cdots, \vdots, \ddots, \dots (context-aware).
  • Negated Symbols: \not=, \notin, \nleq, \ngeq, \ncong, \nmid, and 30+ AMS negated relation symbols.
  • Additional AMS Symbols: \checkmark, \complement, \blacksquare, \aleph, \measuredangle, geometric symbols, double-headed arrows, and more.
Large Operators (28) — Summation, Integrals, Limits, Modulo
  • Summation & Integrals: \sum, \prod, \int, \oint, \iint, \iiint, \bigcup, \bigcap, \bigvee, \bigwedge, \coprod, \bigoplus, \bigotimes, \bigsqcup, \bigodot, \biguplus.
  • Limits: \lim, \max, \min, \sup, \inf, \limsup, \liminf.
  • Custom Operators: \operatorname, \operatorname*, \DeclareMathOperator, \mathop.
  • Multi-line Subscripts: \substack.
  • Modulo: \bmod, \pmod, \mod.
Matrices — Standard, Starred & Compact Matrix Environments

Supports matrix, pmatrix, bmatrix, Bmatrix, vmatrix, Vmatrix, smallmatrix, mathtools starred variants with [l|c|r] alignment, as well as array and subarray.

Delimiters & Brackets — Automatic Scaling & Manual Sizes
  • Automatic sizing with \left...\right and \middle.
  • Asymmetric delimiters such as \left.\right| and \left\{\right..
  • Manual sizing using \big, \Big, \bigg, \Bigg and variants (\bigl, \bigr, \bigm).
Decorations (42+) — Accents, Cancellation, Stretchy Arrows, Braces
  • Accents: \widecheck, \overparen, \underparen, and standard accents.
  • Braces: \overbrace, \underbrace, \overbracket, \underbracket.
  • Arrow Decorations: \overrightarrow, \overleftarrow, \overleftrightarrow, \underleftarrow, \underrightarrow.
  • Cancellation: \cancel, \bcancel, \xcancel.
  • Stretchy Arrows: \xrightarrow, \xleftarrow, \xhookrightarrow, \xhookleftarrow, \xRightarrow, \xLeftarrow, \xLeftrightarrow, \xmapsto, \xlongequal.
  • Stacking: \overset, \underset, \stackrel.
Font Styles (17)

Supports \mathbf, \mathit, \mathrm, \mathsf, \mathtt, \mathbb, \mathfrak, \mathcal, \mathscr, \boldsymbol, \bm, \text, \mbox, \textnormal, \textup, \textmd, \textsc, \textsl, \emph, and Unicode-math style aliases.

Font Sizes (10)

\tiny, \scriptsize, \footnotesize, \small, \normalsize, \large, \Large, \LARGE, \huge, \Huge

Math Styles

Supports \displaystyle, \textstyle, \scriptstyle, \scriptscriptstyle, inline math ($...$), and display math ($$...$$).

Environments (21) — Alignment, Cases, Matrices, Tables
  • Equation: equation(*), displaymath
  • Alignment: align(*), aligned, flalign(*), alignat(*), alignedat
  • Centered: gather(*), gathered
  • Cases: cases, dcases, rcases and starred variants
  • Multi-line: split, multline(*)
  • Others: eqnarray(*), subequations, tabular
  • Line Control & Numbering: \\, \cr, \intertext, \shortintertext, \notag, \nonumber, \tag, \label, \ref, \eqref
Spacing Control

Supports standard mathematical spacing, \hspace, \kern, \mkern, \allowbreak, and common escaped special characters.

Colors & Backgrounds
  • Text Colors: \color, \textcolor
  • Background Colors: \colorbox, \fcolorbox
Chemistry (13) — mhchem

Supports \ce, \bond, and \pu, including molecules, ions, isotopes, reaction arrows, and chemical equations.

Special Effects & Layout (17)
  • Boxes: \boxed, \fbox
  • Enclosures: \enclose, \circled
  • Supported Notations: box, roundedbox, circle, left, right, top, bottom, updiagonalstrike, downdiagonalstrike, verticalstrike, horizontalstrike
  • Supported Attributes: mathcolor, mathbackground
  • Phantoms: \phantom, \smash, \vphantom, \hphantom, \mathstrut
  • Zero-width Layout: \mathclap, \mathllap, \mathrlap
  • TeX Layout: \clap, \llap, \rlap, \raisebox, \rule
  • Mathtools: \Aboxed, \MoveEqLeft, \splitfrac, \splitdfrac, \DeclarePairedDelimiter
Physics & SI Units
  • Derivatives: \dv, \pdv
  • Dirac Notation: \bra, \ket, \braket, \comm, \anticomm, \eval, \vb, \va, \abs, \norm
  • SI Units: \SI, \si, \qty, \unit, \numrange, \qtyrange, \ang
Advanced Annotations (6)
  • Hyperlinks: \href, \url
  • Side Sets: \sideset
  • Prescripts: \prescript
  • Tensor Indices: \tensor, \indices
Custom Commands & Macros (9)

Supports \newcommand, \renewcommand, \def, \newenvironment, \renewenvironment, and \DeclarePairedDelimiter.

Sectioning Commands

\section, \subsection, \subsubsection, \paragraph, \subparagraph (including starred variants).

RTL Text Support
  • Commands: \RLE, \LRE, \textarabic, \texthebrew
  • Environments: RTL, LTR
  • Supports nested RTL/LTR rendering.
Labels & References

Supports \label, \ref, \eqref, \tag, and \tag*.

Error Handling
  • Unknown commands are rendered with an error color instead of being silently ignored.
  • parseWithDiagnostics() provides structured diagnostics with eight error categories and severity filtering.

⚡ Benchmark & Comparison

Why choose latex_kit over legacy alternatives?

Feature flutter_math_fork latex_kit
Compiled Dart Size ~2 MB ~1 MB (~50% smaller)
Symbol Coverage Standard Extensive (450+ Symbols)
Auto Line-Wrapping ❌ No ✅ Yes
Native Canvas Editor ❌ No ✅ Yes

Dependencies & Acknowledgements

latex_kit utilizes or derives code from the following packages:

  • glyph_path - Used exclusively for precise text measurement. It allows the renderer to extract the exact ink boundaries of the KaTeX fonts instead of relying on standard text line boxes, ensuring pixel-perfect math layouts

  • KaTeX - The original web library whose font sets and spacing rules were adapted for this Flutter package.

If you find any issues, kindly let me know.

Libraries

base/latex_const
base/log/h_log
base/log/i_logger
latex_kit
parser/components/chemical_parser
parser/components/command_parser
parser/components/environment_parser
parser/components/handlers/accent_handlers
parser/components/handlers/advanced_handlers
parser/components/handlers/arrow_and_stack_handlers
parser/components/handlers/big_operator_handlers
parser/components/handlers/color_handlers
parser/components/handlers/command_registry
parser/components/handlers/delimiter_handlers
parser/components/handlers/fraction_handlers
parser/components/handlers/macro_handlers
parser/components/handlers/operated_handlers
parser/components/handlers/package_command_handlers
parser/components/handlers/parse_utils
parser/components/handlers/reference_handlers
parser/components/handlers/root_handlers
parser/components/handlers/section_handlers
parser/components/handlers/space_handlers
parser/components/handlers/special_effect_handlers
parser/components/handlers/style_handlers
parser/components/handlers/table_handlers
parser/components/handlers/text_direction_handlers
parser/components/latex_parser_context
parser/components/latex_token_stream
parser/data/latex_node
parser/data/nodes
parser/data/src_range
parser/incremental/incremental_tokenizer
parser/incremental/text_edit
parser/incremental/tree_user
parser/incremental_latex_parser
parser/latex_parser
parser/parse_diagnostic
parser/source_mapper
parser/symbol_map
parser/tokenizer/latex_token
parser/tokenizer/latex_tokenizer
parser/util/latex_printer
parser/visitor/accessibility_visitor
parser/visitor/latex_visitor
parser/visitor/math_ml_vistor
render/animated_latex
render/editor/cursor_calculator
render/editor/editor_state
render/editor/latex_editor
render/editor/latex_template
render/editor/slot_navigator
render/font/katex_font_metrics
render/font/math_font_provider
render/font/math_font_provider_factory
render/font/ttf_ont_set_provider
render/latex_editor_canvas
render/latex_raw_measure
render/latex_widget
render/layout/equation_numbering
render/layout/group_layout_post_processor
render/layout/highlight_calculator
render/layout/latex_measurer
render/layout/latex_renderer
render/layout/layout_cache
render/layout/layout_map
render/layout/line_breaker
render/layout/measure/accent_measurer
render/layout/measure/big_operator_measurer
render/layout/measure/binomial_measurer
render/layout/measure/boxed_phantom_measurer
render/layout/measure/delimiter_measurer
render/layout/measure/extensible_arrow_measurer
render/layout/measure/fraction_measurer
render/layout/measure/matrix_measurer
render/layout/measure/negation_measurer
render/layout/measure/node_measurer
render/layout/measure/ref_measurer
render/layout/measure/root_measurer
render/layout/measure/script_measurer
render/layout/measure/sideset_tensor_measurer
render/layout/measure/stack_measurer
render/layout/measure/substack_measurer
render/layout/measure/tag_measurer
render/layout/measure/text_content_measurer
render/layout/node_layout
render/measure/latex_measurer
render/model/latex_font_families
render/model/render_style
render/util/delimiter_renderer
render/util/font_resolver
render/util/glyph_bounds
render/util/ink_bound_estimator
render/util/latex_utils
render/util/layout_utils
render/util/math_constants
render/util/math_font_utils
render/util/math_spacing
render/util/platform_utils