Document Classessvmono v5.6: theorem counter following subsection counter

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

svmono v5.6: theorem counter following subsection counter

Post by user49915 »

Consider the following input:

Code: Select all

%\documentclass[envcountsame,envcountsubsect]{svmono-hacked}%%% How?
\documentclass[envcountsame,envcountsect]{svmono}%%% Version 5.6 from http://www.springer.com/gp/authors-editors/book-authors-editors/resources-guidelines/rights-permissions-licensing/manuscript-preparation/5636
\usepackage{hyperref}
\begin{document}
\pagenumbering{Roman}
% \author{I, the beloved one}
% \title{My Title}
%\maketitle
\frontmatter
% \tableofcontents%%% Irrelevant
\mainmatter
\chapter{My Chapter}
\begin{definition}MyDefinition1\end{definition}%
\begin{definition}MyDefinition2\end{definition}%
\section{My Section}
\begin{definition}MyDefinition3\end{definition}%
\begin{definition}MyDefinition4\end{definition}%
\subsection{My SubSection}
\begin{definition}MyDefinition5\end{definition}
\begin{definition}MyDefinition6\end{definition}
\end{document}
We wish to hack svmono in such a way that all the theorem-like environments share the same counter on the subsection level, i.e., produce something like
screenshot.png
screenshot.png (45.61 KiB) Viewed 7370 times
How to do it cleanly? My own attempts result in
[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}pdfTeX warning (ext4): des
tination with the same identifier (name{theorem.1.1.1}) has been already used, 
duplicate ignored

\AtBegShi@Output ...ipout \box \AtBeginShipoutBox 
                                                  \fi \fi 
l.21 \end{document}
                   pdfTeX warning (ext4): destination with the same identifier 
(name{theorem.1.1.2}) has been already used, duplicate ignored
messages from hyperref, and, frankly, I don't really understand what to do.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
user22741
Posts: 35
Joined: Fri Nov 09, 2018 12:03 pm

svmono v5.6: theorem counter following subsection counter

Post by user22741 »

Try `\counterwithin{theorem}{subsection}`:

Code: Select all

\documentclass[envcountsame,envcountsect]{svmono}

\usepackage{hyperref}

\counterwithin{theorem}{subsection}


\begin{document}

\chapter{My Chapter}
\begin{definition}MyDefinition1\end{definition}%
\begin{definition}MyDefinition2\end{definition}%
\section{My Section}
\begin{definition}MyDefinition3\end{definition}%
\begin{definition}MyDefinition4\end{definition}%
\subsection{My SubSection}
\begin{definition}MyDefinition5\end{definition}
\begin{definition}MyDefinition6\end{definition}
\end{document}
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

svmono v5.6: theorem counter following subsection counter

Post by user49915 »

Wow! Thx! You saved my ass today. I don't see any package providing `\counterwithin`. I neither see `chngcntr` loaded anywhere. How does it work?
user22741
Posts: 35
Joined: Fri Nov 09, 2018 12:03 pm

svmono v5.6: theorem counter following subsection counter

Post by user22741 »

tex magic!
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

svmono v5.6: theorem counter following subsection counter

Post by user49915 »

user22741 wrote:tex magic!
This magic works for me on Ubuntu 18.10 and Ubuntu 19.04 installations, but not on Ubuntu 18.04.02 LTS, and not on Debian 9.9. Is it hyperref that has to be updated or should it be something else?
user22741
Posts: 35
Joined: Fri Nov 09, 2018 12:03 pm

svmono v5.6: theorem counter following subsection counter

Post by user22741 »

add \listfiles to your document and compare the package versions written to the log file
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

svmono v5.6: theorem counter following subsection counter

Post by rais »

user49915 wrote: This magic works for me on Ubuntu 18.10 and Ubuntu 19.04 installations, but not on Ubuntu 18.04.02 LTS, and not on Debian 9.9. Is it hyperref that has to be updated or should it be something else?
With TL18, chngcntr's \counterwithin/\counterwithout commands (or some modified versions thereof) have been embedded into the LaTeX core, that's why you don't need the chngcntr package anymore. In fact, if used, it should throw an error, because these commands are already defined...

If you want to update, update your TeX distri. If you're using packaged versions of your Linux distri(s), that may not be possible---in that case, simply add \usepackage{chngcntr} for your older versions.

KR
Rainer
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

svmono v5.6: theorem counter following subsection counter

Post by user49915 »

rais wrote: If you want to update, update your TeX distri.
Thx, I see. So, one should change the sources (include chngcntr or not) depending on which LaTeX distribution is used, right?
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

svmono v5.6: theorem counter following subsection counter

Post by rais »

Not necessarily. If you really need to run your code on different LaTeX-distro versions, you could try

Code: Select all

\makeatletter
  \@ifundefined{counterwithin}{\usepackage{chngcntr}}{}
\makeatother
that should load chngcntr only if \counterwithin isn't defined.

Or you could load amsmath and use its \numberwithin instead of \counterwithin.

KR
Rainer
Post Reply