0

Simply put, the following does not compile:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{figure}
    \caption{
        poly\nobreakdash-Si
    }
\end{figure}

poly\nobreakdash-Si % move this to before figure caption and it works

\end{document}

but, as noted in the code comment, if the command has been used in the body of the document before its use inside the figure caption it does compile (and produce the desired result, in a more complicated example).

Why does this happen?

The error message is ! Argument of \@tempb has an extra }. I have tested this with pdflatex and lualatex in TeX Live 2017 and 2020.

  • 1
    Welcome to tex.sx. \nobreakdash needs to be "protected" in a moving argument: \caption{poly\protect\nobreakdash-Si}. It's possible to define \nobreakdash in a way that doesn't require this, but the definition is an old one and hasn't been upgraded. – barbara beeton Apr 30 '20 at 18:45
  • Thank you for quickly pointing me in the right direction. I've found https://tex.stackexchange.com/questions/4736/what-is-the-difference-between-fragile-and-robust-commands and will be reading and pondering for a while. – LinusSch Apr 30 '20 at 19:00
  • Basically it fails in both cases. But in the one the failure doesn't give an error as @tempa more or less by chance has a definition that avoids this. – Ulrike Fischer Apr 30 '20 at 20:53

1 Answers1

1

latex includes a better version of the amsmath command \nobreakdash, \nobreakdashes. It works with -- and --- and importantly here, it is robust so works in the section heading.

\documentclass{article}
%\usepackage{amsmath}
\begin{document}

\begin{figure} \caption{ poly\nobreakdashes-Si } \end{figure}

poly\nobreakdashes-Si % move this to before figure caption and it works

\end{document}

David Carlisle
  • 757,742
  • So please fix amsmath. – barbara beeton Apr 04 '23 at 19:54
  • @barbarabeeton I only just noticed:-) The latex version was added in 2004, before the team picked up amsmath, documented as This idea is borrowed from the \textsf{amsmath} package but here we define a robust command – David Carlisle Apr 04 '23 at 20:27
  • Fair enough. Maybe just make \nobreakdash robust in amsmath. Removing it could make existing documents unprocessable; not a good idea. – barbara beeton Apr 04 '23 at 20:59