4

I am trying to typeset definitions to reference in my problems throughout the work. Here is what I have so far:

\begin{enumerate} %hint

\item \theoremstyle{definition} \newtheorem{defn}{\textbf{Definition 2.2.1}}\label{2.2.1} \textit{Let S be a set. A subset R of S x S is called an \textbf{equivalence relation} on S if \begin{enumerate} \item for all $a \in S, (a,a) \in R;$ \item for all $a,b \in S, $if $(a,b) \in R,$ then $(b,a) \in R;$ \item for all $a,b,c \in S, $if $(a,b) \in R,$ and $(b,c) \in R,$ then $(a,c) \in R. $ \end{enumerate} \textit{We will write $a \sim b$ to denote the fact that $(a,b) \in R.$}} \end{enumerate}

This is what my code generates so far:

enter image description here

The problematic code is here :

\begin{enumerate}

\item Let $x,x \in \mathbb{Z}$ such that $ x | x^k$ and $x|x^j$, then $x\sim x$ and the equivalence relation is reflexive as described by \ref{2.2.1}.\

\end{enumerate}

which generates :

enter image description here

The part that I would like to change is \ref{2.2.1}. In my code it generates a singular number, but I would like the code to say:

... the equivalence relation is reflexive as described by Definition 2.2.1.

Any help would be greatly appreciated.

user257313
  • 41
  • 2
  • Welcome to TEX.SE! Could you please show us a minimal working example? And please explain what you want clearly – Syvshc Nov 23 '21 at 04:58
  • I completely agree with Mico's answer (+1), and I think I see that you were expecting \ref{2.2.1} to magically become Definition 2.2.1. But then I don't understand why you're using \ref in the first place. The point of \ref is to allow Mico's answer to happen. If you're not doing that, then why bother, and not just type "as describe by Definition 2.2.1"? (Which would not let you learn from Mico, but you didn't know that you needed to learn that when you were using \ref.) – Teepeemm Nov 23 '21 at 19:16

2 Answers2

4

I would like to encourage you to learn how to make use of LaTeX's approach -- its "way of thinking", if you prefer -- to separating content matters from formatting issues. While it involves a little bit more overhead at first, doing so immediately has huge payoffs in terms of getting access to all kinds of LaTeX packages that provide macros which perform all kinds of specific actions -- such as including the string label of an object that you wish to cross-reference. In other words, don't re-invent the wheel when a perfectly good one exists...

For instance, do learn how to use the machinery of the amsthm package to define and use theorem-like environments, including the "Definition" environment. If you do so, then creating a labeled cross-reference to a given definition is as trivially simple as replacing \ref{defn:eq_rel} with \cref{defn:eq_rel}, where \cref is a macro provided by the cleveref package.

By separating content matters from formatting issues, your code will quickly become more robust and more adaptable. For instance, if you decide that the definition of equivalence relations needs to be moved elsewhere in the document, not only will LaTeX automatically handle the change in the numbering of the definition, but any cross-references to that definition will also get adapted automatically.

enter image description here

\documentclass{report} % or some other suitable document class
\usepackage{enumitem}  % more control over appearance of lists
\usepackage{amssymb}   % for '\mathbb' macro
\usepackage{amsthm}    % for '\newtheorem' macro
\usepackage[capitalize]{cleveref} % for '\cref' macro
\newtheorem{defn}{Definition}[section] % run this instruction *after* loading 'cleveref'.

\newcommand\boldemph[1]{\textup{\textbf{#1}}} % utility macro

\begin{document} \setcounter{chapter}{2} % just for this example \setcounter{section}{2}

\begin{defn} \label{defn:eq_rel} % use a descriptive label Let $S$ be a set. A subset $R$ of $S \times S$ is called an \boldemph{equivalence relation} on $S$ if \begin{enumerate}[label=\upshape(\alph*)] \item for all $a \in S$, $(a,a) \in R$; \item for all $a,b \in S$, if $(a,b) \in R$, then $(b,a) \in R$; \item for all $a,b,c \in S$, if $(a,b) \in R$ and $(b,c) \in R$, then $(a,c) \in R$. \end{enumerate} We will write $a \sim b$ to denote the fact that $(a,b) \in R$. \end{defn}

\medskip\noindent \dots

\bigskip Let $x$, $x\in\mathbb{Z}$, such that $x\mid x^k$ and $x\mid x^j$. Then $x\sim x$, and the equivalence relation is reflexive as described by \cref{defn:eq_rel}.

\end{document}

Mico
  • 506,678
1

\@currentlabel holds the text (usually a number) of the current \label. You can forcefully set \@currentlabel to be whatever* you want just before calling \label if you want to capture something different:

enter image description here

\documentclass{article}

\usepackage{amssymb}

\makeatletter \newcommand{\setref}[1]{\def@currentlabel{#1}} \makeatother

\newcommand{\newdefinition}[1]{% \textbf{#1}% Set definition \setref{#1}% Set label }

\begin{document}

\begin{enumerate} \item \begingroup \newdefinition{Definition 2.2.1}\label{def-2.2.1} \itshape Let~$S$ be a set. A subset~$R$ of $S \times S$ is called an \textbf{equivalence relation} on~$S$ if \begin{enumerate} \item for all $a \in S, (a, a) \in R$; \item for all $a, b \in S$, if $(a, b) \in R$, then $(b, a) \in R$; \item for all $a, b, c \in S$, if $(a, b) \in R$, and $(b, c) \in R$, then $(a, c) \in R$. \end{enumerate} We will write $a \sim b$ to denote the fact that $(a, b) \in R$. \endgroup \end{enumerate}

\begin{enumerate} \item Let $x, x \in \mathbb{Z}$ such that $x \mid x^k$ and $x \mid x^j$, then $x \sim x$ and the equivalence relation is reflexive as described by \ref{def-2.2.1}. \end{enumerate}

\end{document}

* Note that the contents of \@currentlabel is written to the .aux, so will be expanded.

Werner
  • 603,163