12

The following piece of reStructuredText does not give the result I expect.

*:sup:`superscript`*

Expected result: superscript

Actual result: :sup:`superscript`

The reason why it is happening is clear (reST text roles cannot be nested), however how can I obtain the expected result?

Andrea Corbellini
  • 17,339
  • 3
  • 53
  • 69

2 Answers2

6

As specified in a FAQ, this is not currently possible without using the raw directive or without using a custom, ad-hoc directive.

Andrea Corbellini
  • 17,339
  • 3
  • 53
  • 69
  • 3
    "...on the to-do list... and hopefully will be part of the reStructuredText parser soon", as of [2004-06-14](https://github.com/tony/docutils/commit/5db39c158f316a28fb9ff941a9737e22b68d2f41). Patience is a virtue :). – Pont Mar 09 '19 at 17:42
4

You can use substitution:

The chemical formula for pure water is |H2O|.

.. |H2O| replace:: H\ :sub:`2`\ O

See the reStructuredText spec for further information on character-level markup and the substitution mechanism.

Brent
  • 1,324
  • 1
  • 15
  • 22