1

My tex4ebook ebook is formated in utf8. However, in the Kindle preview, characters are not shown correctly. Indeed, Kindle publishing seems to require latin1 encoding ... ( https://kdp.amazon.com/en_US/help/topic/G200652310 ) .

If I put \usepackage[latin1]{inputenc} in the tex header, the tex4ebook output (xhtmls) is still in utf8 (independently of the tex file encoding). If I convert the epub to latin1 with calibre, the result is also not satisfying.

Is there are way to tell tex4ebook to create latin1 output? Or should I manually convert all xhtmls and then rebuild the epub somewhow?

Kind regards

1
  • 2
    It is really strange. Isn't this document obsolete? It would mean that you cannot have Kindle ebooks in languages that don't support Latin 1. I am pretty sure that there are Kindle ebooks in Czech, that contains characters besides Latin 1. Moreover, Epub requires UTF-8 output, so tex4ebook always produced this encoding by default. It should be possible to support Latin 1 if it was really necessary, for example using iconv, but I think the real issue must be something else.
    – michal.h21
    Jan 12, 2021 at 19:19

1 Answer 1

0

I don't think this issue is caused by UTF-8 encoding, I am pretty sure that it is supported by Kindle. But anyway, it is not hard to change the encoding of the HTML file, using make4ht build file and filters.

Save the following code as mybuild.lua:

local filter = require "make4ht-filter"

local process = filter {
  function(s)
    return s:gsub("charset=utf%-8", "charset=ISO 8859-1")
  end
}
Make:match("html$", "iconv -f utf-8 -t latin1 ${filename}")
Make:match("html$", process)

The two Make:match commands will modify every output HTML file.

Make:match("html$", "iconv -f utf-8 -t latin1 ${filename}")

This command converts HTML file from utf8 to latin 1 using the Iconv command.

Make:match("html$", process)

This command calls the process function to modify the HTML file. We need to change the encoding that is specified in the HTML file. We can use just simple Lua string substitution command:

local process = filter {
  function(s)
    return s:gsub("charset=utf%-8", "charset=ISO 8859-1")
  end
}

The filter command is provided by make4ht-filter library and it enables to chain multiple functions that changes contents of the processed file and then saves it.

Compile using

tex4ebook -e mybuild.lua filename.tex

Sample TeX source:

\documentclass{article}
\begin{document}
diacritics: òíéú
\end{document}

Resulting HTML file:

<?xml version='1.0' encoding='utf-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns='http://www.w3.org/1999/xhtml'> 
<head><title></title> 
<meta content='text/html; charset=ISO 8859-1' http-equiv='Content-Type' /> 
<meta content='TeX4ht (https://tug.org/tex4ht/)' name='generator' /> 
<meta content='TeX4ht (https://tug.org/tex4ht/)' name='originator' /> 
<!--  xhtml,charset=ISO 8859-1,epub,uni-html4,html  --> 
<meta content='sample.tex' name='src' /> 
<link type='text/css' href='sample.css' rel='stylesheet' /> 
</head><body>
<!-- l. 3 --><p class='noindent'>diacritics: òíéú </p>    
 
</body></html>
3
  • Thank you very much for the answer! You were right, the issue is not due to the UTF-8 coding. The issue appeared in Amazon's "look inside", that always takes some time to update - so it is hard to evaluate (at least for me having no experience with ebooks). The issue was still there with an epub3 version that had passed epubcheck without errors. But everything was suddenly fine with an epub2 version (also created with tex4ebook).
    – Hartmut
    Jan 16, 2021 at 9:13
  • However, I don't think it was really due to epub2/epub3 because in the epub2 version I corrected also other inaccurracies that were pointed out during a subscription process (more strict than epubcheck). Unfortunately I can't narrow it down in a better way. In any case, it is (hopefully) fine now. Good to know that latex is still the right horse (in my view) and that it's easy to produce good ebooks with tex4ebook (and still being able to export in other formats). More precisely, it is easy thanks to your great support! Thanks again. Still, I am sure that it was not my last question :-)
    – Hartmut
    Jan 16, 2021 at 9:17
  • @Hartmut I am glad I could help and that you found TeX4ebook useful! It is sad that Amazon don't support Epub 3 and instead pushes it's own inferior format. They don't even provide Kindlegen anymore, so it is impossible to convert Epub to their formats from the command line.
    – michal.h21
    Jan 16, 2021 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.