10

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.

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

2 Answers 2

13
\makeatletter
\begingroup\lccode`~=`_\lowercase{\endgroup\def~}{\extendedsb}
\def\extendedsb{\@ifnextchar<\textsb\sb}
\def\textsb<#1>{\sb{\textnormal{#1}}}
\AtBeginDocument{\catcode`_=12 \mathcode`_="8000 }
\makeatother
2
  • 3
    This lets you use < and > normally, e.g., \[ x_<high>>A_<op><B_<op> \].
    – Manuel
    Commented Jul 12, 2017 at 13:39
  • If you want to be able to nest the _<<symbols>> then we can use xparse.
    – Manuel
    Commented Jul 13, 2017 at 2:40
8

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).

4
  • 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$ > \]. Commented Jul 13, 2017 at 2:25
  • 1
    Or simply brace the index: \[ x + y = z < where $x_{<high>} = 0$> \]. Commented Jul 13, 2017 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... Commented Aug 21, 2017 at 1:40
  • 1
    I've updated the answer mitigating somewhat the interference issue. Commented Aug 21, 2017 at 5:14

You must log in to answer this question.

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