# Using mathrm versus rm MathJax index formatting

I do not understand well, why is so much preferred \mathrm to \rm for index formatting ?

(by occurrence and by user script formatting support.)

Note that I currently use LaTeX/MathJax only in context of SE posts. I have in mind mostly uniform text formatting and MathJax mathematical formulas. Advanced LaTeX documents with document text formatting are probably a different case.

If my understanding is correct, their effect is the same, but they differ in their default scope and delimiting syntax.

The \rm must be explicitly delimited, with \rm being inside delimiters.

\mathrm by default applies to a single character only, with \mathrm outside of delimiters {}.

This theoretically gives an advantage to \mathrm for single letter indexing.

But even in this case, the \rm way to create the source formatting code seems to me as more compact and in case of complex formula more easily to track mentally.

For 2+ symbol indexes, this mentioned advantage of \mathrm disappears, as {} delimiting is needed in both cases.

I ask, because if others apply intensive \mathrm formatting of complex formulas with many indexes, it may convert a relatively compact expression into a "huge formatted beast", difficult to be read and work with at the source code level even for its author.

Later editing of such a formula may be a nightmare.

One solution for me is to create 2(or 4) regex replace expressions to toggle \mathrm (or \rm) index "romanizing" to get the formula readable again for editing/reusing, and then toggle it back.

Some code examples are intentionally wrong for illustrative purposes:

K_{\rm x} K_\mathrm x K
K_{\rm xy} K_\mathrm xy K wrong
K_{\rm xy} K_{\mathrm xy} K wrong
K_{\rm xy} K_\mathrm {xy} K
K_\rm {xy} K_\mathrm {xy} K wrong

$$K_{\rm x} K_\mathrm x K$$ $$K_{\rm xy} K_\mathrm xy K$$ $$K_{\rm xy} K_{\mathrm xy} K$$ $$K_{\rm xy} K_\mathrm {xy} K$$ $$K_\rm {xy} K_\mathrm {xy} K$$

• – user7951
Apr 27 '19 at 6:23
• @Loong Hehe, that beast was your one. :-D Apr 27 '19 at 6:24
• I can understand \rm messing with some text formatting, but mathrm messing with my formula readability is currently bigger issue for me. Apr 27 '19 at 6:35
• One solution for me is to create 2(or 4) regex replace expressions to toggle \mathrm (or \rm) index "romanizing" to get the formula readable again for editing/reusing, and then toggle it back. Apr 27 '19 at 7:44

\rm shouldn't be used at all as it's a deprecated command existing solely for the backward compatibility. Historically, the two-letter commands such as \it, \bf and \rm are the inheritance of the old $$\mathrm{\LaTeX}$$ 2.09 and AMS-$$\mathrm{\LaTeX}$$ 1.1 and are not the part of the current production-level $$\mathrm{\LaTeX}2ε$$ and probably will be dropped entirely in the upcoming $$\mathrm{\LaTeX}3$$.

There are two main reasons for not to use \rm from the perspective of a $$\mathrm{\LaTeX}$$ system:

1. As it's not a part of $$\mathrm{\LaTeX}$$, ususally document classes define it as such so that in most cases \rm is equivalent to \normalfont\rmfamily — but there is no standard. Also, some classes such as KOMA-Script recently dropped the support for \rm completely.

2. All two-letter commands including \rm are not orthogonal, e.g. the order these commands are given is important and you cannot supply certain font attributes.

\mathrm, on the other hand, only adds math roman typeface and is lacking all these limitations or \rm. As for MathJax, I don't fully understand the reason for keeping \rm, but it is there (compatibility with legacy version, maybe?), even though its usage is undesirable as it produces the code that is semantically incorrect and may cause potential problems in the future when MathJax receives a major update.

Addressing you issue with the code formatting, passing the text you want to be an upright math font as an argument to \mathrm{…}, e.g. x_\mathrm{y + z} $$(x_\mathrm{y + z})$$, always works correctly no matter how many symbols you have. Although for a single symbol \mathrm␣<symbol>, e.g. x_\mathrm y + z $$(X_\mathrm y + z)$$, will do. Enclosing {\mathrm foo bar} in curly braces won't turn the upright mode on as it were in case with {\rm foo bar}, so please avoid using it as such unless you know what you doing, e.g. with X_{\mathrm y + z} $$(X_{\mathrm y + z})$$.

Speaking of code readability, I don't see any difference between \rm and \mathrm. $$\mathrm{\LaTeX}$$ syntax in general is considered cumbersome by many, but there is no sane alternative yet. If you are really upset with how the MathJax code reads on SE, you can use some text editor with advanced syntax highlighting for editing and writing your posts. Sure, you don't get instant preview out of the box, but OMG look at all these colors:)

• The fact is, the "real formula code" is diluted by \mathrm meta code. significantly more. Highlighting can help just partially (e.g. Notepad++). I strongly consider regex based toggling as mentioned before. Apr 27 '19 at 8:34
• Note that I have excluded from my question {\mathrm text} even before reading your answer, originally thought it was OK. Apr 27 '19 at 8:39
• @Poutnik I honestly don't see how \mathrm is more diluting. Probably you really like Groff with its two-symbol commands on the beginning of each line, but it's not going to work with LaTeX or similar markup systems as there are too many of them. At this point it's not a matter of personal preferences, using \rm is just wrong. Of course, you can convert the code for your own usage with regex, but please avoid making it public and do convert it back to \mathrm before posting.
– andselisk Mod
Apr 27 '19 at 8:39
• I am not going to use \rm out of explicit scope of my question, and definitely not if I use some LaTeX editors. I have personally difficulties, if a formula is stretched over many lines to read it. Apr 27 '19 at 8:43
• Unrelated, but it is also reason I hate multiline Excel formulas, preferring VBA functions. Apr 27 '19 at 8:44
• Just put a line break whenever you want, plus your version control system will benefit from it as it gets shorter diffs. If the formula is long, put a line break after =; if it's very long, then after each operator.
– andselisk Mod
Apr 27 '19 at 8:45
• VBA is not much better than plain Excel formulas. In fact it's so bad that it's the most dreaded language for the fast few years according to SO stats.
– andselisk Mod
Apr 27 '19 at 8:47
• Well, it may help, but just partially. It causes me "not seeing the wood because of trees". BTW, by regex I mean toggling, not removing. Apr 27 '19 at 8:49
• I wrote 2 quite big projects in VBA. If there were Excel formulas, I would be dead or crazy. Apr 27 '19 at 8:51
• Well, to put it straight, \mathrm is the reality and you have to somehow cope with it. How you do this is entirely up to you, I only shared my limited perspective. If the regex switch is working for you, it's totally fine, go for it. I just think it adds unnecessary complexity, but it's just me:)
– andselisk Mod
Apr 27 '19 at 8:52
• I see. The world is not ideal. Who invented Roman indexes ?? :-) Apr 27 '19 at 8:54
• I bet it weren't Romans. This would've been a direct violation of Stigler's law:D
– andselisk Mod
Apr 27 '19 at 8:58
• I will add to my future posts a warning message not format it yet, as it may not be finished look yet. MathJax is as talkative as Pascal. Apr 27 '19 at 9:03
• You can use eqref without dollars ;) And &+\quad can be +& for probably the same result. Apr 27 '19 at 9:09
• @andselisk I only saw that because of the pretty colours. In latex you wouldn't set the references in maths delimiters, and since this is something our site can actually handle, I thought is worth knowing. (Btw. I totally agree with your post.) Apr 27 '19 at 9:29