texlive 2014, Linux

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

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

Error is

htlatex foo.tex

! 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


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


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


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


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 .