# How to get correct autoref for theorems

I have some own theorem environments. And my theorems are numbered like the chapter. Now I would like to use autoref with that. But it does not work like it is described here (http://www.tug.org/applications/hyperref/manual.html) with aliascnt. So how can I get that?

\documentclass[ngerman,halfparskip,12pt,pointednumbers]{scrreprt}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm,bbm}
\usepackage{hyperref}
\newtheoremstyle{absatz}
{17pt}{10pt}{}{-1pt}{\scshape\bfseries}{.}{\newline}{}

\theoremstyle{absatz}

\newtheorem{satz}{Satz}[chapter]
\newtheorem*{satz*}{Satz}
\newtheorem{lemma}[satz]{Lemma}
\newtheorem{corollar}[satz]{Korollar}

%\renewcommand*{\theoremautorefname}{Satz}
\begin{document}
\begin{satz}
\label{Satz}
text text theorem
\end{satz}

In \autoref{Satz} we have shown...
\end{document}

-
I tried this with the following example  \begin{satz} \todo{citation needed} \label{satz} theorem text \end{satz} In \autoref{satz} ... And of course this did not work, because of the \todo before the label. Just for anyone to remember, who stumbles upon this topic. (sorry I did not get a code environment working here.) – pirad Mar 1 '12 at 8:52

\autoref requires the name of the environment in the form \<name>autorefname to work. So, in order to properly "auto reference" your satz theorem, you should use

\newcommand{\satzautorefname}{Satz}


\documentclass[ngerman,halfparskip,12pt,pointednumbers]{scrreprt}
%\usepackage{babel}
%\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm,bbm}
\usepackage{hyperref}
\newtheoremstyle{absatz}
{17pt}{10pt}{}{-1pt}{\scshape\bfseries}{.}{\newline}{}

\theoremstyle{absatz}

\newtheorem{satz}{Satz}[chapter]
\newtheorem*{satz*}{Satz}
\newtheorem{lemma}[satz]{Lemma}
\newtheorem{corollar}[satz]{Korollar}
\newcommand{\satzautorefname}{Satz}

\begin{document}
\begin{satz}
\label{Satz}
text text theorem
\end{satz}

In \autoref{Satz} we have shown...
\end{document}  ​

-
Thanks that works. And with aliascnt it even works for Lemma and Korollar. – pirad Mar 1 '12 at 8:35

I like all of my theorems etc numbered in sync with equations. For this I use the following macro to create my theorem-like environments:

% Some trickery to make \NewTheorem{} define theorem like environments
% work correctly with \autoref{}
\usepackage{aliascnt}
\def\NewTheorem#1{%
\newaliascnt{#1}{equation}
\newtheorem{#1}[#1]{#1}
\aliascntresetthe{#1}
\expandafter\def\csname #1autorefname\endcsname{#1}
}


Then I define

\NewTheorem{Theorem}
\NewTheorem{Corollary}


etc and use \begin{Theorem}...\end{Theorem} etc in the text.

Note that the environment name (Theorem, Corollary etc) is the label that is used by \autoref.

-

Here a somewhat "less professional" method that I find quite usefull and easy:

Load the hyperref package and insert the following in your preamble

\newcommand{\sref}[2]{\hyperref[#2]{#1 \ref{#2}}}


Now you can refer to anything by typing \sref{<theorem_description>}{<label_name>}. It the <theorem_description> can be anything you want. I personally don't mind a solution like this because it requires almost no extra typing. Also it can be typed differenly in any situation, which I find quite usefull at the beginning of a sentence for instance.

Here's a MWE

\documentclass{article}
\usepackage{hyperref}
\newcommand{\sref}[2]{\hyperref[#2]{#1 \ref*{#2}}}
\newtheorem{satz}{Satz}[section]
\newtheorem{folge}[satz]{Folge}

\begin{document}
\section{YOLO}

\begin{satz}\label{label1} Ein schoener Satz.
\end{satz}

\begin{folge}\label{label2}Wegen \sref{satz}{label1} folgt....
\end{folge}
\sref{Folge}{label2} has a capital, since it is the beginning of a sentence.

\end{document}


Output:

-
Little downside would be the late decision to rename Satz to Keks, or rather Abbildung to Diagram (have seen this desire more often to rename something to Keks). You might find package cleveref interesting, tough. – Johannes_B Oct 3 '14 at 14:50