4

texlive 2014, Linux

This MWE fails when using $[B]$ in section title when the package titlesec is loaded

\documentclass[]{article}%
\usepackage{titlesec}
\begin{document}
\section{this is my $[B]$ section}
test
\end{document}

Error is

htlatex foo.tex

(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo.aux)
! Extra }, or forgotten $.
<recently read> }

l.4 \section{this is my $[B]$ section}                                          
? 

When commenting the titlesec package, it compiles OK. Also, If I load the package, but change the title to $(B)$ instead of $[B]$ then it compiles OK as well. Only when using [] it is not happy.

The above MWE compiles OK with pdflatex and latex.

Why does it fail in tex4ht?

 Version 3.14159265-2.6-1.40.15 (TeX Live 2014)

1 Answer 1

7

In titlesec.4ht macro \ttl@straight@i is redefined

\let\ttl:straight@i\ttl@straight@i
\def\ttl@straight@i#1[#2]#3{%

original \ttl@straight@i is saved ad \ttl:straight@i and \ttl@straight@i is redefined to do some additional things. as you can see, [] characters are used as delimiters. Saved original \ttl@straight@i is then called with

 \ttl:straight@i{#1}[#2]{#3}%

and it seems this is the place where it goes wrong. I tried to fix it with adding brackets around the argument:

 \ttl:straight@i{#1}[{#2}]{#3}%

and it seems to compile without error, but I am not sure whether this doesn't break something else, so I can't confirm that this fix is safe.

Original answer:

It seems that some macro in tex4ht configuration for titlesec is using ] as delimiter, so you must protect it if that character appears in your section title. Simplest thing you can do is it to use {} around your math:

\section{this is my {$[B]$} section}

You must log in to answer this question.

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