If I understand the question correctly, you have some auto-generated LaTeX code which uses \caption{...\label{...}...}
and you would like to change the caption text while preserving the label. This MWE would show the problem:
\documentclass{article}
\begin{document}
\let\oldcaption\caption
\renewcommand{\caption}[1]{\oldcaption{Regression table}}
% This table represents the auto-generated code
\begin{table}
\centering
\caption{A table\label{A}}
\end{table}
\ref{A} % does not work since the caption text and label was replaced
\end{document}
One possible solution would be using the helper macro \caption@getlabel
offered by the caption
package which tries to extract the \label
from it's argument:
\documentclass{article}
\usepackage{caption3}
\begin{document}
\makeatletter
\let\oldcaption\caption
\renewcommand{\caption}[1]{%
\oldcaption{Regression table}%
\caption@getlabel#1\label{}\@nil
\caption@thelabel
}
\makeatother
\begin{table}
\centering
\caption{A table\label{A}}
\end{table}
\ref{A}
\end{document}
Note that only caption3
is loaded (and not caption
) since this package only provides helper macros and no re-definition of existing ones, so it should be compatible with all document classes. (If you load the caption
package anyway you could drop \usepackage{caption3}
.)
Caveat: \caption@getlabel
is an internal macro, not documented in the user documentation of the caption
package. But I (as author and maintainer of the caption
package bundle) do not intend to change its interface in the future.