0

In some contexts, I see the \text command used as follows: $ A_\text B $ , which renders correctly as italics A subscripted by a roman B. However, I recall that I "read somewhere" that the proper usage is $A_\text{B}$ or even $A_{\text{B}}$. In particular, I note that importing packages like breqn introduces errors in the first and second cases.

What is correct, and why?

Jas Ter
  • 111
  • 1
    Welcome to TeX.SX! Always use braces! The correct is $A_{\text{B}}$, and all others work by “accident” – Phelype Oleinik Nov 05 '20 at 11:35
  • 1
    It's just a happy coincidence that the first two versions work. Don't rely on it and use braces. – campa Nov 05 '20 at 11:36
  • Not using braces when not needed is far more elegant. Moreover in this context you should use mathrm rather than text –  Nov 05 '20 at 11:41
  • 1
    Actually ... \text should never even be used for this, it is the wrong command, \text does not do what you think it does, here use $A_{\mathrm{B}} if B is suppose to be upright. Never \text for this – daleif Nov 05 '20 at 11:42
  • @Blincer braces is always better than having to explain to users what it works without braces in some cases and not in other cases. Better to be consistent with the use of braces. Also no-one have guaranteed that the unbraced versions of some commands will always keep workling like that. – daleif Nov 05 '20 at 11:43
  • I don't agree, that would be like asking children to always put brackets when they do calculations. You write 2(3+2) not (2)((3)+(2)). And yes, the version without brackets will still work if there is nothing to bundle. –  Nov 05 '20 at 16:37
  • As I note, omitting braces can break the code with some packages. Thus, I lean towards always using braces. – Jas Ter Nov 06 '20 at 11:32
  • @daleif I think \text does what I think it does. Why is \mathrm preferred? This command preserves math spacing rules, and that looks really odd if the subscript is a phrase, name or similar, and not a mathematical symbol. – Jas Ter Nov 06 '20 at 11:34
  • @JasTer So you are expecting this outcome: \textit{test $A_{\text{B}}$ text} that that is why either \mathrm or even \textrm is preferred over \text. The output of \text corresponds to the text out side math, so if that text is italic, so is the outout of \text. Ergo if B is suppose to he upright in all contexts, \text cannot be used and generally newer should be used for anything by textual commetns in displayed math. What you are doing here is more of a textual index (like in $A_{\textrm{max}}$, since there it is a phrase, I would use \textrm not \mathrm) – daleif Nov 06 '20 at 11:41
  • @daleif Ok, I see! Did not realize that. Thank you! So \textrm is preferred in cases where the subscript is a phrase. – Jas Ter Nov 06 '20 at 11:52
  • @JasTer I've been meaning to write an overview article about \text for year now. Whether one uses \mathrm or \textrm or even \textnormal depends a bit on your language. Say I want to mark the radius of a circular lake in Danish, I'd write $R_{\textrm{sø}}$ because ø cannot be used in math mode and thus is not usable for \mathrm. If you're writing in English, it might be irrelevant whether one used \mathrm or \textrm – daleif Nov 06 '20 at 13:06

0 Answers0