From: Tom Roche
Subject: styling a replacement
Archived-At: http://permalink.gmane.org/gmane.text.docutils.user/7512
asked about styling replacement. He uses chemical formula H2O and want "2" be subscript and all text be emphasised.
This already do :math: role / directive.
I try:
.. role:: chem(math)
:class: chem
This is :chem:H_2O
.
but unfortunately get:
CO2
I can't see additional class "chem". It would be very heplful to distinguish mathematical and chemical formulas in resulted HTML via custom additional style.
See original reference that suggest such usage: http://docutils.sourceforge.net/docs/ref/rst/directives.html#custom-interpreted-text-roles
FWIW using
math
for chemical formulas is unnecessary — they can be rendered using plain HTML while themath
role will usually result in being rendered with something like MathJax.You can write H20 with the help of this tip (looks like the author of docutils-user post did exactly that).
The problem is, that italic subscripts are another form of nested inline markup and require a custom role with matching CSS styling rule. So, while not impossible, the substitution-approach becomes quite complicated (see attachment).
However, as David Goodger suggested this special case is better solved using Unicode characters for the subscript 2.
While I do not recommend using :math: for chemical formulas, the request for class-inheritance of a custom role is valid.
This is fixed now, thanks for the bug report.