# Markdown output in jupyter noteboks

**URL:** <https://discourse.julialang.org/t/markdown-output-in-jupyter-noteboks/34238>\
**Category:** General Usage\
**Tags:** jupyter, markdown\
**Created:** [February 6, 2020, 8:12am UTC](https://discourse.julialang.org/t/markdown-output-in-jupyter-noteboks/34238 "2020-02-06T08:12:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HenrikM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrikm/32/17975_2.png) [@HenrikM](https://discourse.julialang.org/u/HenrikM)\
**Post date:** [February 6, 2020, 8:12am UTC](https://discourse.julialang.org/t/markdown-output-in-jupyter-noteboks/34238/1 "2020-02-06T08:12:08Z")

</div>

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

- [SO: Is it possible to show `print` output as LaTeX in jupyter notebook?](https://stackoverflow.com/questions/48422762/is-it-possible-to-show-print-output-as-latex-in-jupyter-notebook)
- [SO: How to programmatically generate markdown output in Jupyter notebooks?](https://stackoverflow.com/questions/36288670/how-to-programmatically-generate-markdown-output-in-jupyter-notebooks)

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

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [February 6, 2020, 2:30pm UTC](https://discourse.julialang.org/t/markdown-output-in-jupyter-noteboks/34238/2 "2020-02-06T14:30:30Z")

</div>

`Markdown.MD` displays as `text/markdown`. For example

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

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

````

results in  
 ![Screenshot from 2020-02-06 15-30-12](https://global.discourse-cdn.com/julialang/original/3X/e/9/e98dc7a77106f53b58a97047ab782c2808375de3.png)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 6, 2020, 3:29pm UTC](https://discourse.julialang.org/t/markdown-output-in-jupyter-noteboks/34238/3 "2020-02-06T15:29:37Z")

</div>

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

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/d/2d4ecb6951893e507d7a5d1db21ce4a26ac15080.png)

As is [explained in the documentation for `display`](https://docs.julialang.org/en/latest/base/io-network/#Base.Multimedia.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](https://github.com/JuliaGizmos/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).

---

<div class="post-metadata">

**Author:** ![HenrikM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrikm/32/17975_2.png) [@HenrikM](https://discourse.julialang.org/u/HenrikM)\
**Post date:** [February 7, 2020, 7:19am UTC](https://discourse.julialang.org/t/markdown-output-in-jupyter-noteboks/34238/4 "2020-02-07T07:19:41Z")

</div>

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.

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/8/4/84adaf5e143f9351842e94524edf0178da657a59.png)

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [February 7, 2020, 7:44am UTC](https://discourse.julialang.org/t/markdown-output-in-jupyter-noteboks/34238/5 "2020-02-07T07:44:48Z")

</div>

This is at least an option:

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

````
