1

This is a followup of this question.

sample.tex:

\documentclass[ebook,12pt,oneside,openany]{memoir}

\begin{filecontents}{test.bib}
@book{Hiemenz,
author={Hiemenz},
title={Polymer Chemistry}
}
\end{filecontents}

\usepackage{biblatex}
\bibliography{test}

\title{Book}
\author{Author}
\date{}

\begin{document}

\maketitle

\tableofcontents \newpage

\chapter{C1}

Here comes a quotation \cite{Hiemenz}.

\printbibliography

\end{document}

mybuild.mk4:

Make:add("biber","biber ${input}")
Make:htlatex {}
Make:biber {}
Make:htlatex {}
Make:htlatex {}
Make:htlatex {}

command:

tex4ebook -e mybuild.mk4 sample.tex

This gives two entries for the bibliography in the table of contents (see picture).

toc for ebook

It used to work in previous versions like Texlive 2019.

How can this be fixed thanks.

Update:

Using the config file suggested by @michal.h21 still has a problem with the contents since the bibliography doesn't show on the contents :

texlive 2020

Running on texlive 2019 (without the config file) is fine:

texlive 2019

Update 2:

Here is what I get with the new build file.

result for new version of build file

The bibliography is gone. Also a minor error - 1 C1 is shown as 1C1 in TOC.

Also for my information, does the fix have to be in the build file and not the tex4ebook source. I think it would be easier for the user if he doesn't have to add things to the build file.

Thanks again.

2
  • 2
    Instead of \bibliography use \addbibresource
    – Guido
    Oct 26, 2020 at 4:06
  • Doesn't help, problem is still there.
    – user41974
    Oct 26, 2020 at 6:26

1 Answer 1

2

Edit: it seems that my original solution also removes bibliography from TOC, which is not desired

Here is alternative using make4ht build file:

local domfilter = require "make4ht-domfilter"
local filter = require "make4ht-filter"

-- process the NCX file, it contains bookmarks
local ncxprocess = domfilter {
  function(dom)
    for _, navpoint in ipairs(dom:query_selector("navPoint")) do
       -- get section text, trim spaces and make it lowercase
       local text = navpoint:query_selector("text")[1]:get_text():gsub("^%s*", ""):gsub("%s*$", ""):lower()
       -- match bibliography
       if text == "bibliography" then
         -- remove first bibliography node
         navpoint:remove_node()
         -- and break processing. the second bibliography booksmark will be preserved
         break
       end
    end
    for _, el in ipairs(dom:query_selector("text")) do
      local text = el:get_text()
      -- replace element text with a new text node containing original text
      el._children = {el:create_text_node(text)}
    end

    return dom
  end
}

local ncxclean = filter {
  function(s)
    -- remove unvanted spaces at the start of the NCX file
    local s=s:gsub("^%s*", ""):gsub("%s*$", "")
    return s
  end
}

Make:add("biber","biber ${input}")

-- use tex4ebook -m draft to speed up compilation, it is not necessary to execute biber and multiple LaTeX calls
-- every time you compile the document
if mode=="draft" then
  Make:htlatex {}
else
  Make:htlatex {}
  Make:biber {}
  Make:htlatex {}
  Make:htlatex {}
  Make:htlatex {}
end

-- the NCX file at this point is not valid XML, we need to clean it using Tidy first
-- Make:match("ncx$", "tidy -m -xml -utf8 -q -i ${filename}")
Make:match("ncx$", ncxclean)
-- remove bibliography
Make:match("ncx$", ncxprocess)

It uses LuaXML DOM processing methods to find the first bibliography section and removes it from the bookmarks.


TeX4ebook adds all sectioning commands, including starred versions to the bookmarks. Memoir uses the starred command, but in addition to that, it also adds a bibliography to TOC. You can disable the additional TOC entry using this config file:

\Preamble{xhtml}
\begin{document}
\nobibintoctrue
\EndPreamble

The resulting bookmarks:

enter image description here

14
  • Thank you, it works now. For my reference, what changed - was it memoir or tex4ebook. As I said it worked on texlive 2019.
    – user41974
    Oct 27, 2020 at 0:14
  • 1
    @user41974 ah, I see. Maybe it will be easiest to remove the duplicate entry using Lua scripting. I will try it later.
    – michal.h21
    Oct 27, 2020 at 11:52
  • 1
    @user41974 I've updated my answer. I think we didn't add starred sections to bookmarks in the past, but this resulted in missing bibliography or index sections in bookmarks with default classes.
    – michal.h21
    Oct 28, 2020 at 10:34
  • 1
    @user41974 This is actually a bug in tex4ebook. I've updated the tex4ebook sources. In the meantime, you can try the updated .mk4 file that should fix the spacing issue.
    – michal.h21
    Nov 6, 2020 at 19:34
  • 1
    @user41974 you shouldn't beed the .cfg file with this build file. The TeX4ebook update should fix the space issue, I don't have any good solution for the duplicate TOC entry unfortunatelly.
    – michal.h21
    Nov 7, 2020 at 22:11

You must log in to answer this question.

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