markdown_latex 0.1.6 copy "markdown_latex: ^0.1.6" to clipboard
markdown_latex: ^0.1.6 copied to clipboard

Polished Flutter Markdown + LaTeX mixed renderer. GFM, inline/block math, syntax-highlighted code, edit/preview editor, Light/Dark themes — Notion style.

markdown_latex #

A polished Flutter renderer for Markdown and LaTeX content.

markdown_latex combines GitHub Flavored Markdown, inline and block math, syntax-highlighted code, tables, task lists, themes, and an edit/preview experience in one package.

pub package License: MIT Flutter

Features #

  • Inline math with $...$ and display math with $$...$$
  • GitHub Flavored Markdown, including tables and task lists
  • Syntax highlighting for more than 20 programming languages
  • Selectable text and copyable code blocks
  • Light and dark themes with detailed style customization
  • Edit and preview modes for note and knowledge-base applications
  • Heading anchors and in-document navigation
  • Android, iOS, web, macOS, Windows, and Linux support

Installation #

dependencies:
  markdown_latex: ^0.1.6

Then run:

flutter pub get

The package requires Flutter 3.32 or later and Dart 3.9 or later.

Quick start #

Use a raw Dart string for content containing $ or $$ so Dart does not interpret math delimiters as string interpolation.

import 'package:markdown_latex/markdown_latex.dart';

MarkdownLatex(
  data: r'''
# Schrodinger equation

$i\hbar\frac{\partial}{\partial t}\Psi = \hat{H}\Psi$

$$
-\frac{\hbar^2}{2m}\nabla^2\Psi + V\Psi
= i\hbar\frac{\partial\Psi}{\partial t}
$$
''',
  theme: MarkdownLatexTheme.light(),
  selectable: true,
)

Long documents #

MarkdownLatex uses an inline layout. Wrap it in a scroll view for long documents:

SingleChildScrollView(
  padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
  child: MarkdownLatex(
    data: longArticle,
    maxWidth: 720,
  ),
)

Editor #

final controller = MarkdownLatexEditorController(
  initialData: initialMarkdown,
  selectable: true,
);

MarkdownLatexEditor(
  controller: controller,
  theme: MarkdownLatexTheme.dark(),
  toolbarBuilder: (_, theme) => MarkdownLatexEditorToolbar(theme: theme),
);

// Dispose the controller when it is no longer needed.
controller.dispose();

If theme is omitted, the renderer follows Theme.of(context).brightness.

Main API #

Component Purpose
MarkdownLatex Render mixed Markdown and LaTeX content
MarkdownLatexTheme Configure colors and component styles
MarkdownLatexEditor Switch between editing and previewing
MarkdownLatexEditorController Manage editor content and mode
MarkdownLatexEditorToolbar Provide the built-in editor toolbar

MarkdownLatex parameters #

Parameter Type Default Description
data String required Markdown and LaTeX source
theme MarkdownLatexTheme? system Visual theme
selectable bool false Whether rendered text is selectable
maxWidth double? null Maximum centered content width
padding EdgeInsetsGeometry zero Outer content padding
onTapLink ValueChanged<String>? open URL Custom link callback

Local example #

git clone https://github.com/hurricane-gathering/markdown_latex.git
cd markdown_latex
flutter pub get
flutter run

Contributing #

Bug reports and pull requests are welcome in the GitHub repository.

This project is available under the MIT License.

2
likes
160
points
88
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Polished Flutter Markdown + LaTeX mixed renderer. GFM, inline/block math, syntax-highlighted code, edit/preview editor, Light/Dark themes — Notion style.

Repository (GitHub)
View/report issues

Topics

#markdown #latex #math #mixed-rendering #syntax-highlighting

License

MIT (license)

Dependencies

flutter, flutter_highlight, flutter_markdown_plus, flutter_math_fork, markdown, provider, url_launcher

More

Packages that depend on markdown_latex