## LaTeX forum ⇒ Document Classes ⇒ svmono v5.6: theorem counter following subsection counter

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

### svmono v5.6: theorem counter following subsection counter

Consider the following input:

%\documentclass[envcountsame,envcountsubsect]{svmono-hacked}%%% How?\documentclass[envcountsame,envcountsect]{svmono}%%% Version 5.6 from <!-- m --><a class="postlink" href="http://www.springer.com/gp/authors-editors/book-authors-editors/resources-guidelines/rights-permissions-licensing/manuscript-preparation/5636">http://www.springer.com/gp/authors-edit ... ation/5636</a><!-- m -->\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 (45.61 KiB) Viewed 561 times

How to do it cleanly? My own attempts result in
[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}pdfTeX warning (ext4): destination 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.

user22741
Posts: 35
Joined: Fri Nov 09, 2018 12:03 pm
Try \counterwithin{theorem}{subsection}:

\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: 35
Joined: Wed Apr 17, 2019 12:51 pm
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
tex magic!

user49915
Posts: 35
Joined: Wed Apr 17, 2019 12:51 pm
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
add \listfiles to your document and compare the package versions written to the log file

rais
Posts: 209
Joined: Sun Nov 16, 2014 8:51 pm
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: 35
Joined: Wed Apr 17, 2019 12:51 pm
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: 209
Joined: Sun Nov 16, 2014 8:51 pm
Not necessarily. If you really need to run your code on different LaTeX-distro versions, you could try
\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