# Superscripts and Subscripts

**URL:** <https://community.plotly.com/t/superscripts-and-subscripts/21721>\
**Category:** Dash Python\
**Created:** [April 1, 2019, 4:13pm UTC](https://community.plotly.com/t/superscripts-and-subscripts/21721 "2019-04-01T16:13:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssgo](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@ssgo](https://community.plotly.com/u/ssgo)\
**Post date:** [April 1, 2019, 4:13pm UTC](https://community.plotly.com/t/superscripts-and-subscripts/21721/1 "2019-04-01T16:13:39Z")

</div>

I am using dash to produce an app. I need to write a sentence or two explaining the app. I am using code like this

```
dcc.Markdown(dedent('''
## Plot of Y_p vs. x_i, z_j shows blah blah blah
''')),

```

this produces the sentence shown, number of hashtags determine size of font

What I need to do is write subscripts and superscripts instead of for example x\_i, I for it to output an actual subscript. Is this possible in the DC markdown? Is there another solution?

PS: I already tried 'x\_i' , r'x\_i' ,text/etc…

Any suggestions appreciated. I should mention that I was able to get subscripts and superscripts to work in html.Div() , by inserting html.Div([‘z’,html.Sub(‘j’)]), and I was able to get the subscripts to show in my actual plot by using text. These methods did not work in dcc.Markdown

---

<div class="post-metadata">

**Author:** ![Damian](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Damian](https://community.plotly.com/u/Damian)\
**Post date:** [April 1, 2019, 4:54pm UTC](https://community.plotly.com/t/superscripts-and-subscripts/21721/2 "2019-04-01T16:54:34Z")

</div>

Dash uses React Markdown to render the markdown: [https://github.com/rexxars/react-markdown](https://github.com/rexxars/react-markdown)

It provides a live way to test your markdown: [https://rexxars.github.io/react-markdown/](https://rexxars.github.io/react-markdown/)

The Markdown spec itself does not provide subscript or superscript: [https://spec.commonmark.org/0.28/](https://spec.commonmark.org/0.28/)

And so most Markdown implementations fallback to HTML tags when you need further formatting features, including React Markdown, on their live demo this works:

```
Plot of Y<sub>p</sub> vs. x<sub>i</sub>, z<sub>j</sub> shows blah blah blah

```

But as you can see there are different HTML escaping procedures, it seems `dcc.Markdown` defaults to “escape” mode. Now it has an argument called `dangerously_allow_html` so I would assume this would work:

```
dcc.Markdown(
    dangerously_allow_html=True,
    children=dedent(
        '''
        Plot of Y<sub>p</sub> vs. x<sub>i</sub>, z<sub>j</sub> shows blah blah blah
        '''
    )
)

```

But when I try it seems to use the “skip” html mode, not the “raw” html mode. So what I would say you have here is a bug in `dcc.Markdown`, I suggest you report it here with an example: [https://github.com/plotly/dash-core-components/issues](https://github.com/plotly/dash-core-components/issues)

It _might_ be a regression from 0.39 to 0.40 as well, I would check the version of Dash you have. Later tonight I will check both versions.

---

<div class="post-metadata">

**Author:** ![ssgo](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@ssgo](https://community.plotly.com/u/ssgo)\
**Post date:** [April 1, 2019, 5:03pm UTC](https://community.plotly.com/t/superscripts-and-subscripts/21721/3 "2019-04-01T17:03:50Z")

</div>

This solution worked perfectly. Thanks @Damian !

---

<div class="post-metadata">

**Author:** ![Damian](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Damian](https://community.plotly.com/u/Damian)\
**Post date:** [April 1, 2019, 5:06pm UTC](https://community.plotly.com/t/superscripts-and-subscripts/21721/4 "2019-04-01T17:06:17Z")

</div>

> [@ssgo](#):
>
> This solution worked perfectly. Thanks @Damian !

What version of Dash are you on?

---

<div class="post-metadata">

**Author:** ![ssgo](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@ssgo](https://community.plotly.com/u/ssgo)\
**Post date:** [April 1, 2019, 5:08pm UTC](https://community.plotly.com/t/superscripts-and-subscripts/21721/5 "2019-04-01T17:08:35Z")

</div>

I am on version Dash 0.38.0

---

<div class="post-metadata">

**Author:** ![Damian](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Damian](https://community.plotly.com/u/Damian)\
**Post date:** [April 1, 2019, 5:09pm UTC](https://community.plotly.com/t/superscripts-and-subscripts/21721/6 "2019-04-01T17:09:46Z")

</div>

Okay! Looks like it broke between 0.39 and 0.40, I will report a bug later tonight!

**Edit:** Never-mind, I created 3 environments at home, 0.38, 0.39, and 0.40, and the only one it correctly works on for me it 0.40. So I’m very confused but as long as it works for you I’m glad!

---

<div class="post-metadata">

**Author:** ![Max3](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Max3](https://community.plotly.com/u/Max3)\
**Post date:** [January 2, 2024, 12:59pm UTC](https://community.plotly.com/t/superscripts-and-subscripts/21721/8 "2024-01-02T12:59:41Z")

</div>

Anyone has an explanation how to use superscript/subscript in 2024?

---

<div class="post-metadata">

**Author:** ![David22](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@David22](https://community.plotly.com/u/David22)\
**Post date:** [January 2, 2024, 4:28pm UTC](https://community.plotly.com/t/superscripts-and-subscripts/21721/9 "2024-01-02T16:28:06Z")

</div>

Dunno if it helps but if yo uadd annotation, for instance, adding yourtext around your text is enough

```auto
                        fig.add_annotation(
                            showarrow=False, font=dict(color="orange", size=10),
                            xref="paper", x=0.069, xanchor="left",
                            text="<sup>3</sup>"
                        )

```

You could also enable mathjax and use

```auto
text=r"$\text{}{\ddagger\ddagger}$", valign="middle"

```

> **[Latex](https://plotly.com/python/LaTeX/)**
>
> Detailed examples of LaTeX including changing color, size, log axes, and more in Python.

For instance. Never tried with markdown, though

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [January 2, 2024, 5:24pm UTC](https://community.plotly.com/t/superscripts-and-subscripts/21721/10 "2024-01-02T17:24:44Z")

</div>

Here’s an example of using mathjax with dcc.Markdown:

> **[Poisson-distribution](https://dash-example-index.herokuapp.com/poisson-distribution)**
>
> This app plots a Poisson distribution on a histogram, which contains a formula with MathJax. It has a top-down layout and a regular-callback.

Also, this might be helpful:

> [@How to make subscript and superscript in Dash](https://community.plotly.com/t/how-to-make-subscript-and-superscript-in-dash/57395/2):
>
> Hi @Mlevesque You can use the html.Sub() and the html.Sup() for subscripts and superscripts: html.Div(["H", html.Sub(2), "H", html.Sup(2)]) [image]
