I'd like to redefine \caption* as

\renewcommand{\caption*}[1]{\vspace{\abovecaptionskip}\caption*{\textbf{Note:} #1}\vspace{-\abovecaptionskip}}

but keep getting an error when I try to compile. My work-around is to just define the new command \floatnote and use that instead of \caption*. It's a perfectly fine work-around, but I'm left with the question:

Q: Why doesn't the above \renewcommand code work?

%\renewcommand{\caption*}[1]{\vspace{\abovecaptionskip}\caption*{\textbf{Note:} #1}\vspace{-\abovecaptionskip}}
\newcommand{\floatnote}[1]{\vspace{\abovecaptionskip}\caption*{\textbf{Note:} #1}\vspace{-\abovecaptionskip}}
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.

  \caption{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}
    foo & bar \\
    baz & qux \\
  %\caption*{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}
  \floatnote{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}

Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.



First: you can't say \renewcommand{\caption*}[1]{...} no matter what you put in as the replacement text. A *-variant is not a command by itself: when you say \caption, LaTeX peeks at what's coming next and decides whether to perform the normal action (\caption) or the variant (\caption*).

Second: even if you could, you may not define a command in terms of itself (without taking special precautions, and this is not the case).

If you say \renewcommand{\foo}{xyz \foo} then TeX, upon finding \foo will dutifully replace it with

xyz \foo

and so it would replace \foo with xyz \foo and … TeX will stop when its memory is exhausted.

The strategy of defining \floatnote is surely better.


This answer echoes egreg's and gives some more detail.

When using the LaTeX definitions \newcommand, \renewcommand and \providecommand, only letters are allowed in the definition of the control sequence. Sometimes you may use @, but this is only allowed after changing the category code from other (or 12) to letter (or 11); hence the call to \makeatletter. For a list of TeX's category codes, see What are category codes? You are allowed other non-letter character constructions, but then you have to use a different (more low-level) control sequence definition/construction.

The way one would (re)define a command that has a *-variant would be via "verbatim peeking" - this uses the TeX condition \@ifstar (see Commands defined with * options) - or by using constructs that support it, like those provided by xparse or suffix. Regardless, whether conditioning or using support techniques, you (re)define the unstarred version, and merely supply a *-variant.

Here's how you would go about redefining a command to have a *-variant using xparse:

\usepackage{xparse}% http://ctan.org/pkg/xparse
\RedefineDocumentCommand{\somecommand}{s ...}{
  % macro contents where #1 refers to *-variant (true) or not (false)
  \IfBooleanTF{#1}% Condition on *
    {}% TRUE: \somecommand*
    {}% FALSE: \somecommand

Here's how the interface with suffix is used:

\usepackage{suffix}% http://ctan.org/pkg/suffix
\newcommand\somecommand{...}% unstarred version
\WithSuffix\newcommand\somecommand*{...}% *-variant
  • Wish I could check two answers. This was very helpful. But I'll just stick with the simpler \floatnote method, mentioned above, and not go down this road. – lowndrul Feb 8 '12 at 18:38

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.