4

I'm using the memoir class and I define theorems with thmtools. Theorems often have a name, besides being numbered. I'm looking to write a \fullref command that outputs the name of the environment (here, Theorem) along with its given name, but without its number. (This command should work for any environment for which a name is defined, e.g., via \myenvautorefname.)

I used to use the following command, found here on TeX SE:

\newcommand{\fullref}[1]{\hyperref[#1]{\namecref{#1}\ \nameref*{#1}}}

Unfortunately, memoir and cleveref conflict with each other. So I'd like to make do without cleveref.

It seems that I should be able to achieve the same effect with autoref only. The command

\newcommand{\fullref}[1]{\hyperref[#1]{\autoref*{#1}\ \nameref*{#1}}}

almost does what I want, except that it displays the theorem number between Theorem and the theorem name.

Here's a MWE that illustrates the command above:

\documentclass{memoir}

\usepackage{amsthm,thmtools}
\usepackage{nameref}
\usepackage{hyperref}

\declaretheorem{theorem}
\renewcommand{\theoremautorefname}{Theorem}

\newcommand{\fullref}[1]{\hyperref[#1]{\autoref*{#1}\ \nameref*{#1}}}

\begin{document}
  \begin{theorem}[Whatever]
    \label{thm:whatever}
    Some witty theorem.
  \end{theorem}

  % The following outputs "Theorem 1 Whatever".
  % I would like "Theorem Whatever".
  Consider \fullref{thm:whatever}.
\end{document}

Thanks in advance!

  • 1
    What's the incompatibility exactly? If I add cleveref into your MWE and substitute your original definition of \fullref, it seems to do what I'd expect, I think. – cfr Dec 22 '14 at 0:38
  • 1
    Also, the documentation of cleveref says memoir is compatible. According to that, you just need to use a small workaround in the case of labels for sub-captions in the case of sub-figures. [Note, this is for the current version. An older version was apparently incompatible, according to the version history.] – cfr Dec 22 '14 at 0:44
3

Why not use cleveref?!

\documentclass{memoir}

\usepackage{amsthm,thmtools}
\usepackage{nameref}
\usepackage{hyperref}
\usepackage{cleveref}

\declaretheorem{theorem}
\renewcommand{\theoremautorefname}{Theorem}

\newcommand{\fullref}[1]{\hyperref[#1]{\namecref{#1}\ \nameref*{#1}}}

\begin{document}
  \begin{theorem}[Whatever]
    \label{thm:whatever}
    Some witty theorem.
  \end{theorem}

  % The following outputs "Theorem 1 Whatever".
  % I would like "Theorem Whatever".
  Consider \fullref{thm:whatever}.
\end{document}

<code>cleveref</code> with <code>memoir</code>

| improve this answer | |
2

The following uses zref as an alternative to cleveref to create a new property called envname (similar to what is provided by the zref-env module) which stores either \<env>autorefname or \@currenvir - the current environment name:

enter image description here

\documentclass{memoir}

\usepackage{amsthm,thmtools,zref}
\usepackage{hyperref}% Loads nameref

\makeatletter
\zref@newprop{envname}[??]{%
  \expandafter\ifx\csname\@currenvir autorefname\endcsname\relax
    \@currenvir
  \else
    \csname \@currenvir autorefname\endcsname
  \fi}%
\AtBeginDocument{
  \let\oldlabel\label
  \renewcommand{\label}[1]{\zref@labelbyprops{#1}{envname}\oldlabel{#1}}
}
\newcommand{\fullref}[1]{%
  \zref@refused{#1}% Mark label as used
  \hyperref[#1]{\zref@extract{#1}{envname}\ \nameref*{#1}}}
\makeatother


\declaretheorem{theorem}
\renewcommand{\theoremautorefname}{Theorem}

\begin{document}

\begin{theorem}[Whatever]
  \label{thm:whatever}
  Some witty theorem.
\end{theorem}

% The following outputs "Theorem Whatever".
Consider \fullref{thm:whatever}.
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.