Math & Scienceautoref and theorems

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
obco
Posts: 2
Joined: Sat Apr 11, 2009 10:34 pm

autoref and theorems

Post by obco »

The autoref command can't tell the difference between theorems and lemmas on the same counter. How do I get round this problem?

(1) Using the thm-autoref package, which is part of the thmtools package, still gives me a bunch of errors.

Code: Select all

\documentclass{article}

\usepackage{amsmath, amsthm}
\usepackage{thm-autoref}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}

\usepackage{hyperref}

\begin{document}

\begin{theorem}[My Theorem]\label{thm:mytheorem}
This is my theorem.
\end{theorem}

\begin{lemma}[My Lemma]\label{thm:mylemma}
This is my lemma.
\end{lemma}

My Theorem is autoreferenced by \autoref{thm:mytheorem}, and My Lemma by \autoref{thm:mylemma}.

\end{document}
(2) Using the cleveref package, the lemma is still referred to as a theorem.

Code: Select all

\documentclass{article}

\usepackage{amsmath, amsthm}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}

\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}

\begin{theorem}[My Theorem]\label{thm:mytheorem}
This is my theorem.
\end{theorem}

\begin{lemma}[My Lemma]\label{thm:mylemma}
This is my lemma.
\end{lemma}

My Theorem is autoreferenced by \cref{thm:mytheorem}, and My Lemma by \cref{thm:mylemma}.

\end{document}
Any help would be much appreciated.

Cheers.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

autoref and theorems

Post by gmedina »

Hi,

you could use the \crefname command provided by the cleveref package and the optional argument of the \label command, to get the desired result. Have a look at the following example:

Code: Select all

\documentclass{article}
\usepackage{cleveref}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\crefname{lemma}{lemma}{lemmas}

\begin{document}

\begin{theorem}[My Theorem]\label{thm:mytheorem}
  This is my theorem.
\end{theorem}

\begin{lemma}[My Lemma]\label[lemma]{thm:mylemma}
  This is my lemma.
\end{lemma}

My Theorem is autoreferenced by \cref{thm:mytheorem}, and My Lemma by \cref{thm:mylemma}.

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
obco
Posts: 2
Joined: Sat Apr 11, 2009 10:34 pm

Re: autoref and theorems

Post by obco »

Lol, so simple! thnx :)
Post Reply