5
$\begingroup$

Spacing around subscripts within strings seems to work well:

enter image description here

But the spacing around sub-subscripts does not:

enter image description here

I did not manually add that space after the 2. How can this be fixed? Thanks!

$\endgroup$
9
$\begingroup$

The subscript is interpreted as Times[Subscript[H, 2], O], and Mathematica uses spaces to denote multiplication. You can work around this by using the ZeroWidthTimes option:

enter image description here

$\endgroup$
  • $\begingroup$ I appreciate this workaround. Unfortunately, this is one example of several where strings are getting parsed when I don't want them to. I learned (from you) that I could stop different coloration by using ShowAutoStyles->False. Here I learn that I can fix misdisplayed strings with ZeroWidthTimes->True. This is feeling like whack-a-mole. I keep finding places where my notation (Chemistry-specific) runs counter to Mathematica assumptions, and so I have to tell Mathematica to handle each differently, when what I would really like is to tell Mathematica to simply not parse strings. Period. $\endgroup$ – Kevin Ausman Apr 12 at 21:48
  • $\begingroup$ @KevinAusman The problem is that using subscripts inside of a string creates linear syntax, which is essentially the boxes of an expression. It is not a simple string. $\endgroup$ – Carl Woll Apr 12 at 21:56
  • $\begingroup$ Fair enough. I guess I just don't see why a RowBox assumes that sequential boxes are multiplications. It makes sense to assume that if we have an expression, but not if it's in a string. $\endgroup$ – Kevin Ausman Apr 12 at 22:17
1
$\begingroup$

I don't know if this will suit your situation but if you just want to get the expression typeset correctly in, say, a label for graphics, you can do this;

Subscript[X, Row[{Subscript[H, 2], O}]]

typesetting

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.