2

I use \text{} a lot for subscripts as it make equations look cleaner.

It is however a giant pain to write something like x_{\text{subscript}} several times over. Not to mention that it makes the latex code a lot harder to read for mere mortals.

Is there a quicker way of achieving the result of writing \text{myText}?

iHnR
  • 141
  • For one, there's always LyX and similar things. – user202729 Jul 11 '22 at 12:19
  • I find this question quite useful: https://tex.stackexchange.com/questions/96080/expanding-subscript-and-subscript-capabilities It defines a shorthand for these kind of subscripts. There are some issues, but I use it in many documents productively. – pschulz Jul 11 '22 at 12:19
  • Maybe \newcommand{\tsub}[2]{#1_{\text{#2}}} then using \tsub{x}{subscript} --- it's quite semantically sound, imho. – Rmano Jul 11 '22 at 12:28
  • @Rmano I quite like that one. It's not exactly what I was looking for, but it's a lot better than the alternative :p – iHnR Jul 11 '22 at 12:35
  • 2
    You should almost never use \text that makes a non-math region that picks up the current font from outside the math (eg it is italic is an italic theorem) – David Carlisle Jul 11 '22 at 13:42
  • @DavidCarlisle This is for an engineering report so I'm alright for now, but thanks for the heads up. Does \textrm{} solve this? – iHnR Jul 11 '22 at 14:07
  • @iHnR normally \mathrm but as Rmano notes you can't currently use that for accented letters, so textrm if you need that – David Carlisle Jul 11 '22 at 14:20

2 Answers2

1

Forcing with strange catcodes changes the standard behavior of _ and ^ is quite for sure a call to have problems down the way (TikZ? babel?). I also use a lot plain text subscripts; I suggest a semantic definition:

\newcommand{\tsub}[2]{#1_{\textrm{#2}}}
\newcommand{\maxval}[1]{\tsub{#1}{máx}}

(for example) and then you can use (notice that it's quite clear what the semantic is, and you have just one point of update if you want to change language...)

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\newcommand{\tsub}[2]{#1_{\textrm{#2}}}
\newcommand{\maxval}[1]{\tsub{#1}{máx}}
\begin{document}

$a+\tsub{b}{medio}=\maxval{c}$

\end{document}

output from the above snippet

(Yes, \textrm¹ and not \mathrm otherwise you can't use máx...)


¹ thanks @DavidCarlisle...

Rmano
  • 40,848
  • 3
  • 64
  • 125
0

You can simply define a custom macro as a little wrapper:

\newcommand{\t}[1]{\text{#1}}

Then you can use \t{myText} instead of \text{myText}.

EDIT: As was pointed out in the comments, \t is already taken. So either choose a different name or - if you don't need the original \t anywhere in your document - use \renewcommand instead to overwrite the definition of \t. This might have other unintended side-effects though, so that's probably not the best idea.

Raven
  • 3,023