7

I want to be able to print the names of my own theorems with autoref. E.g. on

\begin{lemma}
\label{lemma_foo}
  Some lemma
\end{lemma}

\autoref{lemma_foo}

I want something like "Lemma 3.2" being printed.

My current approach is:

\newtheorem{lemma}{Lemma}[chapter]
\newcommand{\lemmaautorefname}{Lemma}

\newtheorem{definition}[lemma]{Definition}
\newcommand{\definitionautorefname}{Definition}

Definition shares the counter with lemma, which is intended, however it has the side effect, that referencing definitions results in them being called lemmas.

How do I fix this?

5
  • 1
    Welcome to TeX.SX! The cleveref package does better in these cases.
    – egreg
    Apr 27, 2015 at 22:25
  • I still do have the exact same problem. Setting the \crefname{definition} does nothing, whereas \crefname{lemma} changes it for both lemmas and definitions. I belive this is, because the way I defined "definition" it is treated as a subset of lemma. But I need this for the correct numbering. Apr 27, 2015 at 22:44
  • Do you perform the definitions of the lemma and definition environments before or after loading hyperref and cleveref?
    – Mico
    Apr 27, 2015 at 22:46
  • \usepackage{cleveref} comes first. Apr 27, 2015 at 22:50
  • The cleveref package provides labels for environments named lemma and definition. It shouldn't be necessary to execute \crefname directives for them.
    – Mico
    Apr 27, 2015 at 22:58

2 Answers 2

6

As long as the lemma and definition environments are defined after the hyperref and cleveref packages are loaded, using \cref in lieu of \autoref should give you what you want.

enter image description here

\documentclass{report} % or 'book'?
\usepackage{ntheorem}  % or 'amsthm'?
\usepackage[colorlinks]{hyperref}
\usepackage[capitalize,nameinlink,noabbrev]{cleveref} % to emulate \autoref style

\newtheorem{lemma}{Lemma}[chapter]
\newcommand{\lemmaautorefname}{Lemma}
\newtheorem{definition}[lemma]{Definition}
\newcommand{\definitionautorefname}{Definition}

\setcounter{chapter}{1} % just for this example

\begin{document}
\begin{lemma}
\label{lemma_foo}
  Some lemma
\end{lemma}
\autoref{lemma_foo}  (correct) and \cref{lemma_foo} (correct) \dots

\begin{definition}
\label{definition_bar}
  A definition
\end{definition}
\autoref{definition_bar} (incorrect) and \cref{definition_bar} (correct) \dots

\end{document}
4
  • Well not exactly, but your working example got me on the right track. It was including \usepackage{ntheorem} that did the trick. Thanks Apr 27, 2015 at 23:28
  • @user2089648 - What do you mean by "not exactly"? Loading ntheorem will not make \autoref produce the expected output, or will it?
    – Mico
    Apr 28, 2015 at 0:05
  • Yes, that is exactly what I mean. Try commenting it out in the example provided and it will just call everything a lemma. Apr 28, 2015 at 0:18
  • @user2089648 - I suppose we're talking about different things. I was focusing on whether \autoref can be made to generate the correct output if ntheorem is loaded.
    – Mico
    Apr 28, 2015 at 0:27
1

I managed to get this to work with \autoref, but it will only allow the counters to count for each type. So you would have Definition 1.1 then Definition 1.2 and if you add a lemma after that Lemma 1.1. It might be acceptable.

\newtheorem{lemma}{Lemma}[section]
\newtheorem{definition}{Definition}[section]

\newcommand{\lemmaautorefname}{Lemma}
\newcommand{\definitionautorefname}{Definition}
0

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.