Markdown
marimo provides powerful markdown support throughmo.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 usingmo.md():
Interpolating Python Variables
One of the most powerful features ofmo.md() is the ability to interpolate Python variables using f-strings:
Dynamic Content Example
Embedding UI Elements
You can embed UI elements directly in markdown:Complex Example
LaTeX Math
marimo supports LaTeX math rendering for beautiful mathematical expressions.Inline Math
Use single dollar signs for inline math:Display Math
Use double dollar signs or square brackets for display math:Dynamic Math
Combine LaTeX with Python variables:Loading LaTeX from Files
For LaTeX macros or preambles, usemo.latex():
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:Multi-line Strings
Use triple quotes for multi-line markdown: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