I've been using the abbreviation macros for i.e., e.g., and etc. that are provided in this post. However, I just discovered that the etc. macro, and a similar one I made for et al. both cause errors when used inside a caption. When I compile the code below, I get an error Argument of \@caption has an extra }. Is there a way to modify the macro to fix this? Thanks.
\documentclass{article}
\usepackage{caption}
\usepackage{xspace}
\newcommand*{\eg}{e.g.\@\xspace}
\newcommand*{\ie}{i.e.\@\xspace}
\makeatletter
\newcommand*{\etc}{%
\@ifnextchar{.}%
{etc}%
{etc.\@\xspace}%
}
\makeatother
\begin{document}
\begin{figure}
\caption{Me \etc} % This causes problems
\label{}
\end{figure}
\end{document}