# Would like <…> to expand to \text{…}

Almost every subscript I write has to be in \text{..}, so to de-clutter, it would be nice to be able to write e.g. x_<high> instead of x_\text{high}.

(Shortening it to \t{..} is not quite as pretty.)

There was a similar question about using §...§ notation for this purpose, so the \def from the accepted answer there gives a half-way solution here. But the trouble is that I'll need \lt and \gt to map to < and > that would not be expanded in turn. I'm not sure what machinery to use here.

• You could use a keyboard shortcut mapper instead. – Azor Ahai Jul 12 '17 at 16:08
• @Azor-Ahai I use them heavily, but the lessons of markup and Markdown cannot be ignored... – Evgeni Sergeev Jul 16 '17 at 11:43

\makeatletter
\begingroup\lccode~=_\lowercase{\endgroup\def~}{\extendedsb}
\def\extendedsb{\@ifnextchar<\textsb\sb}
\def\textsb<#1>{\sb{\textnormal{#1}}}
\AtBeginDocument{\catcode_=12 \mathcode_="8000 }
\makeatother

• This lets you use < and > normally, e.g., $x_<high>>A_<op><B_<op>$. – Manuel Jul 12 '17 at 13:39
• If you want to be able to nest the _<<symbols>> then we can use xparse. – Manuel Jul 13 '17 at 2:40

It's pretty simple, actually. When you define some macro (or use \let to assign it) the current catcodes for the left hand side of the definition or assignment become fixed, so you can do the following:

\documentclass{article}

\usepackage{amsmath}
\let\lt=<
\let\gt=>

{
\catcode\<=\active
\gdef<#1>{{\text{#1}}}
}
\AtBeginDocument{%
\catcode\<=\active
}

\begin{document}
$A_<op>\lt B_<op>$
\end{document}


The \AtBeginDocument part delays the actual catcode switching which can help with some packages that need the old category (for example for comparing numbers using \ifnum).

• Neat! I guessed correctly that it doesn't allow nesting, but for some reason, if the nesting is through a macro, it works fine. For example, the following works: \newcommand{\xhigh}{x_<high>} $x + y = z <where \xhigh = 0 >$. – Evgeni Sergeev Jul 13 '17 at 2:25
• Or simply brace the index: $x + y = z < where x_{<high>} = 0>$. – Sergei Golovan Jul 13 '17 at 5:40
• I've been using this heavily the last couple of months. It caused much less side-effect trouble than may be presumed. Such a simple fix, makes a lot of difference. One strange thing I noticed is that if we \usepackage{mathtools}, it stops working, unless we also \usepackage[pdftex]{graphicx}. An interesting case of package-package interference... – Evgeni Sergeev Aug 21 '17 at 1:40
• I've updated the answer mitigating somewhat the interference issue. – Sergei Golovan Aug 21 '17 at 5:14