Markdown

Hello, Markdown!

Use marimo’s “md” function to write markdown. This function compiles Markdown into HTML that marimo can display.

For example, here’s the code that rendered the above title and paragraph:

mo.md(
    '''
    # Hello, Markdown!

    Use marimo's "`md`" function to embed rich text into your marimo
    apps. This function compiles your Markdown into HTML that marimo
    can display.
    '''
)

Tip: toggling between the Markdown and Python editor

Although markdown is written with mo.md, marimo provides a markdown editor that hides this boilerplate from you.

Toggle between the Markdown and Python editors by clicking the blue icon in the top-right of the editor, entering Ctrl/Cmd+Shift+M, or using the “cell actions menu”. You can also hide the markdown editor through the cell actions menu.

Tip: To interpolate Python values into markdown strings, you’ll need to use mo.md(f"...") directly; the markdown view does not support f-strings. ## LaTeX You can embed LaTeX in Markdown.

For example,

mo.md(r'$f : \mathbf{R} \to \mathbf{R}$')

renders \(f : \mathbf{R} \to \mathbf{R}\), while

mo.md(
    r'''
    \[
    f: \mathbf{R} \to \mathbf{R}
    \]
    '''
)

renders the display math

[ f: . ]

Use r'' strings to remove the need to escape backslashes when writing LaTeX.
marimo actually uses KaTeX, a math typesetting library for the web which supports a subset of LaTeX. For a list of (un)supported commands, visit https://katex.org/docs/support_table

Interpolating Python values

You can interpolate Python values into markdown using f-strings and marimo’s as_html function. This lets you create markdown whose contents depend on data that changes at runtime.

Here are some examples.

marimo objects know how to format themselves, so you can omit the call to as_html.
mo.as_html is only needed when interpolating objects into markdown; the last expression of a cell (its output) is converted to HTML automatically.

Putting it all together

Here’s a more interesting example that puts together everything we’ve learned: rendering markdown with LaTeX that depends on the values of Python objects.

Back to top