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.

user41974
  • 841

1 Answers1

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

michal.h21
  • 50,697
  • 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 '20 at 00:14
  • Actually it doesn't quite work - see update. – user41974 Oct 27 '20 at 03:19
  • 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 '20 at 11:52
  • Thanks for looking into this, though I still don't understand why it doesn't work now and it was ok with texlive 2019. – user41974 Oct 28 '20 at 00:20
  • 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 '20 at 10:34
  • It still doesn't work - please see update 2. – user41974 Oct 28 '20 at 22:55
  • @michael.h21 Sorry, it works if I don't use the config file. Space issue is still there. – user41974 Oct 28 '20 at 23:04
  • @michael.h21 Is there a way to fix the missing space in the TOC, thanks. – user41974 Nov 06 '20 at 04: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 06 '20 at 19:34
  • @michael.h21 Using the new build file and running command tex4ebook -a info -c ebook.cfg -e mybuild.mk4 sample.tex works. Will \nobibintoctrue in ebook.cfg and the ncx commands in mybuild.mk4 still be needed with the new version of tex4ebook, thanks. – user41974 Nov 07 '20 at 02: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 07 '20 at 22:11
  • @michael.h21 I still need \nobibintoctrue in ebook.cfg even with the new tex4book (texlive now has new version) otherwise get duplicate bibliography entries in TOC. – user41974 Nov 09 '20 at 04:09
  • @michael.h21 With the latest version of tex4ebook on texlive and using epub3 output the \nobibintoctrue is not needed, thanks. – user41974 Nov 12 '20 at 02:18
  • @user41974 that's great! – michal.h21 Nov 12 '20 at 08:31