2

I would like to insert a copyleft sign inside a \caption. The following command, given here, works outside \caption:

\reflectbox{\sffamily{\copyright}}

and does what I would like.

But this:

\caption{A caption \reflectbox{\sffamily{\copyright}}}

leads to an error. What surprises me most is that

\documentclass{article}
\usepackage{graphicx}
\newcommand{\copyleft}{\reflectbox{\sffamily{\copyright}}}

\begin{document}

\begin{figure}
   \caption{A simple caption \copyleft}
\end{figure}
\end{document}

yields the error:

Undefined control sequence.
\Gscale@box #1[#2]#3->\leavevmode \def \Gscale@x
{#1}\def \Gscale@y {#2}\set...
l.9 \caption{A simple caption \copyleft}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
[...]

but this one works !

\documentclass{article}
\usepackage{graphicx}
\newcommand{\copyleft}{\reflectbox{\sffamily{\copyright}}}


\begin{document}

\copyleft

\begin{figure}
    \caption{A simple caption \copyleft}
\end{figure}
\end{document}

Any ideas or suggestions? I just want to include a copyleft sign in a caption, using latex.

2
  • 3
    Use \DeclareRobustCommand{\copyleft}{...} or place \protect before \copyleft when used in a caption.
    – egreg
    Commented Aug 26, 2013 at 9:36
  • @egreg Surely that's an answer, not just a comment :-)
    – Joseph Wright
    Commented Aug 26, 2013 at 9:38

1 Answer 1

3

\reflectbox is a “fragile” command (see What is the difference between Fragile and Robust commands?), so it needs protection when used (directly or indirectly) in a moving argument.

So you have to do either

\documentclass{article}
\usepackage{graphicx}
\newcommand{\copyleft}{\reflectbox{\sffamily\copyright}}


\begin{document}

\copyleft

\begin{figure}
    \caption{A simple caption \protect\copyleft}
\end{figure}
\end{document}

that is, using \protect in front of \copyleft whenever it is in a moving argument (captions and titles, mostly), or

\documentclass{article}
\usepackage{graphicx}
\DeclareRobustCommand{\copyleft}{\reflectbox{\sffamily\copyright}}


\begin{document}

\copyleft

\begin{figure}
    \caption{A simple caption \copyleft}
\end{figure}
\end{document}

As an aside, notice that \sffamily doesn't take an argument: it is a declaration that remains in force until the group it is in ends; a box command, such as \reflectbox, builds its contents in a group. The version with an argument is \textsf.

2
  • Thank you very much for this informative answer. I guess \newcommand{\copyleft}{\protect\reflectbox{\sffamily\copyright}} would also work, correct?
    – anderstood
    Commented Aug 26, 2013 at 12:01
  • 1
    @anderstood Your alternative definition would survive only one write operation and usually two of them are involved.
    – egreg
    Commented Aug 26, 2013 at 12:25

You must log in to answer this question.

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