¿Hay alguna manera de hacer que Cleveref distinga dos entornos con el mismo contador?

¿Hay alguna manera de hacer que Cleveref distinga dos entornos con el mismo contador?

Creo que normalmente le dices explícitamente a Cleveref cómo llamar a tu etiqueta \crefname{type}{singular}{plural}; sin embargo, esto no funciona, ya que aquí "tipo" tiene que ser el nombre del contador (creo). También intenté usarlo \label[type]{label}sin éxito. ¿Hay alguna manera de lograr que dos entornos compartan un mostrador, pero que los inteligentes puedan distinguir entre ellos? (¿O tal vez hay alguna manera de usar dos contadores, pero que siempre sean iguales/dependientes para lograr el mismo efecto?)

A continuación se muestra un ejemplo:

\documentclass{article}
\usepackage[colorlinks, linkcolor=blue]{hyperref} 
\usepackage[noabbrev, capitalise]{cleveref}
\usepackage{tikz}

%new theorem environment
\newcounter{theo}[section]\setcounter{theo}{0}
\renewcommand{\thetheo}{\arabic{section}.\arabic{theo}}
\newenvironment{theo}{%
\refstepcounter{theo}%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut \textbf{Theorem~\thetheo.}};
\newline
}

\crefname{theo}{Theorem}{Theorems}

%new lemma environment
\newenvironment{lem}{%
\refstepcounter{theo}
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=blue!20]
{\strut \textbf{Lemma~\thetheo.}};
\newline
}

\begin{document}
\begin{theo}\label{thrm}
Just some text.
\end{theo}

\begin{lem}\label{lm1}
Just some more text.
\end{lem}

\begin{lem}\label[Lemma]{lm2}
Just some more text.
\end{lem}

\noindent
\cref{thrm}\\ %give Theorem 0.1
\cref{lm1}\\ %give Lemma 0.2
\cref{lm2}\\ %give Lemma 0.3
\end{document}

Al final del ejemplo utilizo \cref tres veces. En un comentario muestro el resultado deseado. Aquí solía \crefname{theo}{Theorem}{Theorems}darle al entorno "theo" el nombre correcto, como puede ver, el entorno "lem" recibe el mismo nombre cuando se hace referencia a él. La segunda vez que uso el entorno "lem", lo etiqueto usando \label[Lemma]{lm2}, lo que resulta no tener el efecto deseado.

(Nota: el código que usa tikz no es relevante; lo agregué como una pequeña justificación para no usar el comando \newtheorem en su lugar).

Respuesta1

Puedes asignar a lem y theo al mismo registro de conteo (con cuidado :-)

ingrese la descripción de la imagen aquí

\documentclass{article}
\usepackage[colorlinks, linkcolor=blue]{hyperref} 
\usepackage[noabbrev, capitalise]{cleveref}
\usepackage{tikz}

%new theorem environment
\newcounter{theo}[section]\setcounter{theo}{0}
\renewcommand{\thetheo}{\arabic{section}.\arabic{theo}}
\newenvironment{theo}{%
\refstepcounter{theo}%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut \textbf{Theorem~\thetheo.}};
\newline%BADNESS 10000!!!!!
}

\makeatletter
\let\c@lem\c@theo
%now def not \let so it picks up current value
\def\p@lem{\p@theo}
\def\thelem{\thetheo}
\makeatother
\crefname{theo}{Theorem}{Theorems}
\crefname{lem}{Lemma}{Lemmas}

%new lemma environment
\newenvironment{lem}{%
\refstepcounter{lem}%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=blue!20]
{\strut \textbf{Lemma~\thetheo.}};
\newline%BADNESS 10000!!!!!
}

\begin{document}
\begin{theo}\label{thrm}
Just some text.
\end{theo}

\begin{lem}\label{lm1}
Just some more text.
\end{lem}

\begin{lem}\label{lm2}
Just some more text.
\end{lem}

\noindent
\cref{thrm}\\ %give Theorem 0.1
\cref{lm1}\\ %give Lemma 0.2
\cref{lm2}\\ %give Lemma 0.3
\end{document}

Respuesta2

No es necesario realizar contorsiones de programación: simplemente cargue el paquete amsthmo antes de y y luego defina los entornos similares a teoremas de la forma habitual. En particular, está perfectamente bien que varios entornos similares a teoremas compartan el mismo contador ( en el siguiente código):ntheoremhyperrefclevereftheo

ingrese la descripción de la imagen aquí

\documentclass{article}

\usepackage{amsthm} %or: \usepackage{ntheorem}
\usepackage[colorlinks, linkcolor=blue]{hyperref} 
\usepackage[noabbrev, capitalise]{cleveref}

% two new theorem-like environments
\newtheorem{theo}{Theorem}[section] % subordinate 'theo' cntr to 'section' cntr
\newtheorem{lem}[theo]{Lemma} % make 'lem' and 'theo' share same cntr

\crefname{theo}{Theorem}{Theorems}
\crefname{lem}{Lemma}{Lemmas}

\begin{document}
\setcounter{section}{2} % just for this example

\begin{theo}\label{thrm}Just some text.\end{theo}
\begin{lem}\label{lm1}Just some more text.\end{lem}
\begin{lem}\label{lm2}Still more text.\end{lem}

\cref{thrm} \dots

\cref{lm1,lm2} \dots
\end{document}

información relacionada