Text FormattingCustom subsection numbering

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

Custom subsection numbering

Post by Jürgen Hubert »

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

Code: Select all

Code, edit and compile here:
\documentclass[oneside]{book}
[...]
\usepackage{chngcntr}
\counterwithout{subsection}{chapter}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Custom subsection numbering

Post by rais »

\counterwithout{subsection}{chapter}
does nothing, because the subsection counter is bound to the section counter, not the chapter counter.
You could try

Code: Select all

\counterwithout{subsection}{section}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
instead.
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

Code: Select all

\newcounter{story}
\newcommand\story{\par\textit{Story \thestory:~}}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
or some such.

KR
Rainer
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Custom subsection numbering

Post by Ijon Tichy »

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:
Code, edit and compile here:
\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]
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
You can omit emulatestandardclasses,chapterprefix=false to see the differences using the default layout of scrbook.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Jürgen Hubert
Posts: 6
Joined: Tue Aug 13, 2019 9:21 am

Custom subsection numbering

Post by Jürgen Hubert »

rais wrote:\counterwithout{subsection}{chapter}
does nothing, because the subsection counter is bound to the section counter, not the chapter counter.
You could try

Code: Select all

\counterwithout{subsection}{section}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
instead.
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

Code: Select all

\newcounter{story}
\newcommand\story{\par\textit{Story \thestory:~}}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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?
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Custom subsection numbering

Post by Ijon Tichy »

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.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Custom subsection numbering

Post by rais »

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

Custom subsection numbering

Post by Jürgen Hubert »

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:

Code: Select all

! Package scrlayer Error: package incompatibility detected.
[...]
? H
Another 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.
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Before I try to delve deeper into this, does anyone know of any incompatibilities between scrbook and one of the following?

Code: Select all

Code, edit and compile here:
\usepackage[utf8]{inputenc}
\usepackage{chngcntr}% http://ctan.org/pkg/chngcntr
\counterwithout{subsubsection}{subsection}
\ifdefined\HCode
\usepackage[xindy,noautomatic]{imakeidx}
\else
\usepackage[]{imakeidx}
\fi
\usepackage{multibib}
\usepackage{tex4ebook}
\usepackage{xcolor}
\usepackage[hyperindex=true]{hyperref}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Custom subsection numbering

Post by Ijon Tichy »

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:

Code: Select all

Code, edit and compile here:
\ifdefined\HCode
\AtBeginDocument{\def\pagestyle#1{\edef\currentpagestyle{#1}}}
\fi
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
before \documentclass.

However you should report the problem to the maintainer of tex4ht.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Jürgen Hubert
Posts: 6
Joined: Tue Aug 13, 2019 9:21 am

Custom subsection numbering

Post by Jürgen Hubert »

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:

Code: Select all

Code, edit and compile here:
\ifdefined\HCode
\AtBeginDocument{\def\pagestyle#1{\edef\currentpagestyle{#1}}}
\fi
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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

Code: Select all

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

Code: Select all

Code, edit and compile here:
\usepackage{indexing4ht}
\Preamble{xhtml}
\begin{document}
\EndPreamble
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
and mybuild.mk4

Code: Select all

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) do
t[#t+1] = "-M ".. v
end
par.moduleopt = table.concat(t, " ")
local xindy_call = "xindy -L ${language} -C ${encoding} ${moduleopt} ${idxfile}" % par
print(xindy_call)
return os.execute(xindy_call)
end, { language = "english", encoding = "utf8"})
if mode=="index" then
Make:htlatex {}
Make:xindy { idxfile="place.idx"}
Make:xindy { idxfile="topic.idx"}
Make:htlatex {}
Make:htlatex {}
elseif mode=="draft" then
Make:htlatex {}
else
Make:htlatex {}
Make:htlatex {}
Make:htlatex {}
end
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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

Custom subsection numbering

Post by Jürgen Hubert »

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.
Post Reply