![覆蓋自訂方程式環境的自動引用名稱](https://rvso.com/image/475708/%E8%A6%86%E8%93%8B%E8%87%AA%E8%A8%82%E6%96%B9%E7%A8%8B%E5%BC%8F%E7%92%B0%E5%A2%83%E7%9A%84%E8%87%AA%E5%8B%95%E5%BC%95%E7%94%A8%E5%90%8D%E7%A8%B1.png)
我無法根據使用自訂名稱的環境取得\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
),但重要的是,環境的內容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}