1

The following LaTeX document is saved in a file whose path is ~/test.tex.

\documentclass{article}

\usepackage{amsthm}
\newtheorem{definition}{Definition}
\newtheorem{theorem}[definition]{Theorem}

\usepackage{cleveref}

\begin{document}
\begin{definition}\label{d}
This is a definition.
\end{definition}

\begin{theorem}\label{t}
This is a theorem.
\end{theorem}

Here is a reference to~\cref{t}.
\end{document}

When the following commands are executed at the terminal:

> cd ~
> pdflatex test
> pdflatex test

a PDF file is generated at the path ~/test.pdf. When opened in a PDF viewer, the file displays as follows:

The reference to the theorem displays as a reference to a definition.

Notice that the reference to the theorem is displayed as a reference to a definition.

How can I get \cref to distinguish between the theorem and the definition, while maintaining a continuous, unified numbering schema for theorems definitions?

1
  • 1
    For this MWE to work properly, all you need to do is load the cleveref package before the \newtheorem directives are executed.
    – Mico
    Nov 30, 2022 at 23:14

1 Answer 1

2

This works:

\documentclass{article}

\usepackage{thmtools}

\declaretheorem[name=Definition]{definition}
\declaretheorem[name=Theorem, numberlike=definition]{theorem}
\usepackage{cleveref}
\crefname{theorem}{Theorem}{Theorems}
\crefname{definition}{Definition}{Definitions}

\begin{document}

\begin{definition}\label{d}
This is a definition.
\end{definition}

\begin{theorem}\label{t}
This is a theorem.
\end{theorem}

Here is a reference to~\cref{t} based upon \cref{d}.

\end{document}
5
  • Thank you. The two \crefname lines are redundant. Would you please delete them so your code be minimal, for future reference?
    – Evan Aad
    Nov 14, 2022 at 21:45
  • 1
    @EvanAad: The two \crefname lines are not redundant, since they cause the references to appear with capitalized T and D; without them, those initial letters would be lower-case.
    – murray
    Nov 15, 2022 at 2:12
  • 1
    According to the cleveref manual, if you prefer to capitalize all cross-reference names, you can pass the capitalize option to the cleveref package. However, this preference is irrelevant to my original question, and therefore its implementation in your answer, by whatever means, is redundant.
    – Evan Aad
    Nov 15, 2022 at 4:33
  • It's much better to declare the theorems after loading the packages.
    – egreg
    Dec 1, 2022 at 0:11
  • @egreg: because ??
    – murray
    Dec 2, 2022 at 2:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .