[tex4ht] Fwd: Getting rid of <span class="cmr-9"> breaks in footnotes

Michal Hoftich michal.h21 at gmail.com
Sat Jul 4 15:13:12 CEST 2020

On Sat, Jul 04, 2020 at 07:50:41AM +0200, Jürgen Hubert wrote:
>Unfortunately, the problem persisted even after this change. I investigated further by manually editing the EPUB file with Calibre, and it turns out that the problem wasn't actually the </span><span> tags - it was the line break between "the" and "Devil". The empty spaces _also_ seem to be displayed in the popup.
>Yes, Amazon - one of the biggest companies in the world with massive amounts of IT resources - is unable to interpret HTML correctly with their "popup footnote" feature.

I am always amazed how bad ebook readers are. The only evolution that 
happens is on the hardware side, stuff like backlighting, etc. But the 
actual rendering is still awfull and nobody seems to have problem with 
that. And then comes stuff like footnotes that are displayed as popups, 
instead of, you know, as footnotes are displayed in books for last few 
hundreds of years. 

And of course, even this awfull way is broken. I lost my hope in ebooks 
long ago, but this is another level.

>So, uhm, do you see any way of eliminating this line break and the unnecessary empty spaces while compiling the EPUB file?
>Otherwise I will just have to resign myself to either trying to fix this via half-remembered Unix regex commands (wince) or fixing my footnotes manually (double wince). It will be a chore, but it won't prevent publication...

Fortunatelly, we can use make4ht build files. Using the built-in XML 
processing, it is easy to normalize white spaces inside footnotes:

local domfilter = require "make4ht-domfilter"

local function process_footnote(footnote)
   for _, node in ipairs(footnote:get_children()) do
     if node:is_text() then
       -- replace multiple white space with just obe space
       node._text = node._text:gsub("%s+", " ")
     elseif node:is_element() then
       -- recursivelly process child elements, like italics etc.
   return footnote
local process = domfilter {
     for _, footnote in ipairs(dom:query_selector(".footnote-text")) do
     return dom

Make:match("html$", process)

Save it as for example `mybuild.lua` and require using the `-e` option.

Best regards,

More information about the tex4ht mailing list.