3

I use TeXstudio 2.12.22. Compiling this MWE

\documentclass{scrreprt}
\usepackage{siunitx}
\begin{document}
    Some text $test_\SI{4}{\km}$.
\end{document}

will throw the errors:

line 5: Missing { inserted. Some text $test_\SI
line 5: Missing } inserted. Some text $test_\SI{4}{\km}$

I have tested this with the document classes scrbook and scrartcl as well.

When combining the code with the \text command from the amsmath package, everything works, correctly:

\documentclass{scrreprt}
\usepackage{siunitx}
\usepackage{amsmath}
\begin{document}
    Some text $test_\text{\SI{4}{\km}}$.
\end{document}

Output of the latter MWE

Did I find a bug, Joseph Wright?

  • 1
    Try with an extra set of {} around the \SI command: $test_{\SI{4}{\km}}$. Even if something like $A_4$ gives the desired result, subscripts should always be enclosed in a set of {} as follows: $A_{4}$ – leandriis Feb 27 at 11:38
  • 5
    No bug: complex subscripts should always be braced. If you're used to _\mathrm{x}, change your habits and type _{\mathrm{x}} – egreg Feb 27 at 11:40
7

Math mode _ looks like it is taking 'stuff' as an argument in the construct

$a_\text{b}$

or similar, but this is not the case. Rather, the ability to omit braces in some cases is due to how \text and similar expand. That is not generally true, and official LaTeX syntax is to require braces here in all cases.

In the case of siunitx, the expansion behaviour of the document commands was never intended to 'fool' _ into working. You should add the (standard) braces

\documentclass{scrreprt}
\usepackage{siunitx}
\usepackage{amsmath}
\begin{document}
    Some text $test_{\SI{4}{\km}}}$.
\end{document}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.