referência de tipo inteligente para escrever restrições (ões)

referência de tipo inteligente para escrever restrições (ões)

\cref{eq15,eq16,eq17,eq18}produz Eqs. (15) to (18).

Algumas das equações que quero escrever como Constraint/ constraint/ Constraints/ constraintsdependendo da posição de referência e do número de referência(s). Semelhante ao que acontece em \cref/ \Cref, ele detecta automaticamente o número de referências e produz o(s) número(s) de acordo. Além disso, não quero mudar \crefpara equações.

Possível? Alguma ajuda/ideia?

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}

Responder1

Você pode atingir seu objetivo de formatação definindo um "alias", chamado constraint, para o equationcontador. Observe a forma da \labelinstrução para equationambientes: \label[constraint]{eq|x|}, onde xestá em {2,3,4}. Usar um argumento opcional indica cleverefpara usar um nome de rótulo diferente do padrão.

Para obter mais informações sobre cleverefo recurso "alias" de, consulte a seção 6 doguia do usuário do pacote, "Substituindo o tipo de referência cruzada".

insira a descrição da imagem aqui

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

Responder2

Esta solução depende da definição de um novo comando para usar \cref/ \Crefthattemporáriomuda sua definição quando faz referência cruzada a uma equação. Para que a qualquer momento a equação possa ser cruzada pela definição do rótulo inicial ou por um rótulo adicional (sem remover o inicial/original). Ambos os rótulos podem ser usados ​​para a mesma equação com qualquer ordem e a qualquer momento.

O novo comando pode ser, por exemplo, \ccrefdefinido como segue

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

e da mesma forma para definir a maiúscula\CCref

Abaixo estão exemplos de todos os casos possíveis ao usar dois rótulos eq./eqs./Eq./Eqs.econstraint/constraints/Constraint/Constraints

insira a descrição da imagem aqui

O código completo

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

informação relacionada