2

The MWE below is issued from here

It compiles with no errors when using: Latex —> Biber —> Latex. Moreover, it produces exactly the desired result.

However, when compiling using: htlatex —> Biber —> htlatex, it produces the following kind of warnings at the second htlatex compilation:

l.310 --- TeX4ht warning --- Problem with 'list' environment. Expected syntax:
\begin{list}{label}{spacing} \item.... \end{list} ---
! Missing number, treated as zero.
<to be read again>
                   \c:\end:itm
l.310 ...ography[title={Publication list by year}]

?

Moreover, it skips all newlines, corresponding to new bib entries, in the html file, which seems to be in direct connexion with the warning message.

Is it an incompatibility or a bug? Any help or workaround will be very much appreciated.

Here is the MWE: [EDITED: adding 2 @misc references to the right MWE]

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}

@Article{c,
  date =     2020,
  author =   {Author, BBB},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Misc{hh,
  date =     2003,
  author =   {Misc, Misc},
  title =    {Misc},
  journaltitle = {Misc},
  pages =    {100-141}}

@Report{hh2,
  date =     2020,
  author =   {Misc, Misc},
  title =    {Misc},
  journaltitle = {Misc},
  pages =    {100-141}}

@Misc{hh3,
  date =     2005,
  author =   {Misc, Misc},
  title =    {Misc},
  journaltitle = {Misc},
  pages =    {100-141}}

@Article{d,
  date =     2003,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{i,
  date =     2016,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@patent{l,
  year =     2016,
  author =   {Author, Amy},
  title =    {Patent 1},
  number =   4,
  pages =    {100-141}}

@inproceedings{j,
  date =     2020,
  author =   {Author, Amy},
  title =    {Title 1},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@patent{o,
  year =     2016,
  author =   {Author, Amy},
  title =    {Patent 1},
  number =   4,
  pages =    {100-141}}

 @patent{m,
  year =     2016,
  author =   {Author, Amy},
  title =    {Patent 2},
  number =   4,
  pages =    {100-141}}

@Article{n,
  date =     2016,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{b,
  date =     2003,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}


\end{filecontents*}

\usepackage[backend=biber,defernumbers=true,sorting=ydnt]{biblatex}
\addbibresource{\jobname.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \pertype{article}
      \step[fieldset=presort,fieldvalue=article]
    }
    \map{
      \pertype{inproceedings}
      \step[fieldset=presort,fieldvalue=inproceedings]
    }
    \map{
      \pertype{patent}
      \step[fieldset=presort,fieldvalue=patent]
    }
  }
}

\DeclareSortingTemplate{rasha}{
  \sort[direction=ascending]{
    \field{year}}
  \sort{\field{presort}}
}

\defbibenvironment{bibliography}
  {\enumerate}
  {\endenumerate}
  {\item[]}

\newcounter{myyear}
\setcounter{myyear}{0}

\newcommand\printyear{\textbf{\hspace*{-\leftmargin}\printfield{year}}\par}
\newcommand\bibsection[1]{\hspace*{-\leftmargin}\textbf{#1}\par\noindent}
\newcommand\printenum{\stepcounter{enumi}\hspace*{-\leftmargin}\arabic{enumi}.\space}
\newcommand\mybibitem{\printenum}
\renewbibmacro{begentry}{%

\ifnumgreater{\thefield{year}}{\value{myyear}}
  {\printyear%
   \setcounter{myyear}{\thefield{year}}%
   \setcounter{enumi}{0}%
   \xdef\mylastentrytype{}%
   }%
  {}%
  \iffieldequals{entrytype}{\mylastentrytype}
  {}
    {%
      \setcounter{enumi}{0}%
      \iffieldequalstr{entrytype}{article}%
        {\bibsection{Journal Articles}}%
        { \iffieldequalstr{entrytype}{inproceedings}%
            {\bibsection{Conference Papers}%
            }%
            {\iffieldequalstr{entrytype}{patent}%
                {\bibsection{Patents}%
                 \setcounter{enumi}{0}%
                }%
                {}%
            }%
        }%
      \xdef\mylastentrytype{\thefield{entrytype}}%
    }%
    \mybibitem%
}

\begin{document}
\nocite{*}
    \begin{refcontext}[sorting=rasha]
        \printbibliography[title={Publication list by year}]
    \end{refcontext}
\end{document}
24
  • Do you have updated TeX distribution? I can compile your example without errors and the output looks identical to the PDF version.
    – michal.h21
    Feb 24, 2020 at 13:50
  • @Michael.h21 thanks for your answer. I'll be able to check the distribution in 2 weeks time (as I'm out of office). But it seems to me that I was up to date.
    – rasha
    Feb 24, 2020 at 15:35
  • The example compiles fine for me with MikTeX's tex4ht/htlatex 2018-07-03-10:36. (In case the was any doubt, the output is as I expected. It looks pretty much like the PDF.)
    – moewe
    Feb 24, 2020 at 16:44
  • 1
    @rasha I've also checked mwe you posted on TeX4ht issue tracker and it fails to compile, so maybe you just posted wrong code here.
    – michal.h21
    Feb 24, 2020 at 16:53
  • 1
    @moewe I've found that it is on the mailing list: tug.org/pipermail/tex4ht/2020q1/002441.html the issue is caused by custom bibmacros
    – michal.h21
    Feb 24, 2020 at 17:12

1 Answer 1

4

This example works for me, but I suppose you actually wanted to use the example you posted on TeX4ht mailing list. This example actually fails with TeX4ht, it is caused by custom bibliography macros. Here is modified version that works both in PDF and HTML:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}

@Article{b,
  date =     2003,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{c,
  date =     2003,
  author =   {Author, BBB},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{d,
  date =     2003,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{i,
  date =     2016,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@patent{l,
  year =     2016,
  author =   {Author, Amy},
  title =    {Patent 1},
  number =   4,
  pages =    {100-141}}

@inproceedings{j,
  date =     2016,
  author =   {Author, Amy},
  title =    {Title 1},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@patent{o,
  year =     2016,
  author =   {Author, Amy},
  title =    {Patent 1},
  number =   4,
  pages =    {100-141}}

 @patent{m,
  year =     2016,
  author =   {Author, Amy},
  title =    {Patent 2},
  number =   4,
  pages =    {100-141}}

@Article{n,
  date =     2016,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

\end{filecontents*}

\usepackage[backend=biber,defernumbers=true,sorting=ydnt]{biblatex}
\addbibresource{\jobname.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \pertype{article}
      \step[fieldset=presort,fieldvalue=article]
    }
    \map{
      \pertype{inproceedings}
      \step[fieldset=presort,fieldvalue=inproceedings]
    }
    \map{
      \pertype{patent}
      \step[fieldset=presort,fieldvalue=patent]
    }
  }
}

\DeclareSortingTemplate{rasha}{
  \sort[direction=ascending]{
    \field{year}}
  \sort{\field{presort}}
}



\defbibenvironment{bibliography}
  {\enumerate}
  {\endenumerate}
  {\item[]}

\newcounter{myyear}
\setcounter{myyear}{0}

\newcommand\printyear{\textbf{\hspace*{-\leftmargin}\printfield{year}}\par}
\newcommand\bibsection[1]{\hspace*{-\leftmargin}\textbf{#1}\par\noindent}
\newcommand\printenum{\stepcounter{enumi}\hspace*{-\leftmargin}\arabic{enumi}.\space}
\newcommand\mybibitem{\printenum}
\renewbibmacro{begentry}{%
\ifnumgreater{\thefield{year}}{\value{myyear}}
  {\printyear%
   \setcounter{myyear}{\thefield{year}}%
   \setcounter{enumi}{0}%
   \xdef\mylastentrytype{}%
   }%
  {}%
  \iffieldequals{entrytype}{\mylastentrytype}
  {}
    {%
      \setcounter{enumi}{0}%
      \iffieldequalstr{entrytype}{article}%
        {\bibsection{Journal Articles}}%
        { \iffieldequalstr{entrytype}{inproceedings}%
            {\bibsection{Conference Papers}%
            }%
            {\iffieldequalstr{entrytype}{patent}%
                {\bibsection{Patents}%
                 \setcounter{enumi}{0}%
                }%
                {}%
            }%
        }%
      \xdef\mylastentrytype{\thefield{entrytype}}%
    }
    \mybibitem%
}

The important part is this:

\defbibenvironment{bibliography}
  {\enumerate}
  {\endenumerate}
  {\item[]}

\newcounter{myyear}
\setcounter{myyear}{0}

\newcommand\printyear{\textbf{\hspace*{-\leftmargin}\printfield{year}}\par}
\newcommand\bibsection[1]{\hspace*{-\leftmargin}\textbf{#1}\par\noindent}
\newcommand\printenum{\stepcounter{enumi}\hspace*{-\leftmargin}\arabic{enumi}.\space}
\newcommand\mybibitem{\printenum}
\renewbibmacro{begentry}{%
\ifnumgreater{\thefield{year}}{\value{myyear}}
  {\printyear%
   \setcounter{myyear}{\thefield{year}}%
   \setcounter{enumi}{0}%
   \xdef\mylastentrytype{}%
   }%
  {}%
  \iffieldequals{entrytype}{\mylastentrytype}
  {}
    {%
      \setcounter{enumi}{0}%
      \iffieldequalstr{entrytype}{article}%
        {\bibsection{Journal Articles}}%
        { \iffieldequalstr{entrytype}{inproceedings}%
            {\bibsection{Conference Papers}%
            }%
            {\iffieldequalstr{entrytype}{patent}%
                {\bibsection{Patents}%
                 \setcounter{enumi}{0}%
                }%
                {}%
            }%
        }%
      \xdef\mylastentrytype{\thefield{entrytype}}%
    }
    \mybibitem%
}

\begin{document}
\nocite{*}
    \begin{refcontext}[sorting=rasha]
        \printbibliography[title={Publication list by year}]
    \end{refcontext}
\end{document}

It suppress printing of the item numbers in the bibliography environment, because it would print numbers even for sections:

\defbibenvironment{bibliography}
  {\enumerate}
  {\endenumerate}
  {\item[]}

The item numbers are printed explicitly instead:

\newcommand\printenum{\stepcounter{enumi}\hspace*{-\leftmargin}\arabic{enumi}.\space}

I've defined custom macros to print years and publication types, because it will allow us to apply custom formatting in TeX4ht.

This is the configuration file for TeX4ht, mycfg.cfg:

\Preamble{xhtml}

\renewcommand\printyear{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="bibyear">}\printfield{year}\HCode{</div>}\par}
\renewcommand\bibsection[1]{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="bibsection">}#1\HCode{</div>}\par}
\Css{.bibyear{font-size: 1.3em;  margin-top: 1em;font-weight: bold;}}
\Css{.bibsection{font-size: 1em;  margin-top: 1em;font-weight: bold;}}
\Css{.bibyear + .bibsection{margin-top: 0.5em;}}
\Css{.bibsection + p {margin-top: 0.5em;}}
\begin{document}
\EndPreamble

It just redefines the macros to insert some HTML tags and use CSS to style them.

Compile your document using

make4ht -c mycfg.cfg filename.tex

This is the HTML version:

enter image description here

And this is the PDF version:

enter image description here

You must log in to answer this question.

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