LaTeX forum ⇒ Document Classessvmono v5.6: theorem counter following subsection counter

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

svmono v5.6: theorem counter following subsection counter

Postby user49915 » Fri Apr 26, 2019 6:51 pm

Consider the following input:

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. %\documentclass[envcountsame,envcountsubsect]{svmono-hacked}%%% How?
  2. \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 -->
  3. \usepackage{hyperref}
  4. \begin{document}
  5. \pagenumbering{Roman}
  6. % \author{I, the beloved one}
  7. % \title{My Title}
  8. %\maketitle
  9. \frontmatter
  10. % \tableofcontents%%% Irrelevant
  11. \mainmatter
  12. \chapter{My Chapter}
  13. \begin{definition}MyDefinition1\end{definition}%
  14. \begin{definition}MyDefinition2\end{definition}%
  15. \section{My Section}
  16. \begin{definition}MyDefinition3\end{definition}%
  17. \begin{definition}MyDefinition4\end{definition}%
  18. \subsection{My SubSection}
  19. \begin{definition}MyDefinition5\end{definition}
  20. \begin{definition}MyDefinition6\end{definition}
  21. \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 751 times


How to do it cleanly? My own attempts result in
  1. [1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}pdfTeX warning (ext4): des
  2. tination with the same identifier (name{theorem.1.1.1}) has been already used,
  3. duplicate ignored
  4.  
  5. \AtBegShi@Output ...ipout \box \AtBeginShipoutBox
  6. \fi \fi
  7. l.21 \end{document}
  8. pdfTeX warning (ext4): destination with the same identifier
  9. (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

Postby user22741 » Fri Apr 26, 2019 9:22 pm

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

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass[envcountsame,envcountsect]{svmono}
  2.  
  3. \usepackage{hyperref}
  4.  
  5. \counterwithin{theorem}{subsection}
  6.  
  7.  
  8. \begin{document}
  9.  
  10. \chapter{My Chapter}
  11. \begin{definition}MyDefinition1\end{definition}%
  12. \begin{definition}MyDefinition2\end{definition}%
  13. \section{My Section}
  14. \begin{definition}MyDefinition3\end{definition}%
  15. \begin{definition}MyDefinition4\end{definition}%
  16. \subsection{My SubSection}
  17. \begin{definition}MyDefinition5\end{definition}
  18. \begin{definition}MyDefinition6\end{definition}
  19. \end{document}

user49915
Posts: 46
Joined: Wed Apr 17, 2019 12:51 pm

Postby user49915 » Sat Apr 27, 2019 12:35 am

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

Postby user22741 » Sat Apr 27, 2019 12:38 am

tex magic!

user49915
Posts: 46
Joined: Wed Apr 17, 2019 12:51 pm

Postby user49915 » Fri May 10, 2019 10: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

Postby user22741 » Thu May 16, 2019 4:03 pm

add \listfiles to your document and compare the package versions written to the log file

rais
Posts: 235
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Fri May 17, 2019 3:09 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: 46
Joined: Wed Apr 17, 2019 12:51 pm

Postby user49915 » Fri May 17, 2019 8:29 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: 235
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Sat May 18, 2019 4:27 pm

Not necessarily. If you really need to run your code on different LaTeX-distro versions, you could try
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \makeatletter
  2. \@ifundefined{counterwithin}{\usepackage{chngcntr}}{}
  3. \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


Return to “Document Classes”

Who is online

Users browsing this forum: No registered users and 4 guests