# svjour3 with envcountsame breaks autoref and cleveref

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}


\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}
$$\labelx{eq:test} 1+1=2$$

\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}


• 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! Dec 3, 2021 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 Dec 4, 2021 at 1:33

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}
$$\label[equation]{eq:test} 1+1=2$$

\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}


• Welcome to TeX.SE! Dec 2, 2021 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. Dec 3, 2021 at 19:35