106

When I need to ask questions, occasionally, I'll need a super or a subscript letter or number for pseudo-code or math equations.

I've seen this done in answers of this question: Special superscript characters

I've gone through the formatting page and for the life of me I can't figure it out.

4
  • 2
    For future reference, you can view the source of any question by clicking the 'edit' button below it (or the 'improve this answer' if not logged in). Commented Sep 14, 2013 at 17:51
  • Although, in that example, it's not superscript, it appears to be some unicode derivative. Commented Sep 14, 2013 at 17:52
  • That question uses the actual Unicode codepoints for superscript characters; it’s not just formatting. If you want a superscript 2, for example, there’s one of those: ² Works in comments, too.
    – Ry- Mod
    Commented Sep 14, 2013 at 17:59
  • Is there a way to do it in comments?
    – user276692
    Commented Mar 16, 2023 at 23:15

4 Answers 4

113

Use <sup> and <sub>:

This is a <sup>superscript</sup>  
This is a <sub>subscript</sub>

This is a superscript
This is a subscript

Using <pre><code> blocks, because they're strange, lets you do this as well:

<pre><code>This is a <sup>superscript</sup>  
This is a <sub>subscript</sub></code></pre>
This is a superscript  
This is a subscript

But it's an evil hack and I wouldn't recommend it.

11
  • 1
    Okay, so is that only usable for regular text? From your example it seems as if it doesn't apply to the code section.
    – Niko
    Commented Sep 14, 2013 at 17:51
  • 1
    @PaulBakerSaltShaker correct - the point of a code block is to show the source. If you put it inside a <pre><code> block however, or use unicode like the other question did, it is possible to have them in there, let me edit my answer for an example. Commented Sep 14, 2013 at 17:52
  • 1
    Okay thanks, I get it now. This makes a lot more sense than it did before. I appreciate the clarification.
    – Niko
    Commented Sep 14, 2013 at 18:02
  • 2
    Oooooh! Evil hacks are fun to know. Commented Sep 14, 2013 at 23:28
  • 5
    Do <sup>sup</sup> and <sub>sub</sub> work in comments, too? Crap. No. Commented Jul 16, 2014 at 22:28
  • 1
    @DavidConrad I notice that on biology.stackexchange.com you can do $O_2$ and it will do the 2 as subscript.
    – barlop
    Commented Mar 17, 2017 at 4:16
  • Broken on May 18, 2017. Commented May 18, 2017 at 14:46
  • 1
    @barlop CO_2 doesn't work within a math equation on Chemistry Stack Exchange but CO_{2} does. Commented Jan 4, 2019 at 22:40
  • This is buggy when I need to show backticks in fenced code. It messes up the text when switching between Rich Text mode and Markdown mode. Reproduction (note there are 4 backticks around the code: <sup><sub>silly way to run a cmd ``` which python ```</sub></sup>
    – Amit Naidu
    Commented Feb 15, 2023 at 3:32
  • 1
    @AmitNaidu It does work with backticks — and all the other shorthand e.g. *italic*, **bold**if you insert whitespace line padding after the opening <sub> tag and before the closing </sub> tag. For example, see the subscript block I added to the bottom of this answer: askubuntu.com/questions/482549/…
    – Benjamin R
    Commented Mar 14, 2023 at 12:39
  • How to do this in comments?
    – user276692
    Commented Mar 16, 2023 at 23:15
4

As this answer to that question says

For instance, here on SO, you could use: demo superscript ABC
That's the output of <sup>demo superscript ABC</sup>

You can also use <sub>…</sub> for subscripting.

4

In the new Stacks Editor the shortcuts for the Superscript Ctrl-. and Subscript Ctrl-, are introduced. Reference: https://github.com/StackExchange/Stacks-Editor/issues/51
Using the new shortcuts you are able to create the Superscript and Subscript texts.

Screenshot for reference:

Superscript, Subscript image

GIF for reference:

Superscript, Subscript gif

1

You can use Unicode superscript numbers (⁰¹²³⁴⁵⁶⁷⁸⁹) or html <sup>2</sup> (but that doesn't work in comments). It seems that some parts of SE are using something called mathjax to render math symbols / formulas including superscript. Here are some examples, but they won't work unless mathjax is enabled.

1
  • For example, this doesn't work here on meta.stackexchange: $x_i^2$, bit it will work in math for example. Commented Nov 26, 2018 at 19:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .