3
$\begingroup$

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$$

| |
$\endgroup$
  • 1
    $\begingroup$ Related: Always \textrm, never \rm? A counterexample?. See also texfaq.org/FAQ-2letterfontcmd $\endgroup$ – user7951 Apr 27 '19 at 6:23
  • $\begingroup$ @Loong Hehe, that beast was your one. :-D $\endgroup$ – Poutnik Apr 27 '19 at 6:24
  • $\begingroup$ I can understand \rm messing with some text formatting, but mathrm messing with my formula readability is currently bigger issue for me. $\endgroup$ – Poutnik Apr 27 '19 at 6:35
  • $\begingroup$ 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. $\endgroup$ – Poutnik Apr 27 '19 at 7:44
10
$\begingroup$

\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:)

VSCode rocks

| |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Poutnik Apr 27 '19 at 8:34
  • $\begingroup$ Note that I have excluded from my question {\mathrm text} even before reading your answer, originally thought it was OK. $\endgroup$ – Poutnik Apr 27 '19 at 8:39
  • $\begingroup$ @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. $\endgroup$ – andselisk Apr 27 '19 at 8:39
  • $\begingroup$ 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. $\endgroup$ – Poutnik Apr 27 '19 at 8:43
  • $\begingroup$ Unrelated, but it is also reason I hate multiline Excel formulas, preferring VBA functions. $\endgroup$ – Poutnik Apr 27 '19 at 8:44
  • $\begingroup$ 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. $\endgroup$ – andselisk Apr 27 '19 at 8:45
  • $\begingroup$ 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. $\endgroup$ – andselisk Apr 27 '19 at 8:47
  • $\begingroup$ 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. $\endgroup$ – Poutnik Apr 27 '19 at 8:49
  • $\begingroup$ I wrote 2 quite big projects in VBA. If there were Excel formulas, I would be dead or crazy. $\endgroup$ – Poutnik Apr 27 '19 at 8:51
  • 1
    $\begingroup$ 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:) $\endgroup$ – andselisk Apr 27 '19 at 8:52
  • $\begingroup$ I see. The world is not ideal. Who invented Roman indexes ?? :-) $\endgroup$ – Poutnik Apr 27 '19 at 8:54
  • 1
    $\begingroup$ I bet it weren't Romans. This would've been a direct violation of Stigler's law:D $\endgroup$ – andselisk Apr 27 '19 at 8:58
  • 1
    $\begingroup$ 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. $\endgroup$ – Poutnik Apr 27 '19 at 9:03
  • 1
    $\begingroup$ You can use eqref without dollars ;) And &+\quad can be +& for probably the same result. $\endgroup$ – Martin - マーチン Apr 27 '19 at 9:09
  • 2
    $\begingroup$ @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.) $\endgroup$ – Martin - マーチン Apr 27 '19 at 9:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .