2

I recently had to reinstall my tex environment (texlive under windows), and afterwards I got lots of "Missing { [or }] inserted" errors. I managed to track the cause down to the use of \texttt within subscript. More precisely, using pdflatex on the following minimal example

\documentclass{beamer}
\begin{document}
    $A_\texttt{a}$
\end{document}

gives me the following errors:

Missing { inserted. $A_\texttt
Missing } inserted. $A_\texttt{a}$

I guess something must have gone wrong with the fonts, but I can't figure out what.

By the way, for this small example the pdf file is created correctly, but for larger files pdflatex aborts.

Any suggestions?

David Carlisle
  • 757,742
Jan
  • 195
  • Do you have a reason for not writing either $A_{\texttt{a}}$ or $A_{\mathtt{a}}$? – Mico Sep 01 '20 at 16:39
  • 1
    Thanks for the tips. As for \mathtt{}, I'm actually using this string inside a command that can appear inside and outside of math mode, so I'd rather stick with \texttt. As for putting { } around it, I didn't know it was necessary. Any Idea why it worked previously, but not anymore? – Jan Sep 01 '20 at 16:45
  • 2
    it was never supported behaviour but because the parsing of _ is very odd it sometimes works anyway, but any redefinition of texttt is likely to break it again. if _ took it's argument like a macro the braces would be needed, \fbox\texttt{a} would be \fbox{\texttt}{a} and fail badly. – David Carlisle Sep 01 '20 at 16:49
  • 1
    your example works in texlive 2018 but not 2019 or 2020 – David Carlisle Sep 01 '20 at 16:53
  • That figures, my previous texlive installation was a few years old. OK, thanks to both of you, guess I'll have to rewrite a few commands... – Jan Sep 01 '20 at 16:55
  • This is asked all the time. The answer to Math notation in LaTeX? has often been used as a duplicate. Not the best, but it covers the same problem. – barbara beeton Sep 01 '20 at 19:22
  • Barbara, I think my problem is a bit different because I was aware that I have to use curly braces if the sub/superscript contains several characters, but I thought commands, even with arguments, counted as one character. And because omitting the braces used to work for previous releases of texlive and, according to egreg, still works in other document classes. – Jan Sep 01 '20 at 22:32

1 Answers1

2

The suggestion is to use

$A_{\mathtt{a}}$

or, if you really prefer,

$A_{\texttt{a}}$

Beware, though, that in an italic context, the latter would print the subscript in italics.

The error you get is specific to beamer, because it juggles with fonts in order to get as much sans serif as possible. It wouldn't appear with article or other document classes.

Anyway, the syntax A_\texttt{a} has never been officially supported and complex subscript should always be braced.

Some examples are

A_\sqrt{2}
A_\frac{1}{2}
A_\notin

The last example shows that not even a single token is safe. You can safely use unbraced a single letter or digit, with no formatting instruction. For symbols, use braces and you'll be OK. Hence

A_{\mathrm{a}}

is good, whereas A_\mathrm{a} is bad, even if it appears to work.

egreg
  • 1,121,712