I am typing a file where I often have to write $T_{\text{area}}$
. But the command for adding text in a subscript is quite long when I have to write it all the time. Do anyone have any tips on a newcommand that could simplify this, for example where I can type T_area and that gives me the correct format?
I tried to use
\newcommand{T_area}{S_{\text{area}}}
but it does not work. Also It would be nice to generalize it for all texts, not ony "area".
Best Answer
The instruction
is faulty for two separate reasons. First, TeX macros should generally start with a
\
(backslash) character. (Well, there is the\csname ... \endcsname
possibility; however, that's clearly not what you're concerned with.) Second, TeX control sequences should consist of either one or more lowercase and uppercase alphabetical letters (also known asa
toz
andA
toZ
...) or exactly one non-letter character. Examples of non-letter control sequences are\,
,\!
,\_
,\$
,\%
,\\
, etc.Building on these two insights, the alternative definition
is valid -- but only from a purely syntactical point of view. As the comments posted below the query have already pointed out, the output of the
\text
macro is not as robust as you may think it is. Try executing$\Tarea$ \textit{$\Tarea$} \textsc{$\Tarea$} \texttt{$\Tarea$}
and be prepared to be surprised. If you want the subscript material to be typeset exclusively in the upright shape of the document's main text font, givea try. Of course, you are entirely free to choose a different macro name.
Using some unavoidable LaTeX jargon, this objective may be achieved by specifying that
\TareaX
takes an optional argument with default valuearea
:A final remark: Since the TeX-special character
_
occurs in the definitions of the macros\Tarea
and\TareaX
, TeX will issue a (possibly mysterious) warning or error message if these macros are not used while inside math mode.