# Using memoir and hyperref, can I get a "\subref" in the caption of a figure?

I am writing a document using the memoir class. I would like to create a figure with two subfigures and to display a caption like "Plot of Y vs X with z=1 (a) and with z=2 (b)", where "(a)" and "(b)" are references to the subfigures.

I read How to reference subfigure in caption and Customize referencing of subcaptions in “memoir”?. The following example based on Werner's code solve my problem.

\documentclass{memoir}
\newsubfloat{figure}
\usepackage[demo]{graphicx}
\usepackage{xstring}
\usepackage{xspace}

\newcommand*{\subfigref}[1]{(\StrBetween{\ref{#1}}{(}{)})\xspace}%

\begin{document}

\begin{figure}[ht]
\centering
\subbottom[This is a subfigure\label{fig:label:b}]{\includegraphics{figure2}}
\caption{These are some awesome figures: \protect\subfigref{fig:label:a} and \protect\subfigref{fig:label:b} }
\label{fig:label1}
\end{figure}

\end{document}


How can I make the previous example work with hyperref ? In Customize referencing of subcaptions in “memoir”?, egreg seems to know how to do this but I do not understand enough his answer to use it for this particular problem.

EDIT

Note that I would also like to keep references such as "in Figure 0.1(a)" outside the figure.

You can redefine \p@subfigure which controls the prefix that will be added to the subfigure counter:

\documentclass{memoir}
\newsubfloat{figure}
\usepackage[demo]{graphicx}
\usepackage{hyperref}

\makeatletter
\renewcommand\p@subfigure{}
\makeatother

\begin{document}

\begin{figure}[ht]
\centering

• Thank you for your help. Unfortunately, if I use \ref{fig:label:a} outside the figure, it will appear as "(a)" and I would like it like "0.1(a)". Using \begingroup changes nothing. I edited my question to make this point clearer. Mar 27, 2013 at 8:03
• @RaphaëlCoudret perhaps \subcaptionref could be helpful. C.f., tex.stackexchange.com/a/115093/37198 Oct 7, 2018 at 9:43