Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

latex: how to let theorem numbering follow (sub-)sections?

76 views
Skip to first unread message

Jaakov

unread,
May 25, 2015, 3:02:25 PM5/25/15
to
Dear all:

In a book I am having sections with subsections and other sections
without subsections.

In sections that do not have subsections, I would like theorems,
propositions, lemmas etc. to follow the section numbering:
chapternnumber.sectionnumber.theoremnumber

In sections that do have subsections, I would like theorems,
propositions, lemmas etc. to follow the subsection numbering.
chapternnumber.sectionnumber.subsectionnumber.theoremnumber

I am using

\usepackage{amsthm}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{prop}[thm]{Proposition}
\newtheorem{lem}[thm]{Lemma}
\theoremstyle{definition}
\newtheorem{note}[thm]{Note}
etc.

in the preamble.

I need a solution that
- would be long-term (Must use amsthm, svmono, or a different
theorem-providing package expected to be maintained for 10 years.
Unfortunately, ntheorem is not an option: it has unacceptable bugs in
the qed placement and, as of today, has not been maintained since 2011.)
- would be solely restricted to the preamble
- would require no editing of the contents.

Any ideas?

Thanks in advance

Jaakov

Jaakov

unread,
May 25, 2015, 3:05:52 PM5/25/15
to
I am happy or ready to use latex3/expl3, if that would be of any help.

Jaakov

unread,
May 25, 2015, 11:32:35 PM5/25/15
to
Dear all:

In a book I am having sections with subsections and other sections
without subsections.

In sections that do not have subsections, I would like theorems,
propositions, lemmas etc. to follow the section numbering:
chapternnumber.sectionnumber.theoremnumber

In sections that do have subsections, I would like theorems,
propositions, lemmas etc. to follow the subsection numbering.
chapternnumber.sectionnumber.subsectionnumber.theoremnumber

I am using

\usepackage{amsthm}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{prop}[thm]{Proposition}
\newtheorem{lem}[thm]{Lemma}
\theoremstyle{definition}
\newtheorem{note}[thm]{Note}
etc.

in the preamble.

I need a solution that
- would be long-term (Must use amsthm, svmono, or a different
theorem-providing package expected to be maintained for 10 years.
Unfortunately, ntheorem is not an option: it has unacceptable bugs in
the qed placement and has not been maintained since 2011 till today.)
- would be solely restricted to the preamble
- would require no editing of the contents.

I am happy or ready to use latex3/expl3, if that would be easier or of
Message has been deleted

Ulrich D i e z

unread,
May 26, 2015, 8:15:39 AM5/26/15
to
[ This posting supersedes my posting
<news:mk1ipm$4d9$1...@news.albasani.net > ]

( Please make sure to read this posting in "original format".
Otherwise web interfaces might display it with some sort of
"prettified" line breaking while changing the line breaking of
(La)TeX-code might affect functionality of that code. )

Jaakov wrote:

> Dear all:
>
> In a book I am having sections with subsections and other sections
> without subsections.
>
> In sections that do not have subsections, I would like theorems,
> propositions, lemmas etc. to follow the section numbering:
> chapternnumber.sectionnumber.theoremnumber
>
> In sections that do have subsections, I would like theorems,
> propositions, lemmas etc. to follow the subsection numbering.
> chapternnumber.sectionnumber.subsectionnumber.theoremnumber

What numbering of theorems, propositions, lemmas, notes etc
do you wish within "starred"/unnumbered sections or
within "starred"/unnumbered subsections?

> I am using
>
> \usepackage{amsthm}
> \theoremstyle{plain}
> \newtheorem{thm}{Theorem}[section]
> \newtheorem{prop}[thm]{Proposition}
> \newtheorem{lem}[thm]{Lemma}
> \theoremstyle{definition}
> \newtheorem{note}[thm]{Note}
> etc.
>
> in the preamble.

Management and dependencies of counters for sectioning etc depends
on the documentclass and the packages in use.
You did not provide a minimal working document revealing that
information. Thus in the example below I relied on the book-class.

> I need a solution that
> - would be long-term (Must use amsthm, svmono, or a different
> theorem-providing package expected to be maintained for 10 years.
> Unfortunately, ntheorem is not an option: it has unacceptable bugs in
> the qed placement and, as of today, has not been maintained since 2011.)
> - would be solely restricted to the preamble
> - would require no editing of the contents.
>
> Any ideas?
>
> Thanks in advance
>
> Jaakov


The following approach might work both with hyperref-package being
loaded and without hyperref-package being loaded.

Sincerely

Ulrich



\documentclass[a4paper]{book}
\usepackage{hyperref}
\usepackage{amsthm}

\makeatletter

\newcommand{\IfGreaterZero}[1]{%
\ifnum\number\value{#1}>0 %
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}%
\newcommand\c@subsectionfork{}%
\newcommand\cl@subsectionfork{}%
\newcommand\thesubsectionfork{%
\IfGreaterZero{subsection}{\thesubsection}{\thesection}%
}%
\newcommand\theHsubsectionfork{%
\csname the%
\IfGreaterZero{subsection}%
{\@ifundefined{theHsubsection}{}{H}sub}%
{\@ifundefined{theHsection}{}{H}}%
section\endcsname
}%

\newcommand\disallocateCNT{\global\advance\count10 by -1\relax}%

\theoremstyle{plain}

\newif\ifUpcase
\global\Upcasefalse
\DeclareRobustCommand\ChkUpcase[1]{%
\ifUpcase
\global\Upcasefalse
\expandafter\uppercase
\else
\expandafter\@firstofone
\fi
{#1}%
}
\DeclareRobustCommand\Upcase{\Upcasetrue}%

\@addtoreset{thm}{chapter}
\@addtoreset{thm}{section}
\@addtoreset{thm}{subsection}
\newtheorem{thm}{Theorem}[subsectionfork]
\renewcommand\p@thm{\ChkUpcase theorem }

\@addtoreset{prop}{chapter}
\@addtoreset{prop}{section}
\@addtoreset{prop}{subsection}
\disallocateCNT
\newtheorem{prop}{Proposition}[subsectionfork]
\renewcommand\p@prop{\ChkUpcase proposition }

\@addtoreset{lem}{chapter}
\@addtoreset{lem}{section}
\@addtoreset{lem}{subsection}
\disallocateCNT
\newtheorem{lem}{Lemma}[subsectionfork]
\renewcommand\p@lem{\ChkUpcase lemma }

\theoremstyle{definition}

\@addtoreset{note}{chapter}
\@addtoreset{note}{section}
\@addtoreset{note}{subsection}
\disallocateCNT
\newtheorem{note}{Note}[subsectionfork]
\renewcommand\p@note{\ChkUpcase note }

\makeatother

\begin{document}

\tableofcontents

\chapter{A chapter}
\section{A section with subsection}
\subsection{A subsection}

\begin{thm}
\label{T1}This is a theorem.
\end{thm}

\begin{prop}
\label{P1}This is a proposition.
\end{prop}

\begin{lem}
\label{L1}This is a lemma.
\end{lem}

\begin{note}
\label{N1}This is a note.
\end{note}

\section{A section without subsection}

\begin{thm}
\label{T2}This is another theorem.
\end{thm}

\begin{prop}
\label{P2}This is another proposition.
\end{prop}

\begin{lem}
\label{L2}This is another lemma.
\end{lem}

\begin{note}
\label{N2}This is another note.
\end{note}


Referencing to labels of first section:\\
This is reference to \ref{T1}.\\
This is reference to \ref{P1}.\\
This is reference to \ref{L1}.\\
This is reference to \ref{N1}.\\

Referencing to labels of first section when the label is at
beginning of the sentence:\\
\Upcase\ref{T1} is nice.\\
\Upcase\ref{P1} is nice.\\
\Upcase\ref{L1} is nice.\\
\Upcase\ref{N1} is nice.\\

Referencing to labels of second section:\\
This is reference to \ref{T2}.\\
This is reference to \ref{P2}.\\
This is reference to \ref{L2}.\\
This is reference to \ref{N2}.\\

Referencing to labels of second section when the label is at
beginning of the sentence:\\
\Upcase\ref{T2} is nice.\\
\Upcase\ref{P2} is nice.\\
\Upcase\ref{L2} is nice.\\
\Upcase\ref{N2} is nice.\\

\end{document}

Jaakov

unread,
May 26, 2015, 11:43:13 AM5/26/15
to
Dear Ulrich,
That's a bit unfortunate, but we probably have to live with it.

> You did not provide a minimal working document revealing that
> information. Thus in the example below I relied on the book-class.
I am sorry about that. (I had thought your answer would not require a
minimal working example.)

>
>> I need a solution that
>> - would be long-term (Must use amsthm, svmono, or a different
>> theorem-providing package expected to be maintained for 10 years.
>> Unfortunately, ntheorem is not an option: it has unacceptable bugs in
>> the qed placement and, as of today, has not been maintained since 2011.)
>> - would be solely restricted to the preamble
>> - would require no editing of the contents.
>>
>> Any ideas?
>>
>> Thanks in advance
>>
>> Jaakov
>
>
> The following approach might work both with hyperref-package being
> loaded and without hyperref-package being loaded.
>
Indeed, it does!
Thank you so much!

However, the words "theorem", "note", "lemma", etc. are now part of the
reference. This is a great feature by itself. But this is not quite
compatible with the traditional representation. Also you might need to
say something like "using claims 9.1.9--9.1.13 ...", where these claims
are multitype, consisting of, say, lemmas and corollaries. This is not
expected to happen in this book, but it did occur once in my own practice.
As far as I understand, to get just the number without text when writing
\ref, I have to comment out commands "\renewcommand\p@thm{\ChkUpcase
theorem }". Is it true?

I would never have been able to come up with this solution myself. Thank
you once again!

Jaakov.

Axel Romihsita

unread,
May 26, 2015, 11:57:53 AM5/26/15
to
> What numbering of theorems, propositions, lemmas, notes etc
> do you wish within "starred"/unnumbered sections or
> within "starred"/unnumbered subsections?
A good question. In my book, there are no unnumbered
chapters/sections/subsections with theorem-like environments so far. The
front and back matters have no such environments so far.

If I had some, I guess, I would like to have no numbering of
theorem-like environments as well.

Jaakov

unread,
May 26, 2015, 11:58:53 AM5/26/15
to
> What numbering of theorems, propositions, lemmas, notes etc
> do you wish within "starred"/unnumbered sections or
> within "starred"/unnumbered subsections?

Ulrich D i e z

unread,
May 26, 2015, 2:08:10 PM5/26/15
to
Jaakov wrote:

> However, the words "theorem", "note", "lemma", etc. are now part of the
> reference. This is a great feature by itself. But this is not quite
> compatible with the traditional representation. Also you might need to
> say something like "using claims 9.1.9--9.1.13 ...", where these claims
> are multitype, consisting of, say, lemmas and corollaries.

You are right - I don't know what I was thinking.

Below is the code with these words removed.
\@addtoreset{thm}{chapter}
\@addtoreset{thm}{section}
\@addtoreset{thm}{subsection}
\newtheorem{thm}{Theorem}[subsectionfork]

\@addtoreset{prop}{chapter}
\@addtoreset{prop}{section}
\@addtoreset{prop}{subsection}
\disallocateCNT
\newtheorem{prop}{Proposition}[subsectionfork]

\@addtoreset{lem}{chapter}
\@addtoreset{lem}{section}
\@addtoreset{lem}{subsection}
\disallocateCNT
\newtheorem{lem}{Lemma}[subsectionfork]

\theoremstyle{definition}

\@addtoreset{note}{chapter}
\@addtoreset{note}{section}
\@addtoreset{note}{subsection}
\disallocateCNT
\newtheorem{note}{Note}[subsectionfork]

This is reference to theorem \ref{T1}.\\
This is reference to proposition \ref{P1}.\\
This is reference to lemma \ref{L1}.\\
This is reference to note \ref{N1}.\\

Referencing to labels of second section:\\
This is reference to theorem \ref{T2}.\\
This is reference to proposition \ref{P2}.\\
This is reference to lemmma \ref{L2}.\\
This is reference to note \ref{N2}.\\

The following does only work with hyperref and is intended
to exhibit another possibility of getting arbitrary additional
phrases into the text of a hyperlink as well:

Referencing to labels of first section---%
some phrase is part of the link:\\
This is reference to \hyperref[T1]{theorem \ref*{T1}}.\\
This is reference to \hyperref[P1]{proposition \ref*{P1}}.\\
This is reference to \hyperref[L1]{lemma \ref*{L1}}.\\
This is reference to \hyperref[N1]{note \ref*{N1}}.\\

Referencing to labels of second section---%
some phrase is part of the link:\\
This is reference to \hyperref[T2]{theorem \ref*{T2}}.\\
This is reference to \hyperref[P2]{proposition \ref*{P2}}.\\
This is reference to \hyperref[L2]{lemmma \ref*{L2}}.\\
This is reference to \hyperref[N2]{note \ref*{N2}}.\\

\end{document}

Jaakov

unread,
May 26, 2015, 4:17:18 PM5/26/15
to
Dear Ulrich:

Thank you so much!!!

Jaakov.
0 new messages