Someone please help me! I have some custom environments and I want to label them according to theorem counter. Means, that I get a numbering like Def. 1.1, Thm. 1.2 and so on. Right now, I have to enter the numbers for the labels myself and with growing content of my document, this gets messy really quick.

My goal is a modified environment for definition and theorem such that it automatically includes a label with the name of the current environment (definition, theorem, …) the chapter number and the theorem counter. See my example below.

Does anyone have an idea on how to accomplish this or even a code snippet with an implementation? I am very grateful for any help. :)

Best regards, Joe

\chapter{A first chapter}
Some first definition.
Some theorem.
Definition~\ref{defi:1.1} is important for Theorem~\ref{theo:1.2}!
  • My suggestion: don't label anything automatically, because that literally destroys the whole meaning of LaTeX labels. – user156344 Apr 12 at 16:58
  • 1
    What's the use of \label{defi:\thetheorem} when you don't know what number will be assigned? The label should be a mnemonic string that you associate to the theorem for adding cross references independently of the number that gets assigned to the theorem. – egreg Apr 12 at 17:22
  • \label is a command for creating data-structures via the .aux-file for cross referencing. How do you intend to do \ref{<name of label>} or \pageref{<name of label>} if you cannot be sure about <name of label> as it can change whenever you add/remove some theorems/definitions? – Ulrich Diez Apr 12 at 17:58

The purpose of \label is to introduce a mnemonic string for referring to some number, for example of a theorem.

Implementing what you'd like to do is very easy:


would do the trick and similarly for the theorem. But it would be completely useless, because you would have to refer to the statements by

Definition~\ref{defi:1.1} is important for Theorem~\ref{theo:1.2}!

anyhow and it's quite clear that

Definition~1.1 is important for Theorem~1.2!

is shorter and doesn't even need a two-pass system like \label-\ref.

Most importantly, are you sure that the numbering will stay? What if you realize that between the definition and the theorem a lemma should be stated? You will have to chase around the document for all cross-references involving 1.2 and all subsequent statements in the same section that will have their numbers changed because the numbers will all be wrong.

Compare with

\chapter{A first chapter}


Some first definition.

Some theorem.
Definition~\ref{defi:first} is important for Theorem~\ref{theo:some}!

This will typeset correct numbers even if you add the lemma in between, it just takes one more run of LaTeX if you are greeted by the warning

Label(s) may have changed. Rerun to get cross-references right.
  • In case of using the hyperref-package, one may wish to use the \label-\ref-mechanism as well for obtaining hyperlinks that link to the referenced items of sectioning. I agree that making the \label-\ref-mechanism working correctly being dependent on some numbering never being modified is not an approach that one would suggest lightheartedly. – Ulrich Diez Apr 13 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.