カスタム方程式環境の autoref 名をオーバーライドする

カスタム方程式環境の autoref 名をオーバーライドする

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

この問題 (例で説明されているように) は、この方法で作成された参照が、本来は「クエリ Q1」と読みたいところ、「方程式 Q1」と読み取られてしまうことです。これを実現するには、何を変更すればよいでしょうか。

これを機能させるための別の戦略(たとえば、環境の別の定義)も検討していますが、環境の内容が数式モードに設定され、環境のカウンターが他のカウンター(カウンターなど)から独立していることがquery重要です。この場合、ではなくを使用すると問題が発生します。これは、使用しなければならないテンプレート/ドキュメント クラスとの組み合わせで問題が発生したためです。queryequationcleverefhyperrefsvjour3

答え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}

ここに画像の説明を入力してください

関連情報