6

I defined \+ and \- macros for conveniently entering notation. Surprisingly, I noticed that in table and figure captions \- does not work while \+ works. (The same problem appears also in the content of figures if they're made with TikZ.) Is there any explanation for this strange behavior? Perhaps, this is related to the fact that \- is normally used for hyphenation. But why should that matter after I redefined it?

Here is a minimal working example:

\documentclass{article}

\usepackage{amssymb}
\newcommand{\+}{\boxplus}
\renewcommand{\-}{\boxminus}

\begin{document}
  Plus $\+$ and minus $\-$ work here.
  \begin{figure}
    \caption{Why does $\-$ not work in a caption while $\+$ works?}
  \end{figure}
  \begin{table}
    \caption{Why does $\-$ not work in a caption while $\+$ works?}
  \end{table}
\end{document}

Screen shot of PDF

1
  • Don't do such bad stuff with \-
    – user31729
    Jul 30, 2015 at 20:20

1 Answer 1

9

The macro \caption executes \@parboxrestore, that in turn executes

\let\-\@dischyph

which means that, in a caption, \- gets again its original LaTeX meaning of \discretionary{-}{}{}. Indeed, if you look in the .aux file, you see

Why does $\discretionary {-}{}{}$ not work in a caption while $\boxplus $ works?

It's generally a bad idea to redefine such important commands.

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.