Thanks to this answer, I wrote this code:

\catcode`\| 12 %

I'm getting:

! Missing { inserted.
<to be read again>
l.15 $a_|

However, $a |b|$ works just fine. Also $a_{|b|}$ also works. Is it possible to fix this and make it possible to use $a_|b|$ (without the curled brackets around |b|)?

  • why support that syntax? subscripts should always be braced. Commented Nov 15, 2022 at 22:21
  • @DavidCarlisle I can do $a_\text{hello}$, but can't do $a_\foo{hello}$
    – yegor256
    Commented Nov 15, 2022 at 22:24
  • It is really unfortunate, undocumented and accidental that \text does not error in that context Commented Nov 15, 2022 at 22:26
  • If your aim is to use a_|b| to get the subscript in \mathtt, you're using the wrong approach. Do you really need verbatim subscripts? With special characters such as #{}?
    – egreg
    Commented Nov 15, 2022 at 22:37
  • yes as egreg said I have been wondering why verbatim, none of the examples in your recent questions have needed that Commented Nov 15, 2022 at 22:45

1 Answer 1


The fact that some commands, as an accidental sequence of undocumented expansions, do not give errors on horrible input constructions such as x_\text{foo} or x^\frac12 does not mean that such things need copying elsewhere. The documented latex syntax always braces subscripts.

That said, assuming you want to ignore this advice...

\catcode`\| 12 %

You must log in to answer this question.

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