svjour3 与 envcountsame 中断 autoref 和 cleveref

svjour3 与 envcountsame 中断 autoref 和 cleveref

svjour3当使用选项(对所有定理类环境仅使用一个计数器)将我的手稿转换为 Springer 的自定义文档envcountsame类时,所有对命题、引理、推论等的引用都出错了,因为 autoref 和 cleveref 认为它们都是定理。请参阅下面的 MWE。有没有办法使用 Springer 的定理环境,但仍然能够使用 autoref 或 cleveref?(用 定义我自己的自定义定理环境不是amsthm一个理想的解决方案,因为这偏离了期刊风格。)

我的通常的解决方案是加载包thmtools,因为仅仅加载该包可以修复使用定义的定理环境的这个问题amsthm,但对于不起作用svjour3

另一位用户在评论中也提出了同样的问题这里

梅威瑟:

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

平均能量损失

答案1

将以下代码添加到你的序言中:

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

在文档中使用\labelx而不是\label。这段代码对我来说是有用的,但很难说它是否有任何副作用。

例子

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

输出

答案2

手册的第 6 节cleveref建议通过向命令添加可选参数来覆盖交叉引用类型\label

例子:

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

在此处输入图片描述

相关内容