사용자 정의 방정식 환경에 대한 자동 참조 이름 재정의

사용자 정의 방정식 환경에 대한 자동 참조 이름 재정의

사용자 정의 이름을 사용하기 위해 환경을 기반으로 패키지 \autoref에서 사용자 정의 환경으로 참조를 가져올 수 없습니다 . 이러한 참조에서는 사용자 정의 이름을 사용하는 대신 "Equation"을 사용합니다.hyperrefequation

다음 예를 고려하십시오.

\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하므로 문제 가 됩니다.hyperrefsvjour3

답변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}

여기에 이미지 설명을 입력하세요

관련 정보