2

I labeled my lemma with \label{lem1} and referred to it later using \autoref{lem1}. However, what was printed was "Theorem 2.1" where it should really say "Lemma 2.1". How do I fix this?

\documentclass[a4paper, 12pt, twoside]{thesis}
\usepackage{verbatim} 
\usepackage{amssymb,amsmath}
\usepackage{amsthm,amsfonts,amscd,amsrefs}
\newtheoremstyle{component}{}{}{}{}{\itshape}{.}{.5em}{\thmnote{#3}#1}
    \theoremstyle{component}
    \newtheorem*{component}{}

\begin{document}
\begin{lemma} \label{lem1}
This is a lemma.
\end{lemma}

By \autoref{lem1}, we have..

\end{document}
jh4
  • 229
  • 2
  • 6
  • Looking into my chrystal ball of magic it says: Please provide a MWE ;-) –  Mar 19 '15 at 15:36
  • oh no sorry! New here I keep forgetting. Let me edit it in real quick. – jh4 Mar 19 '15 at 15:43
  • 1
    The Internet is chock-full of documentclass files named either Thesis.cls or thesis.cls. Where did you obtain your variant from? – Mico Mar 19 '15 at 15:47
  • from my senior in school. Here's the one I have: https://app.box.com/s/0zc51evopkdpulxgygqjuadocxyv97tw – jh4 Mar 19 '15 at 16:02

1 Answers1

2

The problem is not related to the .cls file and is well documented, see e.g. amsthm with shared counters messes up autoref references

You could use any of the two solutions proposed in that post, and I would recommend using cleveref as in the second one. To do that, just include

\usepackage{cleveref} 

in the .cls file, right after

\usepackage{...,amsthm,...}

Then use \Cref{lem1} (instead of autoref) in the document. The code would be:

\documentclass{article}
\usepackage{hyperref}
\usepackage{amsthm}
\usepackage{cleveref}
\newtheorem{theorem}{Theorem}
\newtheorem{lemm}[theorem]{Lemma}
\begin{document}

\begin{lemm}\label{lem1}
This is a lemma.
\end{lemm}

By \Cref{lem1}, we have.

\end{document}

If you didn't want to modify the .cls file, an easier but less robust solution is to define a newcommand \lref for lemmas (and then another command \dref for definitions, etc.) through

\newcommand\lref[1]{Lemma~\ref{#1}}

I say this is less robust because you can always make a mistake and use \lref to quote, let's say, a definition.

\documentclass{article}
\usepackage{hyperref}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\newtheorem{lemm}[theorem]{Lemma}
\newcommand\lref[1]{Lemma~\ref{#1}}
\begin{document}

\begin{lemm}\label{lem1}
This is a lemma.
\end{lemm}

By \lref{lem1}, we have.

\end{document}
summer
  • 1,474
  • thank you for this and the link to the other article. I tried adding \cleveref to Thesis.cls, but adding that caused \begin{definition}..\end{definition} environment to be unrecognisable by the compiler. – jh4 Mar 19 '15 at 18:14
  • Do the following in the .cls file: 1) Change cref to chref in \newcommand{\cref}[1]{Chapter~\ref{#1}}. 2) Move \usepackage{cleveref} and all the lines from \theoremstyle{plain} to \newtheorem{remark}[theorem]{Remark} right after \usepackage[...]{hyperref}. This should solve all your problems. – summer Mar 19 '15 at 18:32