Markdown output in jupyter noteboks

In Python it seems to be easy to output markdown in a jupyter notebook, see

I have not found a way to do this in Julia. How can I do this in Julia?

1 Like

Markdown.MD displays as text/markdown. For example

using Markdown
Markdown.parse("""
# Header-1

Some text.
```julia
some + code
```
""")

results in
Screenshot from 2020-02-06 15-30-12

2 Likes

The easiest way is to use display("text/markdown", "...some markdown text..."). For example:

As is explained in the documentation for display, by passing a MIME type as the first argument you can supply the “raw” data in any given MIME type. (e.g. you can supply a string of text/latex, a byte array of image/png data, and so on.)

The advantages of creating a Markdown.MD object, as suggested by @fredrikekre, are that (1) you can return this object so that it can be displayed in a context determined by the caller (e.g. for use by Interact.jl) and (2) it can display in contexts that don’t support markdown (e.g. it can display as plain text in the REPL, or as text/html in contexts that support this). The disadvantage is that it requires a bit more typing and is marginally slower (since it requires Julia to parse the markdown text instead of sending it as-is to Jupyter).

3 Likes

Thank you, this was exactly what I was looking for!

Follow up question: How can I use produce latex display math in jupyter?
If I evaluate the cell shown below it prints dollars symbols before and after the equation.

s = raw"
# Hello
$$
\begin{bmatrix}
a
\end{bmatrix}
$$
"
Markdown.parse(s)

Below is an image of what “native” markdown in jupyter looks like and what Julia markdown looks like.
markdown_latex

This is at least an option:

s = raw"
# Hello
```math
\begin{bmatrix}
a
\end{bmatrix}
```
"
Markdown.parse(s)
1 Like