2

I am using the xr and cleveref packages to reference figures in another document, using the same figure and table numbers as the other document, as shown here. However, for non-floating figures and tables, I can't use the \@captype used in \extref. Therefore, I'd like to get the cleveref type of a given reference. However, I have been unable to find a technique for this.

Here's a MWE without xr and the external document (because I don't think those complications are important for this question, unless there's no way to extract the cleveref type).

Updated MWE (showing more precisely the problem):

\documentclass{article}

\usepackage{graphicx} \usepackage{cleveref} \usepackage{caption}

\makeatletter \newcommand{\extref}[1]{% @namedef{the@captype}{\ref{#1}}% } \makeatother

\begin{document}

\begin{center} \includegraphics{example-image-a.jpg} \captionof{figure}{caption\label{fig:example}} \end{center}

\begin{center} \includegraphics{example-image-a.jpg} \extref{fig:example} \captionof{figure}{repeated} \end{center}

Here is a reference: \cref{fig:example}.

\end{document}

  • Updated MWE, now showing the use of \extref. I need to replace \@captype with something that extracts the cleveref type. – Rico Picone Aug 04 '23 at 22:57

1 Answers1

5

That's what \namecref is for:

\documentclass{article}

\usepackage{graphicx} \usepackage{cleveref}

\begin{document}

\begin{figure} \includegraphics{example-image-a.jpg} \caption{caption\label{fig:example}} \end{figure}

Here is a reference: \cref{fig:example}.

Now I want to know the label type: \namecref{fig:example}

\end{document}

enter image description here

Edit: Getting the type proper, instead of the type name, as requested in the comments:

\documentclass{article}

\usepackage{graphicx} \usepackage{cleveref}

\makeatletter \newcommand{\mycreftype}[1]{% \cref@gettype{#1}{@mytempvar}% @mytempvar} \makeatother

\begin{document}

\begin{figure} \includegraphics[width=\linewidth]{example-image-a.jpg} \caption{caption\label{fig:example}} \end{figure}

Here is a reference: \cref{fig:example}.

Now I want to know the label type: \mycreftype{fig:example}

\end{document}

enter image description here

gusbrs
  • 13,740
  • Thanks! I want the actual type and not the typeset version of the type. Is that what is returned? – Rico Picone Aug 04 '23 at 22:42
  • @RicoPicone Mhm, I don't know any public interface for that, and I'm not sure there is one. It's probably viable to create some wrapper command that does it, but that's more than I can go for right now. With zref-clever it would be trivial, since it is exposed as a property, but that's not what you asked. – gusbrs Aug 04 '23 at 22:48
  • 1
    I'll take a look at zref-clever and see if my document will work with it without major surgery. I'll also update my MWE to include more explicitly what I want. Thanks! – Rico Picone Aug 04 '23 at 22:50
  • 1
    @RicoPicone Your question is clear, and the MWE very good. It is just that, as far as I know, this would be a non-trivial query for cleveref. But the information definitely exists and can be retrieved somehow. If you do get your document working with zref-clever and like it, all you need to get the type is \zcref[ref=zc@type]{<label>}. – gusbrs Aug 04 '23 at 22:56
  • 1
    @RicoPicone Oops, that would actually be \zcref[ref=zc@type,noname]{<label>}, or using zref, \zref[zc@notype]{<label>} (shorter, but no hyperlink). – gusbrs Aug 04 '23 at 23:06
  • 1
    @RicoPicone I took a look now, and found an internal auxiliary function of cleveref for the purpose. See edit. – gusbrs Aug 05 '23 at 03:32