% experimental package to make footnotes in captions less prone to
% doubling; it's probably not possible to avoid the problem completely
% without a complete redesign of the way captions are done, but this
% package will eliminate most instances, and will give a warning if it
% detects an apparent problem

\edef\CF@gobble@opt{\noexpand\protect
  \expandafter\noexpand\csname CF@gobble@opt \endcsname}
\expandafter\def\csname CF@gobble@opt \endcsname{
  \@ifnextchar[%]
    \CF@gobble@twobracket
    \@gobble
}
\def\CF@gobble@twobracket[#1]#2{}

\def\CF@measurebox{%
  \@tempdima\wd\@tempboxa
}

\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \begingroup
%
% first measure the width of the caption with footnotes suppressed
    \let\footnote\CF@gobble@opt
    \sbox\@tempboxa{#1: #2}%
    \expandafter\endgroup
  \ifdim \wd\@tempboxa>\hsize
%
% even without footnotes, it's already too wide -- typeset it without
% further ado
    #1: #2\par
  \else
%
% measure the caption text with footnotes
    \sbox\@tempboxa{#1: #2}%
    \ifdim\wd\@tempboxa>\hsize
%
% if it's now too wide, the caption was teetering on the edge, and
% there's nothing we can do: warn the user
      \PackageWarning{captfnt}{Text of footnote in caption may be doubled}%
      #1: #2\par
    \else
%
% everything's fine: it really is going to fit on one line
      \global \@minipagefalse
      \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
    \fi
  \fi
  \vskip\belowcaptionskip
}
