Closed mathjiajia closed 2 months ago
Looks about what I'd do for this case.
Could you elaborate what do you mean by "enable shared counters"? How do you expect zref-clever
to distinguish the same counter in different situations without telling it what to do?
When using cleaveref
, it can detect that: for a lemma it will use the correct type of”lemma” and correct counter, even shared with theorem, proposition…
I just expected zref-cleaver
to recognise the correct type of each label, such as section, lemma, remark …
As for the counter number, just follow the built in \ref command
Is that possible? Thanks for your help.
You mean that the first (mandatory) argument of \newtheorem
should be used to set the type instead of the second (optional) one (like in https://tex.stackexchange.com/a/19106), if I understand correctly. Yes, cleveref
does that, but it does so by redefining the internals of \newtheorem
(for the kernel, amsthm
and ntheorem
), but I have no intention of doing the same for zref-clever
. Indeed, it is a matter of policy of zref-clever
to be the least intrusive possible of other people's code.
The way to handle this case for zref-clever
is documented in the manual, and is the one you are already using. In my view, it is not silly at all, but rather an improvement: a little more document setup for a lot less headaches. The way to do it is simple enough, and there's no way I'll touch \newtheorem
for the sake of such a slight convenience.
If you find that that annoying, you could redefine things yourself, e.g.:
\documentclass{article}
\usepackage{amsthm}
\usepackage{zref-clever}
\NewDocumentCommand{\mynewtheorem}{momo}{%
\IfValueTF{#4}
{\newtheorem{#1}{#3}[#4]}
{%
\IfValueTF{#2}
{%
\AddToHook{env/#1/begin}{\zcsetup{countertype={#2=#1}}}%
\newtheorem{#1}[#2]{#3}%
}
{\newtheorem{#1}{#3}}%
}%
}
\theoremstyle{plain}
\mynewtheorem{theorem}{Theorem}[section]
\mynewtheorem{axiom}[theorem]{Axiom}
\mynewtheorem{conjecture}[theorem]{Conjecture}
\mynewtheorem{corollary}[theorem]{Corollary}
\mynewtheorem{hypothesis}[theorem]{Hypothesis}
\mynewtheorem{lemma}[theorem]{Lemma}
\mynewtheorem{proposition}[theorem]{Proposition}
\begin{document}
\section{Section 1}
\begin{theorem}\label{thm:test}
theorem
\end{theorem}
\begin{lemma}\label{lem:test}
lemma
\end{lemma}
\begin{corollary}\label{cor:test}
corollary
\end{corollary}
As shown in \zcref{thm:test,lem:test,cor:test}
\end{document}
I see. Thanks for your explanation.
Currently, I have to add the following, which looks silly:
Without the above part,
zcref
will treat everything astheorem