Skip to main content

Markdown

marimo provides powerful markdown support through mo.md(), allowing you to create rich text content with embedded Python variables, LaTeX equations, and interactive UI elements.
Markdown in marimo is dynamic - you can interpolate Python variables and even embed interactive UI elements directly in your markdown.

Basic Markdown

Create markdown content using mo.md():
The output is automatically rendered as formatted HTML.

Interpolating Python Variables

One of the most powerful features of mo.md() is the ability to interpolate Python variables using f-strings:

Dynamic Content Example

When you move the slider, the markdown cell automatically updates!

Embedding UI Elements

You can embed UI elements directly in markdown:
The UI element appears inline with the markdown text.

Complex Example

LaTeX Math

marimo supports LaTeX math rendering for beautiful mathematical expressions.

Inline Math

Use single dollar signs for inline math:
Use raw strings (prefix with r) to avoid escaping backslashes in LaTeX.

Display Math

Use double dollar signs or square brackets for display math:
Or using square brackets:

Dynamic Math

Combine LaTeX with Python variables:

Loading LaTeX from Files

For LaTeX macros or preambles, use mo.latex():
This is useful for defining custom LaTeX commands that you want to use throughout your notebook.

Markdown Extensions

marimo supports many markdown extensions for rich formatting:

Tables

Task Lists

Code Blocks with Syntax Highlighting

Python Console Sessions

marimo automatically detects Python console sessions:

Emojis

Footnotes

Strikethrough and Formatting

Keyboard Keys

Admonitions

Create callout boxes:

Embedding HTML Objects

Embed plots, charts, and other visualizations:
Use mo.as_html() to convert non-HTML objects (like matplotlib plots) into HTML for embedding in markdown.

Multi-line Strings

Use triple quotes for multi-line markdown:
marimo’s md() function automatically strips leading whitespace using Python’s cleandoc, so indentation in your Python code doesn’t affect the rendered output.

Advanced Examples

Interactive Dashboard

Mathematical Document

Data Summary

Best Practices

1

Use raw strings for LaTeX

Always use r""" for strings containing LaTeX to avoid escaping backslashes.
2

Separate content from logic

Create UI elements and calculations in separate cells, then reference them in markdown.
3

Format numbers appropriately

Use Python’s formatting (:.2f, :,.0f) to make numbers readable.
4

Leverage f-strings

Use f-strings for clean, readable variable interpolation.

Dynamic

Markdown updates automatically when variables change

Rich Formatting

Tables, code blocks, math, emojis, and more

Interactive

Embed UI elements directly in markdown

Extensible

Supports many markdown extensions out of the box

Common Patterns

Form with Markdown

Conditional Content

Markdown in marimo is reactive - when any interpolated variable changes, the markdown automatically re-renders with the new values!