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

Flutter Markdown + LaTeX mixed renderer. GFM, inline/block math, syntax-highlighted code blocks, task lists, tables, edit/preview editor — Notion / GitHub styling.

markdown_latex #

pub package License: MIT

Flutter Markdown + LaTeX 混合渲染组件 — 同时渲染 Markdown 正文与 LaTeX 数学公式。
视觉风格接近 Notion / GitHub,支持 GFM、代码高亮、编辑/预览双模式。


✨ Features #

Feature Description
🔀 混合渲染 Markdown 与 $...$ / $$...$$ LaTeX 公式无缝混排
📝 GFM 标题、粗斜体、列表、引用、表格、任务列表
💻 代码高亮 flutter_highlight 语法高亮 + 一键复制
✏️ 编辑/预览 MarkdownLatexEditor 双模式 + 文本可选开关
🌗 主题 内置 Light / Dark,可完全自定义

📦 Installation #

dependencies:
  markdown_latex: ^0.1.1
  provider: ^6.1.5   # 使用 MarkdownLatexEditor 时需要
flutter pub get

环境要求: Flutter >=3.32.0,Dart >=3.8.0


🚀 Quick Start #

⚠️ 含 $$$ 的字符串请使用 raw stringr'...'),避免 Dart 插值冲突。

import 'package:markdown_latex/markdown_latex.dart';

MarkdownLatex(
  data: r'# Hello

质能方程:$E=mc^2$',
  theme: MarkdownLatexTheme.light(),
  selectable: true,
)

可滚动长文档 #

MarkdownLatex 本身不滚动,请包裹 SingleChildScrollView

SingleChildScrollView(
  padding: const EdgeInsets.all(16),
  child: MarkdownLatex(data: longDocument),
)

编辑 / 预览 #

final controller = MarkdownLatexEditorController(
  initialData: r'# Hi

$x^2$',
);

MarkdownLatexEditor(
  controller: controller,
  toolbarBuilder: (context, theme) =>
      MarkdownLatexEditorToolbar(theme: theme),
);

// 用完后释放
controller.dispose();

🧩 API #

Widget Description
MarkdownLatex 混合渲染主组件
MarkdownLatexTheme 主题(含 mathBackground / mathBorder
MarkdownLatexEditor 编辑/预览编辑器
MarkdownLatexEditorController 内容、模式、selectable 状态
MarkdownLatexEditorToolbar 内置工具栏

MarkdownLatex 常用参数 #

参数 类型 默认 说明
data String 必填 Markdown + LaTeX 源码
theme MarkdownLatexTheme? 跟随系统 渲染主题
selectable bool false 是否可选中文本
maxWidth double? null 内容最大宽度(居中)
onTapLink ValueChanged<String>? 自动打开 链接点击回调

📐 LaTeX 语法 #

行内:$E = mc^2$

单行显示:$$\frac{a}{b}$$

多行块:
$$
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
$$

🏗️ 项目结构 #

lib/
├── markdown_latex.dart          # 导出入口
└── src/
    ├── markdown_latex_view.dart # MarkdownLatex 渲染
    ├── theme.dart
    ├── editor/                  # 编辑/预览
    ├── syntax/math_syntax.dart  # LaTeX 解析
    └── builders/                # 代码块 & 公式

本地 Demo:flutter run(根目录 lib/main.dart


📄 License #

MIT © 2026 — 见 LICENSE

2
likes
0
points
88
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter Markdown + LaTeX mixed renderer. GFM, inline/block math, syntax-highlighted code blocks, task lists, tables, edit/preview editor — Notion / GitHub styling.

Repository (GitHub)
View/report issues

Topics

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

License

unknown (license)

Dependencies

flutter, flutter_highlight, flutter_markdown, flutter_math_fork, markdown, provider, url_launcher

More

Packages that depend on markdown_latex