# \renewcommand with \caption*

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?

\documentclass{article}
\usepackage{booktabs}
\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=colon,tableposition=top,figureposition=bottom]{caption}
%\renewcommand{\caption*}[1]{\vspace{\abovecaptionskip}\caption*{\textbf{Note:} #1}\vspace{-\abovecaptionskip}}
\newcommand{\floatnote}[1]{\vspace{\abovecaptionskip}\caption*{\textbf{Note:} #1}\vspace{-\abovecaptionskip}}
\begin{document}
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.

\begin{table}[h]
\centering
\caption{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}
\begin{tabular}{ll}
\toprule
foo & bar \\
\midrule
baz & qux \\
\bottomrule
\end{tabular}
%\caption*{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}
\floatnote{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}
\end{table}

Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.
\end{document}


-

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.


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