TransWikia.com

Double bibliography entries in table of contents with latest tex4ebook and texlive 2020

TeX - LaTeX Asked by user41974 on May 17, 2021

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.

One Answer

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

Correct answer by michal.h21 on May 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP