제약 조건 작성을 위한 Cleveref 유형 참조

제약 조건 작성을 위한 Cleveref 유형 참조

\cref{eq15,eq16,eq17,eq18}생산합니다 Eqs. (15) to (18).

내가 쓰고 싶은 방정식 중 일부는 참조 위치와 참조 개수에 따라 Constraint/ constraint/ Constraints/ 로 작성됩니다. / constraints에서 발생하는 것과 유사하게 참조 수를 자동으로 감지하고 그에 따라 번호를 생성합니다. 또한 방정식을 변경하고 싶지 않습니다 .\cref\Cref\cref

가능한? 어떤 도움/아이디어가 있나요?

MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage[colorlinks,allcolors=red]{hyperref}
\usepackage{cleveref}

\begin{document}
\begin{equation}\label{eq1}
    a+b<2
\end{equation}
\begin{equation}\label{eq4}
    a+b<2
\end{equation}
\begin{equation}\label{eq3}
    a+b<2
\end{equation}
\begin{equation}\label{eq2}
    a+b<2
\end{equation}

\Cref{eq1} should display Equation and \cref{eq1} should display Eq. i.e., normal behaviour of cref. I don't want to change this.

Need some kind of newcommand/macro/package so that I can write constraints (2) to (4). 

%Ex:
%\newref{eq2} = constraint (4)
%\Newref{eq2} = Constraint (4)
%\newref{eq3,eq2,eq4} = constraints (2) to (4)
%\Newref{eq3,eq2,eq4} = Constraints (2) to (4)
%\newref{eq2,eq3} = constraints (3) and (4)
%\Newref{eq2,eq3} = constraints (3) and (4)

\end{document}

답변1

constraint카운터 에 대해 "별칭"을 정의하여 형식 지정 목적을 달성할 수 있습니다 equation. 환경 \label에 대한 지침 의 형식을 관찰하십시오 . , 여기서 는 입니다 . 선택적 인수를 사용하면 기본값이 아닌 다른 레이블 이름을 사용하게 됩니다.equation\label[constraint]{eq|x|}x{2,3,4}cleveref

cleveref의 "별칭" 기능 에 대한 자세한 내용은패키지 사용 설명서, "상호 참조 유형 재정의".

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

\documentclass{article}
\usepackage{amsmath}
\usepackage[colorlinks,allcolors=red]{hyperref}

\usepackage{cleveref}
\crefalias{constraint}{equation}
\crefname{constraint}{constraint}{constraints}
\Crefname{constraint}{Constraint}{Constraints}
\creflabelformat{constraint}{#2{\upshape(#1)}#3} 

\begin{document}
\begin{equation}\label{eq1} a+b=2 \end{equation}
\begin{equation}\label[constraint]{eq2} a+b<2 \end{equation}
\begin{equation}\label[constraint]{eq3} a+b>2 \end{equation}
\begin{equation}\label[constraint]{eq4} a+b\ne2 \end{equation}

\Cref{eq1}; \cref{eq1}.

\Cref{eq2,eq4,eq3}; \cref{eq2,eq4,eq3}.
\end{document}

답변2

\cref이 솔루션은 / \Cref를 사용하기 위한 새로운 명령 정의에 따라 달라집니다 .일시적인방정식을 상호 참조할 때 정의가 변경됩니다. 따라서 언제든지 방정식은 초기 레이블 정의 또는 추가 레이블(초기/원래 레이블을 제거하지 않고)에 의해 상호 참조될 수 있습니다. 두 라벨은 언제든지 순서에 관계없이 동일한 방정식에 사용될 수 있습니다.

예를 들어 새 명령은 \ccref다음과 같이 정의 될 수 있습니다.

\newcommand*\ccref[1]{\crefname{equation}{constraint}{constraints}\Crefname{equation}{Constraint}{Constraints}\cref{#1}\crefname{equation}{eq.}{eqs.} \Crefname{equation}{Eq.}{Eqs.}}

마찬가지로 대문자를 정의하는 경우에도 마찬가지입니다.\CCref

다음은 두 개의 라벨을 사용하는 동안 가능한 모든 경우의 예입니다 eq./eqs./Eq./Eqs..constraint/constraints/Constraint/Constraints

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

전체 코드

\documentclass{article}
\usepackage{amsmath}
\usepackage[colorlinks,allcolors=red]{hyperref}
\usepackage{cleveref}
\crefname{equation}{eq.}{eqs.} % Initial definition of \cref
\Crefname{equation}{Eq.}{Eqs.} % Initial definition of \Cref
%
\newcommand*\ccref[1]{\crefname{equation}{constraint}{constraints}\Crefname{equation}{Constraint}{Constraints}\cref{#1}\crefname{equation}{eq.}{eqs.} \Crefname{equation}{Eq.}{Eqs.}}
\newcommand*\CCref[1]{\crefname{equation}{constraint}{constraints}\Crefname{equation}{Constraint}{Constraints}\Cref{#1}\crefname{equation}{eq.}{eqs.} \Crefname{equation}{Eq.}{Eqs.}}
%
\begin{document}
%
\section{Equations}
    \begin{equation}\label{eq1}
        a+b<2
    \end{equation}
    \begin{equation}\label{eq2}
        a+b<2
    \end{equation}
    \begin{equation}\label{eq3}
        a+b<2
    \end{equation}
    \begin{equation}\label{eq4}
        a+b<2
    \end{equation}

\section{Test single equation}
    \begin{tabular}{l l }
        Command & Output \\
        \hline
    \verb|\cref{eq1}| &  \cref{eq1} \\
    \verb|\Cref{eq1}| &  \Cref{eq1} \\
    \verb|\ccref{eq1}| & \ccref{eq1} \\
    \verb|\CCref{eq1}| &  \CCref{eq1}  \\
    \end{tabular}

\section{Test many equation}

\begin{tabular}{l l }
    Command & Output \\
    \hline
    \verb|\cref{eq1,eq2}| &  \cref{eq1,eq2} \\
    \verb|\Cref{eq1,eq2}| &  \Cref{eq1,eq2} \\
    \verb|\Cref{eq1,eq2,eq4}| &  \Cref{eq1,eq2,eq4} \\
    \verb|\ccref{eq1,eq2}| & \ccref{eq1,eq2} \\
    \verb|\CCref{eq1,eq2}| &  \CCref{eq1,eq2}  \\
    \verb|\CCref{eq1,eq2,eq4}| &  \CCref{eq1,eq2,eq4}  \\
\end{tabular}

\section{Test range of equations}
    \begin{tabular}{l l }
    Command & Output \\
    \hline
    \verb|\cref{eq1,eq2,eq3,eq4}| &  \cref{eq1,eq2,eq3,eq4} \\
    \verb|\Cref{eq1,eq2,eq3,eq4}| &  \Cref{eq1,eq2,eq3,eq4} \\
    \verb|\ccref{eq1,eq2,eq3,eq4}| & \ccref{eq1,eq2,eq3,eq4} \\
    \verb|\CCref{eq1,eq2,eq3,eq4}| &  \CCref{eq1,eq2,eq3,eq4}  \\
\end{tabular}
\end{document}

관련 정보