Skip to content

Instantly share code, notes, and snippets.

@mattpitkin
Last active March 14, 2023 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpitkin/ce45d48664455c8c30c515a30425161c to your computer and use it in GitHub Desktop.
Save mattpitkin/ce45d48664455c8c30c515a30425161c to your computer and use it in GitHub Desktop.

How to typeset a value and its uncertainty in HTML (without a CSS stylesheet)

If you want to quote a value and a plus/minus uncertainty range in HTML, using the <sup> and <sub> tags leaves the values offset, e.g.:

2.3<sup>+1.2</sup><sub>-0.5</sub>

gives:

2.3+1.2-0.5

If the webpage supports MathJAX (or something similar), then you could, of course, use LaTeX syntax, e.g.,

$2.3^{+1.2}_{-0.5}$

to give:

$2.3^{+1.2}_{-0.5}$

However, if you just want to use HTML (and don't want/can't use a style sheet), then (heavily based on this SO answer), you could do:

<span style="white-space:nowrap;">
   2.3<span style="display:inline-block;vertical-align:-0.4em;margin-left:0.1em;line-height:1.15em;font-size:70%;text-align:left;">+1.2<br/>−0.5</span>
</span>

Unfortunately, the style attribute gets sanitised by the Markdown renderer used to GitHub, but an image of it looks like:

Uncertainty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment