titlesec: loss of section numbering with the new update (2016/03/15)

After reinstalling TeXLive distribution (install-tl-20160318, Ubuntu 14.04), a issue occurs with the updated version of the titlesec package: the section numbering is lost.

What could it be missing? Is there a modification I have not seen?

Below is a MWE comparison of the two versions. The prevtitlesec package is a reinstall of the previous version (2011/12/15).

\documentclass{book}
\usepackage[margin=2cm,a4paper]{geometry}
%\usepackage{prevtitlesec}% 2011/12/15 version
\usepackage{titlesec}% 2016/03/15 version
\usepackage{lipsum}

\begin{document}

\chapter{Title of the first chapter}
\lipsum[1]
\section{A test section}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]

\end{document}


titlesec package 2011/12/15:

titlesec package 2016/03/15:

Update

The issue has been solved with titlesec version 2.10.2 (released 2016/03/21)

Original answer

The bug in the new version 2.10.1 is not properly starting horizontal mode as it was done previously.

You can cure the bug by adding

\usepackage{etoolbox}

\makeatletter
\patchcmd{\ttlh@hang}{\parindent\z@}{\parindent\z@\leavevmode}{}{}
\patchcmd{\ttlh@hang}{\noindent}{}{}{}
\makeatother


after \usepackage{titlesec}.

Here is the “proper” code for \ttlh@hang (titlesec.sty line 746)

\def\ttlh@hang#1#2#3#4#5#6#7#8{%
\gdef\ttl@makeline##1{\ttl@calc\hspace{#6}##1\ttl@calc\hspace{#7}}%
\setlength\leftskip{#6}%
\setlength\rightskip{#7}%
\interlinepenalty\@M
\ttl@changecentercr
\ttl@beginlongest
#1{\ifhmode\ttl@hmode@error\fi
\ttl@glcmds
\parindent\z@
\leavevmode % <------ MISSING
\begingroup
\ifttl@label
\sbox\z@{#2\strut\ttl@calc\hspace{#3}}%
\hangindent\wd\z@
\box\z@ % \noindent was redundant
\fi
#4{#8}%
\kern\z@\strut\@@par
\endgroup
\nobreak\ttl@midlongest#5\@@par}%
\ttl@endlongest}


• Many thanks for the patch and your instrutive explanations. – ejazz Mar 22 '16 at 10:02
• Thanks for the code! This was driving me crazy after I've updated my installation. I've just mailed the developer regarding this issue. Hope it will be fixed in an upcoming update. – fdiog Mar 22 '16 at 16:37
• Thanks for the solution. This question has been around since a week yet today I updated my TeX installation and ran into the same problem, and the report is due tomorrow! Although this one is the cure, it's a bit overkill to me :) For a temporal solution, I'll build the final output on another PC which has the old set of packages :) – Jim Raynor Mar 22 '16 at 22:19
• @JimRaynor Just the first five lines are necessary; the rest is the complete macro definition, but the patch is easier. – egreg Mar 22 '16 at 22:30
• @JimRaynor fixed: new version titlesec – touhami Mar 23 '16 at 13:50

For Ubuntu 16.04 with texlive:

sudo wget http://mirrors.ctan.org/macros/latex/contrib/titlesec/titlesec.sty -O /usr/share/texlive/texmf-dist/tex/latex/titlesec/titlesec.sty

For other Linux distros:

First run locate /titlesec.sty then adapt the previous code.

Local tree for a single non-admin user:

mkdir -p ~/texmf/tex/latex/titlesec/ ; wget http://mirrors.ctan.org/macros/latex/contrib/titlesec/titlesec.sty -O ~/texmf/tex/latex/titlesec/titlesec.sty

• long life to you Sir! – PeterB Apr 21 '17 at 19:47
• I am not sure, but maybe it is a better idea to put it in your personal texmf instead. The command in my case is wget http://mirrors.ctan.org/macros/latex/contrib/titlesec/titlesec.sty -O ~/texmf/tex/latex/titlesec/titlesec.sty. You have to make sure the directory already exists. – Paul Paulsen Jul 31 '17 at 13:37