3

In my TeX file I have a something like this:

\newcommand{\head}[2]{
\textbf{#1 \imp:} \textit{#2}\\
}

\newcommand{\definition}[1]{
\head{Definition}{#1}
}

\newcommand{\lemma}[1]{
\head{Lemma}{#1}
}

As I write my lemmata and definitions it is hard to keep track of them. So I'd like to use labels. And then I'd love to write something like this

According to Lemma 3 we know that ....

Where Lemma 3 is filled in on the fly by nameref, so that I'd only have to write this

According to \nameref{lemma_cook} we know that .....

I tried to use labels and references but they only work within sections, figures and stuff that can be enumerated. Is there a way to adjust my new commands to make this possible (put them in an enumerable environment, use a virtual counter, use hyperref package, ...)?

  • 3
    Welcome to TeX.SX! You seem not to have heard about \newtheorem. – egreg Dec 15 '13 at 10:54
  • You're right. Never heard of that, but exactly what I was looking for. Thank you very much! – user42756 Dec 15 '13 at 12:01
3

Instead of doing things by hand, use the \newtheorem command; the amsthm package extends the command with the notion of “current style”:

\documentclass{article}
\usepackage{amsthm}

%\theoremstyle{plain} % implicit
\newtheorem{thm}{Theorem}[section] % theorems are numbered by section
\newtheorem{lem}[thm]{Lemma}       % lemmas share the numbering

\theoremstyle{definition} % body font is upright
\newtheorem{defn}[thm]{Definition} % definitions share the numbering

\newtheorem*{rem}{Remark} % unnumbered

\begin{document}

\section{Basics}

\begin{lem}\label{lem:easy}
$1+1=2$.
\end{lem}

\begin{thm}\label{thm:add}
$1+1+1=3$.
\end{thm}
\begin{proof}
The proof is easy when one recalls Lemma~\ref{lem:easy}.
\end{proof}

\begin{defn}
A natural number is \emph{nice} when it has good properties.
\end{defn}

\begin{thm}\label{thm:main}
Every natural number is nice.
\end{thm}
\begin{proof}
Easy induction, the inductive step is provided by Theorem~\ref{thm:add}.
\end{proof}

\begin{rem}
All of the above extends to real numbers, but this paper is too
short for showing the proof.
\end{rem}

\end{document}

enter image description here

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.