latex_kit 0.0.8
latex_kit: ^0.0.8 copied to clipboard
A lightweight, pure Dart Flutter package for rendering LaTeX symbols.
- 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)
<details>
<summary><b>Mathematical Expressions</b> — Fractions, Roots, Binomials, Superscripts & Subscripts</summary>
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.
</details>
<details>
<summary><b>Symbol System (130+)</b> — Greek Letters, Operators, Arrows, AMS Symbols</summary>
- **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.
</details>
<details>
<summary><b>Large Operators (28)</b> — Summation, Integrals, Limits, Modulo</summary>
- **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`.
</details>
<details>
<summary><b>Matrices</b> — Standard, Starred & Compact Matrix Environments</summary>
Supports `matrix`, `pmatrix`, `bmatrix`, `Bmatrix`, `vmatrix`, `Vmatrix`, `smallmatrix`, mathtools starred variants with `[l|c|r]` alignment, as well as `array` and `subarray`.
</details>
<details>
<summary><b>Delimiters & Brackets</b> — Automatic Scaling & Manual Sizes</summary>
- 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`).
</details>
<details>
<summary><b>Decorations (42+)</b> — Accents, Cancellation, Stretchy Arrows, Braces</summary>
- **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`.
</details>
<details>
<summary><b>Font Styles (17)</b></summary>
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.
</details>
<details>
<summary><b>Font Sizes (10)</b></summary>
`\tiny`, `\scriptsize`, `\footnotesize`, `\small`, `\normalsize`, `\large`, `\Large`, `\LARGE`, `\huge`, `\Huge`
</details>
<details>
<summary><b>Math Styles</b></summary>
Supports `\displaystyle`, `\textstyle`, `\scriptstyle`, `\scriptscriptstyle`, inline math (`$...$`), and display math (`$$...$$`).
</details>
<details>
<summary><b>Environments (21)</b> — Alignment, Cases, Matrices, Tables</summary>
- **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`
</details>
<details>
<summary><b>Spacing Control</b></summary>
Supports standard mathematical spacing, `\hspace`, `\kern`, `\mkern`, `\allowbreak`, and common escaped special characters.
</details>
<details>
<summary><b>Colors & Backgrounds</b></summary>
- **Text Colors:** `\color`, `\textcolor`
- **Background Colors:** `\colorbox`, `\fcolorbox`
</details>
<details>
<summary><b>Chemistry (13)</b> — mhchem</summary>
Supports `\ce`, `\bond`, and `\pu`, including molecules, ions, isotopes, reaction arrows, and chemical equations.
</details>
<details>
<summary><b>Special Effects & Layout (17)</b></summary>
- **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`
</details>
<details>
<summary><b>Physics & SI Units</b></summary>
- **Derivatives:** `\dv`, `\pdv`
- **Dirac Notation:** `\bra`, `\ket`, `\braket`, `\comm`, `\anticomm`, `\eval`, `\vb`, `\va`, `\abs`, `\norm`
- **SI Units:** `\SI`, `\si`, `\qty`, `\unit`, `\numrange`, `\qtyrange`, `\ang`
</details>
<details>
<summary><b>Advanced Annotations (6)</b></summary>
- **Hyperlinks:** `\href`, `\url`
- **Side Sets:** `\sideset`
- **Prescripts:** `\prescript`
- **Tensor Indices:** `\tensor`, `\indices`
</details>
<details>
<summary><b>Custom Commands & Macros (9)</b></summary>
Supports `\newcommand`, `\renewcommand`, `\def`, `\newenvironment`, `\renewenvironment`, and `\DeclarePairedDelimiter`.
</details>
<details>
<summary><b>Sectioning Commands</b></summary>
`\section`, `\subsection`, `\subsubsection`, `\paragraph`, `\subparagraph` (including starred variants).
</details>
<details>
<summary><b>RTL Text Support</b></summary>
- **Commands:** `\RLE`, `\LRE`, `\textarabic`, `\texthebrew`
- **Environments:** `RTL`, `LTR`
- Supports nested RTL/LTR rendering.
</details>
<details>
<summary><b>Labels & References</b></summary>
Supports `\label`, `\ref`, `\eqref`, `\tag`, and `\tag*`.
</details>
<details>
<summary><b>Error Handling</b></summary>
- Unknown commands are rendered with an error color instead of being silently ignored.
- `parseWithDiagnostics()` provides structured diagnostics with eight error categories and severity filtering.
</details>
## ⚡ 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**](https://pub.dev/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**](https://github.com/KaTeX/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.