[ 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}