Menu

#295 Custom text role with inheritence on math role should respect additional class

closed-fixed
nobody
None
5
2020-03-03
2016-02-29
No

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

Discussion

  • Dmitry Shachnev

    Dmitry Shachnev - 2016-03-01

    FWIW using math for chemical formulas is unnecessary — they can be rendered using plain HTML while the math 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).

     
    • Günter Milde

      Günter Milde - 2016-05-24

      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.

       
  • Günter Milde

    Günter Milde - 2016-05-24
    • status: open --> closed-fixed
     
  • Günter Milde

    Günter Milde - 2016-05-24

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.