1

This question already has an answer here:

Here's my problem: I'm writing some mathematics lecture notes. I needed some different theorem types, such as propositions, lemmas, plus observations, examples and definitions whose numbering depends on theorems. Plus, I'm Italian, and wanted custom output labels for those. So I declared them as follows (found that solution probably here on StackExchange, even if I can't find the question right now).

\theoremstyle{plain}
\newtheorem{thm}{Teorema}[chapter]

\theoremstyle{definition}
\newtheorem{defn}[thm]{Definizione}
\newtheorem{exmp}[thm]{Esempio}
\newtheorem{obs}[thm]{Osservazione}
\newtheorem{prop}[thm]{Proposizione}
\newtheorem{lemmy}[thm]{Lemma}

However, right now, I get some problems with their numbering when using both the hyperref and cleveref packages. I want to use those to refer to a Proposition or such made somewhere before, such that I can be automatically redirected to where it is written by clicking on it, but with the link label automatically presenting the theorem type (Lemma, Osservazione and such), and eventually changing automatically if I decide to rename Lemma to, say, Short Theorem. I made a short example:

\documentclass[twoside]{book}
\usepackage{amsthm}
\usepackage{cleveref}
\usepackage{hyperref} 

\usepackage{mathtools}

\theoremstyle{plain}
\newtheorem{thm}{Teorema}[chapter]

\theoremstyle{definition}
\newtheorem{lemma}[thm]{Lemma}

\begin{document}
\chapter{Chapter}
\begin{lemma}
\label{foo}Proposition here
\end{lemma}

As stated in \hyperref[foo]{ \cref*{foo}}

\end{document}

Even if I replace \cref with \ref here, not actually using cleveref, I get the error anyway, so it depends just on the packages declaration.

The error I get is the following:

! LaTeX Error: No counter 'l' defined

If I replace "lemma" with "observation" I get the same error with counter 'o', and so on. Practically, it sees the first letter of the name of the theorem type I have declared as the counter, or something similar. Has anyone got any clue on how to get rid of this conflict?

marked as duplicate by lockstep, Peter Jansson, Jesse, cmhughes, texenthusiast Jan 30 '14 at 17:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • cleveref is one of the few packages that must be loaded after hyperref. – jub0bs Jan 30 '14 at 16:04
  • Hell... that was quick. Thanks a lot for your answer, works like a charm! Feel kinda stupid because the problem was such a little thing though. Shows I'm a LaTeX newbie, the next time some strange, complex and articulated package incompatibility like this occurs, first thing I'm gonna do will be inverting their declaration order. Guess you need to slam your head on the wall personally to learn. Thanks a lot again! – Jeffrey Lebowski Jan 30 '14 at 16:04
  • Don't beat yourself up. The source of the error may not have been obvious to you because, in most cases, hyperref should be loaded last. And welcome to TeX.SX! – jub0bs Jan 30 '14 at 16:10