我无法根据环境使用自定义名称来获取\autoref
从hyperref
包中对自定义环境的引用equation
。此类引用不使用自定义名称,而是使用“方程式”。
请考虑以下示例:
\documentclass{article}
\usepackage{hyperref}
% Define a 'query' counter and environment, based on 'equation'
\newcounter{query}
\newenvironment{query}
{\refstepcounter{query}%
\renewcommand\theequation{Q\arabic{query}}\equation}
{\endequation}
% Attempt to override the name autoref uses for the query environment
\newcommand{\queryautorefname}{Query}
\begin{document}
A labelled instance of the query environment can be found below:
%
\begin{query}
\label{q:my_query}
Q(x) = ...
\end{query}
A reference to \autoref{q:my_query} using \texttt{autoref} uses the wrong name to refer to the environment (i.e., Equation rather than Query).
\end{document}
这个问题(如示例中所述)是,以这种方式进行的引用将显示为“Equation Q1”,而我希望它显示为“Query Q1”。我可以进行哪些更改才能实现此目的?
我愿意接受不同的策略来实现这一点(例如,对环境的不同定义query
),但重要的是将query
环境的内容设置为数学模式,并且环境的计数器独立于其他计数器(例如计数器equation
)。在这种情况下,使用cleveref
而不是hyperref
是有问题的,因为它给我带来了麻烦,svjour3
因为我必须使用模板/文档类。
答案1
\documentclass{article}
\usepackage{hyperref}
% Define a 'query' counter and environment, based on 'equation'
\newcounter{query}
\makeatletter
\newenvironment{query}
{\stepcounter{query}%
\def\Hy@chapterstring{equation}%
\def\Hy@chapapp{query}%
\renewcommand\theequation{Q\arabic{query}}\equation}
{\endequation}
\makeatother
% Attempt to override the name autoref uses for the query environment
\newcommand{\queryautorefname}{Query}
\begin{document}
A labelled instance of the query environment can be found below:
%
\begin{query}
\label{q:my_query}
Q(x) = ...
\end{query}
A reference to \autoref{q:my_query} using \texttt{autoref} uses the wrong name to refer to the environment (i.e., Equation rather than Query).
\end{document}