2

I'm using package amsthm to define a "Definition" environment as follows:

\theoremstyle{definition}
\newtheorem{definition}{Definition}

In brackets, a name for the definition is supplied:

\begin{definition}[Modularity]
For a graph $G = (V,E)$ and disjoint communities $\zeta = \{C_1, \dots, C_k \}$ of $G$, \term{modularity} is defined as
$$M(G, \zeta) := \underbrace{\sum_{C \in \zeta} \frac{|E(C)|}{|E|}}_{\text{coverage}} - \underbrace{\sum_{C \in \zeta}   \frac{ \left (  \sum_{v \in C} deg(v) \right )^2}{(2 \cdot |E|)^2}}_{\text{expected coverage}}$$
\end{definition}

Now, I'd like to label these definitions. Do I actually have to manually \label each one? Wouldn't it be nice and clean to be able to automatically generate a label from the supplied name argument?

lockstep
  • 250,273
clstaudt
  • 1,192
  • 2
  • 11
  • 27

1 Answers1

5

This is not difficult to achieve, just generate a new environment which starts/ends the amsthm definition and adds the label.

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{intdef}{Definition}
\newenvironment{definition}[1]{\begin{intdef}[#1]\label{def:#1}}{\end{intdef}}

\begin{document}

    This is the definition:

    \begin{definition}{Modularity}
        For a graph $G = (V,E)$ and disjoint communities $\zeta = \{C_1, \dots, C_k \}$ of $G$, modularity is defined as
        $$M(G, \zeta) := \underbrace{\sum_{C \in \zeta} \frac{|E(C)|}{|E|}}_{\text{coverage}} - \underbrace{\sum_{C \in \zeta}   \frac{ \left (  \sum_{v \in C} deg(v) \right )^2}{(2 \cdot |E|)^2}}_{\text{expected coverage}}$$
    \end{definition}

    See Definition~\ref{def:Modularity}. 
\end{document}

But beware of the downsides:

  • If you chose to change the title of the definition later, all references will be broken.
  • Most IDEs (at least TeXStudio) won't be able to autocomplete these reference names.
  • The names of the definitions will be restricted: you can't use macros and so on. E.g. it is not possible to create a $\chi$ Theorem
hbaderts
  • 3,920