## 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

\documentclass[oneside]{book} [...] \usepackage{chngcntr}\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: 235
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
\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
\newcounter{story}\newcommand\story{\par\textit{Story \thestory:~}}

or some such.

KR
Rainer

Ijon Tichy
Posts: 118
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:
\documentclass[  emulatestandardclasses,% emulate the layout of the standard book class  chapterprefix=false,% but don't use chapter headings with "chapter" prefix line  oneside,  headings=small,% make the titles of chapters, section etc. somehow smaller]{scrbook} \usepackage{lipsum} \counterwithout{subsection}{section}\renewcommand*{\subsectionformat}{Story~\thesubsection:\ }% show "Story"                                % before number in subsection title\addtokomafont{subsection}{\mdseries}% don't use \bfseries in the subsection title \begin{document}\chapter{The Rogue's Gallery} \section{The Devil} \subsection{The Devil gets tricked by mortals} \lipsum[1] \subsection{The Devil gets tricked by a smith, twice} \lipsum[2] \subsection{Curses, foiled again!} \lipsum[3] \section{Frau Gauden} \subsection{Frau Gauden throws a half-eaten human leg through a window} \lipsum[4] \subsection{Frau Gauden rewards a farmhand with dog droppings that turns into gold the next morning} \lipsum[5] \chapter{The Bestiary} \section{Dragons} \subsection{Plucky farmers poison a lindwurm that has been eating all the cattle and all those useless armored knights} \lipsum[6] \subsection{A lindwurm transforms into a giant hoop and chases a farmer after its kid gets accidentally killed} \lipsum[7] \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
\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
\newcounter{story}\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: 118
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: 235
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:

! Package scrlayer Error: package incompatibility detected. [...] ? HAnother package redefines \pagestyle incompatible with scrlayer.This disables setting of \currentpagestyle and may be serious.Maybe you could prevent this loading package scrlayer later.If not you should either not use scrlayer or not the other package,that redefines \pagestyle.

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

\usepackage[utf8]{inputenc}\usepackage{chngcntr}% <!-- m --><a class="postlink" href="http://ctan.org/pkg/chngcntr">http://ctan.org/pkg/chngcntr</a><!-- m -->\counterwithout{subsubsection}{subsection} \ifdefined\HCode\usepackage[xindy,noautomatic]{imakeidx}\else\usepackage[]{imakeidx}\fi\usepackage{multibib}\usepackage{tex4ebook}\usepackage{xcolor}\usepackage[hyperindex=true]{hyperref}

Ijon Tichy
Posts: 118
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:
\ifdefined\HCode\AtBeginDocument{\def\pagestyle#1{\edef\currentpagestyle{#1}}}\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:
\ifdefined\HCode\AtBeginDocument{\def\pagestyle#1{\edef\currentpagestyle{#1}}}\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

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

using myconfig.cfg

\usepackage{indexing4ht}\Preamble{xhtml}\begin{document}\EndPreamble

and mybuild.mk4

Make:add("xindy", function(par)par.idxfile = par.idxfile or par.input .. ".idx"local modules = par.modules or {par.input}local t = {}for k,v in ipairs(modules) dot[#t+1] = "-M ".. vendpar.moduleopt = table.concat(t, " ")local xindy_call = "xindy -L ${language} -C${encoding} ${moduleopt}${idxfile}" % parprint(xindy_call)return os.execute(xindy_call)end, { language = "english", encoding = "utf8"})  if mode=="index" thenMake:htlatex {}Make:xindy { idxfile="place.idx"}Make:xindy { idxfile="topic.idx"}Make:htlatex {}Make:htlatex {}elseif mode=="draft" thenMake:htlatex {}elseMake:htlatex {}Make:htlatex {}Make:htlatex {}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.