68

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 questions like in this answer: Special superscript characters

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

  • 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). – Richard J. Ross III Sep 14 '13 at 17:51
  • Although, in that example, it's not superscript, it appears to be some unicode derivative. – Richard J. Ross III Sep 14 '13 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- Sep 14 '13 at 17:59
78

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.

  • Okay, so is that only usable for regular text? From your example it seems as if it doesn't apply to the code section. – Paul Nelson Baker Sep 14 '13 at 17:51
  • @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. – Richard J. Ross III Sep 14 '13 at 17:52
  • Okay thanks, I get it now. This makes a lot more sense than it did before. I appreciate the clarification. – Paul Nelson Baker Sep 14 '13 at 18:02
  • 2
    Oooooh! Evil hacks are fun to know. – dmckee Sep 14 '13 at 23:28
  • 4
    Do <sup>sup</sup> and <sub>sub</sub> work in comments, too? Crap. No. – David Conrad Jul 16 '14 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 Mar 17 '17 at 4:16
  • Broken on May 18, 2017. – Peter - Reinstate Monica May 18 '17 at 14:46
  • @barlop CO_2 doesn't work within a math equation on Chemistry Stack Exchange but CO_{2} does. – Chris Jenks Jan 4 at 22:40
5

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.

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.

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

You must log in to answer this question.

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