Theses, Books, Title pages\label{} field in definitions

Classicthesis, Bachelor and Master thesis, PhD, Doctoral degree
Post Reply
pierre92
Posts: 13
Joined: Fri Jun 19, 2015 4:19 pm

\label{} field in definitions

Post by pierre92 »

Hi all,
I would like to add a \label{} field to my definitions in order to be able to refer to them and/or their page further on. Something along the line of

Code: Select all

\begin{definition}[Definition Foo]\index{Definitions!According to Foo}
Foo defines it as ...
\label{def:foo}
\end{definition}

\begin{definition}[Definition Bar]\index{Definitions!Foo}
Bar defines it as ...
\label{def:bar}
\end{definition}

According to Foo (see. Def.\ref{def:foo}) it is rather than that, on the contrary to Bar's definition (cf. \pageref{def:bar}).
However, after running pdflatex main I get a warning : LaTeX Warning: Reference `def:foo` on page 26 undefined on input line 409.
I tried putting it after

Code: Select all

\begin{definition}\label{def:foo}
, but I get the same result.
Any idea how I can achieve this for definitions, theorem and so on ?

Thanks and great forum on a great template!

Recommended reading 2024:

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

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

User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: \label{} field in definitions

Post by Johannes_B »

Welcome, which of the templates are you using?
Did you run LaTeX multiple times? Did you check the spelling?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
pierre92
Posts: 13
Joined: Fri Jun 19, 2015 4:19 pm

\label{} field in definitions

Post by pierre92 »

Thanks a lot for the quick response.

> Welcome, which of the templates are you using?

Sorry about that, it is indeed pretty important: I am using the legrange-orange-book

> Did you run LaTeX multiple times? Did you check the spelling?

I indeed ran pdfLaTeX multiple times and copied/pasted the "def:foo" part in order to avoid spelling mistakes. I have no problem referencing sections, equations, tables and figures, only the new "theorems" described in the "structure.tex" file by :

Code: Select all

%----------------------------------------------------------------------------------------
%	THEOREM STYLES
%----------------------------------------------------------------------------------------

\usepackage{amsmath,amsfonts,amssymb,amsthm} % For math equations, theorems, symbols, etc

\newcommand{\intoo}[2]{\mathopen{]}#1\,;#2\mathclose{[}}
\newcommand{\ud}{\mathop{\mathrm{{}d}}\mathopen{}}
\newcommand{\intff}[2]{\mathopen{[}#1\,;#2\mathclose{]}}
\newtheorem{notation}{Notation}[chapter]

% Boxed/framed environments
\newtheoremstyle{ocrenumbox}% % Theorem style name
{0pt}% Space above
{0pt}% Space below
{\normalfont}% % Body font
{}% Indent amount
{\small\bf\sffamily\color{cbleu}}% % Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily\color{cbleu}\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries\color{black}---\nobreakspace#3.}} % Optional theorem note
\renewcommand{\qedsymbol}{$\blacksquare$}% Optional qed square

\newtheoremstyle{blacknumex}% Theorem style name
{5pt}% Space above
{5pt}% Space below
{\normalfont}% Body font
{} % Indent amount
{\small\bf\sffamily}% Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily{\tiny\ensuremath{\blacksquare}}\nobreakspace\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries---\nobreakspace#3.}}% Optional theorem note

\newtheoremstyle{blacknumbox} % Theorem style name
{0pt}% Space above
{0pt}% Space below
{\normalfont}% Body font
{}% Indent amount
{\small\bf\sffamily}% Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries---\nobreakspace#3.}}% Optional theorem note

% Non-boxed/non-framed environments
\newtheoremstyle{ocrenum}% % Theorem style name
{5pt}% Space above
{5pt}% Space below
{\normalfont}% % Body font
{}% Indent amount
{\small\bf\sffamily\color{cbleu}}% % Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily\color{cbleu}\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries\color{black}---\nobreakspace#3.}} % Optional theorem note
\renewcommand{\qedsymbol}{$\blacksquare$}% Optional qed square
\makeatother

% Defines the theorem text style for each type of theorem to one of the three styles above
\newcounter{dummy} 
\numberwithin{dummy}{section}
\theoremstyle{ocrenumbox}
\newtheorem{theoremeT}[dummy]{Theorem}
\newtheorem{problem}{Problem}[chapter]
\newtheorem{exerciseT}{Exercise}[chapter]
\theoremstyle{blacknumex}
\newtheorem{exampleT}{Example}[chapter]
\theoremstyle{blacknumbox}
\newtheorem{vocabulary}{Vocabulary}[chapter]
\newtheorem{definitionT}{Definition}[section]
\newtheorem{corollaryT}[dummy]{Corollary}
\theoremstyle{ocrenum}
\newtheorem{proposition}[dummy]{Proposition}
Thanks for your help
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

\label{} field in definitions

Post by Johannes_B »

I just tried your snippet from the first post in a clean template, and i cannot reproduce the issue. Can you follow the following simple algorithm to make the reason really stand out? Creating a minimal working example
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
pierre92
Posts: 13
Joined: Fri Jun 19, 2015 4:19 pm

Re: \label{} field in definitions

Post by pierre92 »

I sincerely apologise to have wasted your time, it works indeed. As far as I can understand, I simply created a minimal example and compile it twice, saw that it worked. Re-opened my actual file, recompiled it and now it works... Once again, thanks for the help and sorry to have wasted your time.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: \label{} field in definitions

Post by Johannes_B »

That algorithm is very very useful, in simple cases like that the reason almost always resolves itself. For harder problems, there is just the stuff needed to reproduce an issue, no other stuff stealing attention.

Feel free to ask more questions ;-)
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply