## LaTeX forum ⇒ Text Formatting ⇒ Custom subsection numbering

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Jürgen Hubert
Posts: 6
Joined: Tue Aug 13, 2019 9:21 am

### Custom subsection numbering

I am currently writing a collection of German folklore tales. And in many of the original collection of tales the tales are numbered independently of the chapters and sections. For example:

1. The Rogue's Gallery

1.1 The Devil

Story 1: The Devil gets tricked by mortals

Story 2: The Devil gets tricked by a smith, twice

Story 3: Curses, foiled again!

1.2 Frau Gauden

Story 4: Frau Gauden throws a half-eaten human leg through a window

Story 5: Frau Gauden rewards a farmhand with dog droppings that turns into gold the next morning

2. The Bestiary

2.1 Dragons

Story 6: Plucky farmers poison a lindwurm that has been eating all the cattle and all those useless armored knights

Story 7: A lindwurm transforms into a giant hoop and chases a farmer after its kid gets accidentally killed

and so forth.

My first attempt to do this was with the chngcntr package. However, using

1. \documentclass[oneside]{book}
2.
3. [...]
4.
5. \usepackage{chngcntr}
6. \counterwithout{subsection}{chapter}

I ended up with a counter for the subsections (which is how the individual tales are organized right now) that resets at every section (and not every chapter, as I would have thought given the code).

Do you have any suggestions for how to proceed?

rais
Posts: 258
Joined: Sun Nov 16, 2014 8:51 pm
\counterwithout{subsection}{chapter}
does nothing, because the subsection counter is bound to the section counter, not the chapter counter.
You could try
1. \counterwithout{subsection}{section}

BTW, the functionality of the chngcntr package has been merged into the LaTeX kernel, so if you don't get any error by loading the package, your LaTeX distribution may be outdated.

Come to think of it, you could define your own story' command and thus don't need to adhere to the standard sectioning commands, say
1. \newcounter{story}
2. \newcommand\story{\par\textit{Story \thestory:~}}

or some such.

KR
Rainer

Ijon Tichy
Posts: 233
Joined: Mon Dec 24, 2018 10:12 am
rais wrote:BTW, the functionality of the chngcntr package has been merged into the LaTeX kernel, so if you don't get any error by loading the package, your LaTeX distribution may be outdated.

With new LaTeX kern and new version of chngcntr you won't get an error, only an information in the log file (not the terminal output). So using chngcntr doesn't matter with new LaTeX kernels and may help if someone uses an old LaTeX kernel.

BTW: I would recommend to use a KOMA-Script class. Those classes provide an easy interface to add a prefix before the subsection number or to change the font of the title. Example:
1. \documentclass[
2. emulatestandardclasses,% emulate the layout of the standard book class
3. chapterprefix=false,% but don't use chapter headings with "chapter" prefix line
4. oneside,
5. headings=small,% make the titles of chapters, section etc. somehow smaller
6. ]{scrbook}
7.
8. \usepackage{lipsum}
9.
10. \counterwithout{subsection}{section}
11. \renewcommand*{\subsectionformat}{Story~\thesubsection:\ }% show "Story"
12. % before number in subsection title
13. \addtokomafont{subsection}{\mdseries}% don't use \bfseries in the subsection title
14.
15. \begin{document}
16. \chapter{The Rogue's Gallery}
17.
18. \section{The Devil}
19.
20. \subsection{The Devil gets tricked by mortals}
21.
22. \lipsum[1]
23.
24. \subsection{The Devil gets tricked by a smith, twice}
25.
26. \lipsum[2]
27.
28. \subsection{Curses, foiled again!}
29.
30. \lipsum[3]
31.
32. \section{Frau Gauden}
33.
34. \subsection{Frau Gauden throws a half-eaten human leg through a window}
35.
36. \lipsum[4]
37.
38. \subsection{Frau Gauden rewards a farmhand with dog droppings that turns into gold the next morning}
39.
40. \lipsum[5]
41.
42. \chapter{The Bestiary}
43.
44. \section{Dragons}
45.
46. \subsection{Plucky farmers poison a lindwurm that has been eating all the cattle and all those useless armored knights}
47.
48. \lipsum[6]
49.
50. \subsection{A lindwurm transforms into a giant hoop and chases a farmer after its kid gets accidentally killed}
51.
52. \lipsum[7]
53.
54. \end{document}

You can omit emulatestandardclasses,chapterprefix=false to see the differences using the default layout of scrbook.

Jürgen Hubert
Posts: 6
Joined: Tue Aug 13, 2019 9:21 am
rais wrote:\counterwithout{subsection}{chapter}
does nothing, because the subsection counter is bound to the section counter, not the chapter counter.
You could try
1. \counterwithout{subsection}{section}

BTW, the functionality of the chngcntr package has been merged into the LaTeX kernel, so if you don't get any error by loading the package, your LaTeX distribution may be outdated.

That worked, thanks!

Come to think of it, you could define your own story' command and thus don't need to adhere to the standard sectioning commands, say
1. \newcounter{story}
2. \newcommand\story{\par\textit{Story \thestory:~}}

or some such.

That's an interesting idea - I haven't created any custom LaTeX commands so far, but maybe I should give it a try. Could these also be made to show up in the Table of Contents - or in the bookmarks of a PDF document made with pdflatex?

Ijon Tichy
Posts: 233
Joined: Mon Dec 24, 2018 10:12 am
KOMA-Script classes also provide an interface to generate new section commands (see \DeclareNewSectionCommand in the KOMA-Script manual). With the newly defined command you can do almost the same like I've shown for the reconfiguration of \subsection.

rais
Posts: 258
Joined: Sun Nov 16, 2014 8:51 pm
Ijon Tichy wrote:With new LaTeX kern and new version of chngcntr you won't get an error, only an information in the log file (not the terminal output). So using chngcntr doesn't matter with new LaTeX kernels and may help if someone uses an old LaTeX kernel.

thanks, I stand corrected

KR
Rainer

Jürgen Hubert
Posts: 6
Joined: Tue Aug 13, 2019 9:21 am
I've tried out scrbook, and it works great for pdflatex.

However, when I try to use it with my epub setup, I get the following error:

1. ! Package scrlayer Error: package incompatibility detected.
2.
3. [...]
4.
5. ? H
6. Another package redefines \pagestyle incompatible with scrlayer.
7. This disables setting of \currentpagestyle and may be serious.
9. If not you should either not use scrlayer or not the other package,
10. that redefines \pagestyle.

Before I try to delve deeper into this, does anyone know of any incompatibilities between scrbook and one of the following?

1. \usepackage[utf8]{inputenc}
2. \usepackage{chngcntr}% <!-- m --><a class="postlink" href="http://ctan.org/pkg/chngcntr">http://ctan.org/pkg/chngcntr</a><!-- m -->
3. \counterwithout{subsubsection}{subsection}
4.
5. \ifdefined\HCode
6. \usepackage[xindy,noautomatic]{imakeidx}
7. \else
8. \usepackage[]{imakeidx}
9. \fi
10. \usepackage{multibib}
11. \usepackage{tex4ebook}
12. \usepackage{xcolor}
13. \usepackage[hyperindex=true]{hyperref}

Ijon Tichy
Posts: 233
Joined: Mon Dec 24, 2018 10:12 am
latex.4ht redefines \pagestyle incompatible to scrlayer-scrpage However for an eBook usage of the package doesn't make much sense. So as a workaround you can omit option emulatestandarclasses. Another workaround would be to use:
1. \ifdefined\HCode
2. \AtBeginDocument{\def\pagestyle#1{\edef\currentpagestyle{#1}}}
3. \fi

before \documentclass.

However you should report the problem to the maintainer of tex4ht.

Jürgen Hubert
Posts: 6
Joined: Tue Aug 13, 2019 9:21 am
Ijon Tichy wrote:latex.4ht redefines \pagestyle incompatible to scrlayer-scrpage However for an eBook usage of the package doesn't make much sense. So as a workaround you can omit option emulatestandarclasses. Another workaround would be to use:
1. \ifdefined\HCode
2. \AtBeginDocument{\def\pagestyle#1{\edef\currentpagestyle{#1}}}
3. \fi

before \documentclass.

However you should report the problem to the maintainer of tex4ht.

I'll contact him.

My goal is to create an epub file. From my understanding, tex4ht does this by first creating a series of interlinked HTML documents and then converting these into epub files. I compile all this with

1. tex4ebook -lm index -c myconfig.cfg -e mybuild.mk4 <texfile>.tex

using myconfig.cfg

1. \usepackage{indexing4ht}
2. \Preamble{xhtml}
3. \begin{document}
4. \EndPreamble

and mybuild.mk4

2. par.idxfile = par.idxfile or par.input .. ".idx"
3. local modules = par.modules or {par.input}
4. local t = {}
5. for k,v in ipairs(modules) do
6. t[#t+1] = "-M ".. v
7. end
8. par.moduleopt = table.concat(t, " ")
9. local xindy_call = "xindy -L ${language} -C${encoding} ${moduleopt}${idxfile}" % par
10. print(xindy_call)
11. return os.execute(xindy_call)
12. end, { language = "english", encoding = "utf8"})
13.
14.
15. if mode=="index" then
16. Make:htlatex {}
17. Make:xindy { idxfile="place.idx"}
18. Make:xindy { idxfile="topic.idx"}
19. Make:htlatex {}
20. Make:htlatex {}
21. elseif mode=="draft" then
22. Make:htlatex {}
23. else
24. Make:htlatex {}
25. Make:htlatex {}
26. Make:htlatex {}
27. end

If you have another way of generating epub files that can include multiple hyperlinked indices, I am all ears.

Jürgen Hubert
Posts: 6
Joined: Tue Aug 13, 2019 9:21 am
This blog entry seems to suggest that using scrbook and tex4ebook will not work together, as the author recommends switching between the two for compiling.

As ultimately the PDFs are for proofreading and the epub files are what is really important in the end, I think I will switch back to the book documentclass.