[Tex/LaTex] Incompatibility of biblatex and tex4ht when using defernumbers

biblatexincompatibilitysubdividingtex4ht

There seems to be a known incompatibility between biblatex and tex4ht when using defernumbers=true.
I have one large .bib file. In the document I want to group the references into different categories. When using numerical labels, this requires defernumbers=true to obtain consecutive numbering.

Everything works fine, apart from that htlatex chokes on this option with the following error:

! LaTeX Error: Missing \begin{document} in `'.

Forcing the run to continue for the example below, I obtain a usable .html, but there is a erroneous span tag right at the beginning:

<span 
class="cmr-10">01 12</span>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
  "http://www.w3.org/TR/html4/loose.dtd">  

This example illustrates the problem:

\documentclass{article} 
\usepackage{filecontents} 

\begin{filecontents}{sample.bib} 
@article{Smith42,
    AUTHOR = {Smith}, 
    TITLE = {Some Title}, 
    JOURNAL = {Some Journal},
    YEAR = {1942},
}
@article{Aronson12,
    AUTHOR = {Aronson}, 
    TITLE = {Some Title}, 
    JOURNAL = {Some Journal},
    YEAR = {1912},
}
\end{filecontents}

\usepackage[style=numeric,defernumbers=true]{biblatex} 
% The following instead of the previous line works with tex4ht, but the numbering is not as desired.
%\usepackage[style=numeric]{biblatex} 

\bibliography{sample.bib} 

\DeclareBibliographyCategory{group1}
\DeclareBibliographyCategory{group2}
\addtocategory{group1}{Smith42}
\addtocategory{group2}{Aronson12,Smith42}

\begin{document} 
\nocite{*}
\printbibliography[category=group1]
\printbibliography[category=group2]
\end{document}

Note that the problem doesn't occur without the option defernumbers=true. I am using an up-to-date TL 2011 distribution, i.e., a biblatex.sty version 1.7 dated 2011/11/13 19:09:07 and biblatex.4ht dated 2011-09-18-16:07.

Is there a workaround for this that doesn't require editing the .bib file?

Best Answer

I'm not sure if this will help exactly with the problem above - but I'll try to jot down my debugging steps. I was using a customized bibliography sorting in biblatex, which then requires biber - and, all being good in the PDF - as soon as I wanted to build this using htlatex, biber, htlatex - I got the above error (only when the .aux file is present)..

So first I get something like:

! LaTeX Error: Missing \begin{document} in `'.
See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...
l.29 ...backref{1}{myfirstcite}{0}{4}{4}

I search with grep through files to find this ...backref{1}{myfirstcite} - and it turns out it is in the .aux file; contents around that line look like this:

...
\select@language{american}
\@writefile{toc}{\defcounter {refsection}{0}\relax }\@writefile{toc}{\select@language{american}}
\@writefile{lof}{\defcounter {refsection}{0}\relax }\@writefile{lof}{\select@language{american}}
\@writefile{lot}{\defcounter {refsection}{0}\relax }\@writefile{lot}{\select@language{american}}
\abx@aux@backref{1}{myfirstcite}{0}{4}{4}
\abx@aux@page{1}{4}
...

So I go back, run htlatex again - and now when it stops at error, I press 'I' in the shell to insert, and then just type \show and ENTER (ENTER maybe twice) - this spits an additional error message:

?
! Extra }, or forgotten \endgroup.
\abx@aux@backref ...{#2}}{#4}}\blx@addpagesum {#1}
                                                  {#5}
l.29 ...backref{1}{myfirstcite}{0}{4}{4}

Ok, so by now, I'm pretty sure tex4ht doesn't like \abx@aux@backref.

So, I search first for the macro \abx@aux@page - and it turns out it is present in biblatex.4ht file (from tex4ht); a snippet looks like:

%biblatex.4ht
%
% ...
  \def\abx@aux@page#1#2{\blx@addpagesum{#1}{#2}}%
  \def\abx@aux@fnpage#1#2{\blx@addpagesum{#1}{#2}}}
% ...

... but it also appears in biblatex.sty (from biblatex).

Then I search for \abx@aux@backref - and, as suspected - this one is defined in biblatex.sty, but not in biblatex.4ht; which is probably the reason why it crashes.

Now, \abx@aux@backref contains an @, meaning I'd have to define it in between \makeatletter/\makeatother - somewhere in the preamble after both biblatex and tex4ht are loaded. However, often times in similar cases I just do \let\abx@aux@backref\relax - but, that will not work here, because the original command always has five arguments.

So, after another search through biblatex.sty, I find: "\protected\def\blx@aux@backref#1#2#3#4#5{..." - and while that is not the same command, it is certainly to related to something @aux@backref ... So, in the end I put this in my preamble:

\makeatletter
\def\abx@aux@backref#1#2#3#4#5{}
\makeatother

... and now the htlatex, biber, htlatex combo seems to pass for me?!

 

Well, not sure how right I am about all this - but certainly hope it helps,
Cheers!