12

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?

lockstep
  • 250,273
  • Apparently the above example works fine nowadays. I just tested it in Arch Linux with htlatex from texlive-core version 2022.63035-1 and the current biber from the community repo. However, the automatic generation of sample.bib only worked for me after removing \usepackage{filecontents} and changing \begin{filecontents}{sample.bib} into \begin{filecontents}[overwrite]{sample.bib}. – Manfred Sauter Jun 20 '22 at 23:33

2 Answers2

6

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!

sdaau
  • 17,079
  • This is perfect! Everything works now that I have that mysterious blx@aux@backref stuff in my preamble. Surely the biblatex people or the tex4ht people can do something about this, since it is fixable. – Andrew Aug 29 '12 at 19:55
  • In my example the htlatex run fails with l.9 \abx@aux@number{0}{Smith42}{0}{1} (at least for me). If I just blank out \abx@aux@number like you did with \abx@aux@backref, then htlatex indeed passes. However, the html output does not reflect the option defernumbers=true (i.e., the numbering is the standard one). – Manfred Sauter Nov 23 '12 at 06:00
1

The biblatex.4ht which you use is incompatible with biblatex 1.7. You can use http://von-wachter.de/dateien/for-biblatex-1-6/biblatex.4ht with http://sourceforge.net/projects/biblatex/files/biblatex-1.6/.

user14744
  • 161
  • Well, I think that I had tried this already before I posted my question here. Anyhow, I gave your suggestion a try and downgraded to biblatex-1.6 using the above biblatex.4ht. For my MWE it behaves exactly the same, i.e., it gives the same error and the same defective html output. – Manfred Sauter Nov 23 '12 at 06:21