1

I have looked up many solutions to the problem of referencing a theorem, corollary, lemma, etc. in terms of their name. What I mean is that if the label of a theorem 1 is \label{T:theoremOne}, then when using the command \ref{T:theoremOne}, we get the name and the number of the theorem, that is Theorem 1.

I get the idea of how to get this result when the environments do not depend on a single counter, however I am stuck with a problem in the name when I use a single counter for all my theorems, corollaries, lemmas, propositions, definitions and all (I know, this seems to be silly, but it is a requirement for the final draft of my PhD thesis!). Here is a workable example to illustrate my problem.

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}

\newtheorem{theorem}{Theorem}
\labelformat{theorem}{Theorem~#1}
\newtheorem{corollary}[theorem]{Corollary}
\labelformat{corollary}{Corollary~#1}

\usepackage{graphicx}
\usepackage{lmodern}
\author{Pierre-Olivier Parisé}

\begin{document}
A working example. 

\begin{theorem}\label{T:theoremOne}
Here's a first theorem.
\end{theorem}

So, when we refer to \ref{T:theoremOne}, we get the following corollary.

\begin{corollary}\label{C:corollaryOne}
Here's a corollary of the first Theorem.
\end{corollary}
So now, we see that \ref{C:corollaryOne} is not named correctly...
\end{document}

If you try it, you will get the following output. As you can see, the corollary is printed as Theorem 2 instead of Corollary 2. I think that I know where's the problem. The corollary environment use the same counter as the theorem environment. So, when it prints the name of the counter, it takes the theorem counter's name instead of the corollary counter's name (there are the same in fact, as I understand). I also try to use an external counter for all the environments, but it didn't work as expected (it only prints the number since the counter has no name... and also I would have to select the good name of the environment to print it correctly, which is not obvious for me how to implement this).

Does anybody would have a solution to this problem? Please, if I missed any post on this issue, please refer me to it. I would really appreciate help for this issue. Thank you!

2
  • Off topic. amssymb loads amsfonts, so it's not necessary to load both. No harm done, but nothing gained. Commented Jul 14, 2021 at 23:44
  • Thank you for your comment barbara beeton!
    – popa13
    Commented Jul 16, 2021 at 1:31

2 Answers 2

1

Instead of messing yourself with the label format, you can let cleveref do the work for you:

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[capitalise]{cleveref}

\newtheorem{theorem}{Theorem}
%\labelformat{theorem}{Theorem~#1}
\newtheorem{corollary}[theorem]{Corollary}
%\labelformat{corollary}{Corollary~#1}

\usepackage{graphicx}
\usepackage{lmodern}
\author{Pierre-Olivier Parisé}



\begin{document}
A working example. 

\begin{theorem}\label{T:theoremOne}
Here's a first theorem.
\end{theorem}

So, when we refer to \cref{T:theoremOne}, we get the following corollary.

\begin{corollary}\label{C:corollaryOne}
Here's a corollary of the first Theorem.
\end{corollary}
So now, we see that \cref{C:corollaryOne} is not named correctly...
\end{document}

enter image description here

4
  • Yes I tried cleveref, however, since I have a document with multiple files, I have noticed that cleveref is not capable of handling the cross references between each different files.
    – popa13
    Commented Jun 15, 2021 at 14:56
  • Thank you by the way for your answer!
    – popa13
    Commented Jun 15, 2021 at 14:57
  • @popa13 -- It sounds odd that multiple files aren't handled properly. I assume you use \input to incorporate those files since article is the class, or might it be book and \include since this is a PhD dissertation? Could you add a small extra file and enlarge the example to tie the conditions down more clearly? (This might warrant a new question.) Commented Jul 14, 2021 at 23:54
  • Hi, I have changed my file to skip this technical problem (I have referred to numbers instead of the name of the environment and the number). However, I would like to try with cleverref next time. I will try to reproduce my problem with the book class. Actually, I am using the documentclass ulthese (you can find it on CTAN) and I used \include to include each file in the main document.
    – popa13
    Commented Jul 16, 2021 at 1:30
0

You should use cleveref, really. Anyway, you can do the job also without it.

\documentclass[12pt,a4paper]{article}
%\usepackage[english]{babel}

\usepackage{lmodern}

\usepackage{amsmath}
\usepackage{amsthm}
%\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage{graphicx}
\usepackage{aliascnt}

\newtheorem{theorem}{Theorem}
\labelformat{theorem}{Theorem~#1}

\newaliascnt{corollary}{theorem}
\newtheorem{corollary}[corollary]{Corollary}
\labelformat{corollary}{Corollary~#1}
\aliascntresetthe{corollary}

\author{Pierre-Olivier Parisé}

\begin{document}

A working example. 

\begin{theorem}\label{T:theoremOne}
Here's a first theorem.
\end{theorem}

So, when we refer to \ref{T:theoremOne}, we get the following corollary.

\begin{corollary}\label{C:corollaryOne}
Here's a corollary of the first Theorem.
\end{corollary}

So now, we see that \ref{C:corollaryOne} is not named correctly...

\end{document}

enter image description here

You must log in to answer this question.

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