3

When converting my manuscript to Springer's custom svjour3 document class using the option envcountsame (to use only one counter for all theorem-like environments), all references to propositions, lemmas, corollaries, etc. come out wrong, because autoref and cleveref think they are all theorems. See MWE below. Is there a way to use Springer's theorem environments but still be able to use autoref or cleveref? (Defining my own custom theorem environments with amsthm is not a desirable solution, as this deviates from the journal style.)

My usual solution is to load the package thmtools, as merely loading that package fixes this problem for theorem environments defined using amsthm, but that doesn't work for svjour3.

The same question was also asked by another user in a comment here.

MWE:

\documentclass[smallextended,envcountsame]{svjour3}
\usepackage{hyperref}
\newcounter{chapter} % do this before loading cleveref to fix a bug in svjour3; see https://tex.stackexchange.com/a/327686
\usepackage[capitalise]{cleveref}
\usepackage{thmtools} % fixes this problem for amsthm, but not for svjour3

\begin{document}

\begin{proposition}
    \label{prop:cow}
    The cow says: moo.
\end{proposition}

\begin{lemma}
    \label{lem:cat}
    The cat says: meow.
\end{lemma}

\begin{corollary}
    \label{cor:dog}
    The dog says: woof.
\end{corollary}

Autoref: \autoref{prop:cow}, \autoref{lem:cat}, \autoref{cor:dog}.

Cleveref: \cref{prop:cow}, \cref{lem:cat}, \cref{cor:dog}.

\end{document}

MWE

3

Add the following code to your preamble:

\makeatletter
\newcommand{\labelx}[1]{
    \relax
    \ifmmode
        \label{#1} 
    \else 
        \ifnum\pdfstrcmp{\@currenvir}{document}=0
            \label{#1}
        \else
            \label[\@currenvir]{#1}
        \fi
    \fi
}
\makeatother

Use \labelx instead of \label in your document. This piece of code works for me, but it's hard to say if it has any side effect.

Example

\documentclass[smallextended,envcountsame]{svjour3}
\usepackage{hyperref}
\newcounter{chapter} % do this before loading cleveref to fix a bug in svjour3; see https://tex.stackexchange.com/a/327686

\usepackage[capitalise]{cleveref}
\usepackage{thmtools} % fixes this problem for amsthm, but not for svjour3

%%%use \labelx instead of \label to make cleveref work with predefined theorem-like environments
\makeatletter
\newcommand{\labelx}[1]{
    \relax
    \ifmmode
        \label{#1} 
    \else 
        \ifnum\pdfstrcmp{\@currenvir}{document}=0
            \label{#1}
        \else
            \label[\@currenvir]{#1}
        \fi
    \fi
}
\makeatother

\begin{document}
\begin{equation}\labelx{eq:test}
    1+1=2
\end{equation}

\begin{proposition}
    \labelx{prop:cow}
    The cow says: moo.
\end{proposition}

\begin{lemma}
    \labelx{lem:cat}
    The cat says: meow.
\end{lemma}

\begin{corollary}
    \labelx{cor:dog}
    The dog says: woof.
\end{corollary}

Autoref: \autoref{prop:cow}, \autoref{lem:cat}, \autoref{cor:dog}.

Cleveref: \cref{prop:cow}, \cref{lem:cat}, \cref{cor:dog}. \cref{eq:test}

\end{document}

output

2
  • Based on Stefan's answer, I now understand what is going on here, and this seems like a perfectly fine workaround/solution. Personally, I would usually share a counter between equations and theorems, in which case this code might not work (because of the \ifmmode check, but also because there are many different environments capable of producing equation numbers). But you can always fall back on manual specification of the label (as in Stefan's answer), or define another macro \labeleq to use in equations. So your answers combined are more than sufficient. Thanks!
    – Josse
    Dec 3 '21 at 19:43
  • @Josse You are right. One can adjust the answer to fit his/her personal hobbits, and the \ifmmode check is not that perfect. By the way, one can hack the original \label command by using etoolbox. However, the editorialmanager system may not support it. :-P
    – Yijun Yuan
    Dec 4 '21 at 1:33
1

Section 6 of the cleveref manual suggests to override the cross-reference type by adding an optional argument to the \label command.

Example:

\documentclass[smallextended,envcountsame]{svjour3}
\usepackage{hyperref}
\newcounter{chapter} % do this before loading cleveref to fix a bug in svjour3; see https://tex.stackexchange.com/a/327686

\usepackage[capitalise]{cleveref}
\begin{document}
\begin{equation}\label[equation]{eq:test}
    1+1=2
\end{equation}

\begin{proposition}
\label[proposition]{prop:cow}
    The cow says: moo.
\end{proposition}

\begin{lemma}
     \label[lemma]{lem:cat}
    The cat says: meow.
\end{lemma}

\begin{corollary}
\label[corollary]{cor:dog}
    The dog says: woof.
\end{corollary}
Cleveref: \cref{prop:cow}, \cref{lem:cat}, \cref{cor:dog}. \cref{eq:test}

\end{document}

enter image description here

2
  • Welcome to TeX.SE!
    – Mensch
    Dec 2 '21 at 16:48
  • Thank you for your contribution, and thanks for the reference to the cleveref manual! It seems that this is essentially a non-automatic (i.e. manual) version Yijun Yuan's answer. Seeing as they answered first, I'm going to accept their answer.
    – Josse
    Dec 3 '21 at 19:35

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.