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}
rasha
  • 704
  • 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 '20 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 '20 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 '20 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 '20 at 16:53
  • 1
    @moewe I've found that it is on the mailing list: https://tug.org/pipermail/tex4ht/2020q1/002441.html the issue is caused by custom bibmacros – michal.h21 Feb 24 '20 at 17:12
  • @michal.h21 Thanks! – moewe Feb 24 '20 at 17:12
  • @rasha Please always include links to the other places if you double post. That makes it easier for people with a similar problem to find all info. And it also makes it easier for people to help you. At the very least it means that people don't solve a problem that has already been solved. – moewe Feb 24 '20 at 17:13
  • It appears to me that the question should have been about the last MWE in the question of https://tex.stackexchange.com/q/346564/35864. With that example I can indeed reproduce an error. – moewe Feb 24 '20 at 17:36
  • @michal.h21 Yes, with the example in https://tex.stackexchange.com/q/346564/35864 I can reproduce an error, I guess the fact that the bibmacro tries to start a new \section* within the bibliography (which is already a list) and issues \item is too much for tex4ht. And frankly I'm a bit surprised that LaTeX seems to be cool with this. – moewe Feb 24 '20 at 17:38
  • @moewe yes, this cannot work with TeX4ht, the custom macro needs to be polished – michal.h21 Feb 24 '20 at 18:14
  • @michal.h21 thank you very much. Indeed I messed up with the MWE and you found the right one. I'll be able to check the solution as soon as I'm back in 10-days. Thanks a lot. – rasha Feb 28 '20 at 07:12
  • @moewe I succeeded sending an email in turg.org , as you advised me, but I did not succeed to find my email on the website. I'm quite not familiar with turg.org. Hence I could not point out my question. Sorry for that. – rasha Feb 28 '20 at 07:17
  • @michal.h21, the solution works fine. However, the special characters, like the opening and closing quotes, french accents, ... are note printed correctly. I need an additional htlatex compilation (with no option) to get them printed correctly. Do I need to set up any particular option in make4ht? – rasha Mar 10 '20 at 14:05
  • @rasha I guess there may be an issue with French Babel, if you use this package. It would be best to post this issue as a separate question. – michal.h21 Mar 10 '20 at 14:18
  • @michal.h21, what should be changed to get the years printed as

    -level titles? (Example

    2013

    )? I'd like also the titles "Journal Articles", "Conference papers", "patents" be printed as

    -level tags. Actually, the desired output should look like: http://malti.fr/index.php/publications

    – rasha Mar 10 '20 at 14:19
  • @michal.h21, regarding the special characters, the issue seems not to be related to french babel. I commented the use of french babel and yet the opening and closing quotes do not print correctly, even in the MWE, you posted below. It disappears with an additional htlatex compilation. It seems to be related to make4ht. – rasha Mar 10 '20 at 14:30
  • @rasha change tags in \renewcommand\printyear and \renewcommand\bibsection from <div class=...> to <h3> and <h4> – michal.h21 Mar 10 '20 at 14:32
  • @rasha I cannot find the wrong quotes in the example. I've also tried to add accented characters and they seem to work correctly. – michal.h21 Mar 10 '20 at 14:54
  • @michal.h21, regarding the special characters I found that the option -u was required, indicating an UTF8-type of coding. So the problem is solved using: make4ht -u -c mycfg.cfg filename.tex – rasha Mar 11 '20 at 07:53
  • @michal.h21, how can I skip the indentation of all what follows "Publication list by year", in the html-output-file (see the output below)? – rasha Mar 11 '20 at 09:46
  • @rasha in the current version of make4ht Unicode is used by default, so the -u option is not required. In the older version it is better to use i. – michal.h21 Mar 11 '20 at 10:27
  • @rasha it should be doable using CSS. I don't have access to the files right now so I cannot tell you what exactly is necessary. I hope to be able to access them on Friday – michal.h21 Mar 11 '20 at 10:29
  • @michal.h21, I'm facing another problem and spent all day long trying to resolve it without success. I've updated my MWE (check above), by adding 2 references of misc-type. I'd like these two references to be ignored because they are not of (Article, Inproceeding, or Patent type). Instead of ignoring them, the macro prints them at the end of the last type of references by reseting the numbering. I guess what should be done (but I don't know how to do it in LaTeX), it is to set entrytype to some dummy-value when the last condition \iffieldequalstr{entrytype}{patent} is false. – rasha Mar 11 '20 at 14:43
  • @rasha I think this needs to be ignored using \DeclareSourcemap. but I cannot get it to work – michal.h21 Mar 11 '20 at 19:32

1 Answers1

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

michal.h21
  • 50,697