1

I am trying to get tex4ht to add a prefix to the <title> tags of split chapters.

Using the following make4ht config file:

\Preamble{xhtml,ext=html,charset="utf-8"}
\Configure{TITLE+}{Some Author | Book Title}
\begin{document}
\EndPreamble

With the following TeX file:

\documentclass[openright,a5paper]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\title{Some Book}
\subtitle{A novel}
\author{Some Author}

\begin{document}

\maketitle{}
\tableofcontents{}

\chapter{Chapter One}
\chapter{Chapter Two}

\end{document}

Compiling via:

make4ht --config make4ht.cfg --utf8 book.tex "2,sec-filename,nominitoc,sections+"

I end up with the main .html containing a nice title (Some Author | Book Title), as expected. However, the <title> tags of the chapter .html files contain:

 1 Chapter One
 2 Chapter Two

I would like the chapter pages to be titled (for easier bookmarking and SEO):

Some Author | Book Title | 1 Chapter One
Some Author | Book Title | 2 Chapter Two

How can I add this prefix? It seems the TITLE+ configuration knob only applies to the main file.

1 Answer 1

3

Titles for pages broken on sectioning commands can be set using \Configure{<cmd>TITLE+}{title contets}. As you broke your document on chapters, you can use chapterTITLE+. You will probably also want to support \chapter*. In this case, add also the likechapterTITLE+:

\Preamble{xhtml,ext=html,charset="utf-8"}
\Configure{TITLE+}{Some Author | Book Title}
\Configure{chapterTITLE+}{Some Author | Book Title | \thechapter\space#1}
\Configure{likechapterTITLE+}{Some Author | Book Title | #1}
\begin{document}
\EndPreamble

The HTML file for chapter one now looks like this:

<!DOCTYPE html> 
<html lang='en-US' xml:lang='en-US'> 
<head><title>Some Author | Book Title | 1 Chapter One</title> 
<meta charset='utf-8' /> 
3
  • Thanks, this is brillant! Works like a charm :-). Is it also possible to include the chaper number in the title for the chapters? Mar 27, 2022 at 12:39
  • @OliverFreyermuth sure, see my edit
    – michal.h21
    Mar 27, 2022 at 12:46
  • Works perfectly :-). I already upvoted your reply and accepted it as answer, the vote may only arrive once I have collected enough reputation here. Thanks again! Mar 27, 2022 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .