3

I'm trying to use tex4ebook to generate an epub file from a project in LaTeX. The original project, targetting pdf, uses XeLaTeX and the package xeCJK, and works fine.

With tex4ebook, I get the following error if the package xeCJK is included:

tex4ht warning: package xeCJK was prevented from loading
! Undefined control sequence.
l.98 \DeclareDocumentCommand
                            \setCJKmainfont{o m o}{}

If I remove xeCJK, it seems to work, the ebook is genterated and everything is fine, except that all the text in Japanese simply disappears.

I've reduced the file to a minimum working example, which generates the expected pdf file perfectly.

The .tex file is the following:

\documentclass[a5paper,10pt,openright]{book}
%\usepackage{xeCJK}
\usepackage[portuguese]{babel}
\begin{document}
!!START JAPANESE TEXT!!
三里塚闘争は、千葉県成田市の農村地区名称である三里塚とその近辺で継続している成田市・芝山町の地元住民及び新左翼活動家らによる新東京国際空港(成田国際空港)の建設・存続に反対する闘争のことを指す。成田闘争とも呼ばれる。
!!END JAPANESE TEXT!!
\end{document}

The command I'm using is the following:

tex4ebook -x -f epub ebooktest.tex

I've been looking around but so far I haven't found a way to make it work.

1
  • 1
    works fine for me in current texlive 2023. Jul 3, 2023 at 19:52

1 Answer 1

3

It seems that you may have an older installation. With up-to-date TeX Live 2023, it works. Even with the older installation, you can compile it and get the Japanese text if you don't use the xeCJK package and compile your file with LuaTeX instead of XeTeX. With LuaTeX, TeX4ht can keep all Unicode characters used in your document in a much more robust way than with XeTeX. Your modified example can look like this:

\documentclass[a5paper,10pt,openright]{book}
\ifdefined\HCode\else
\usepackage{xeCJK}
\fi
\usepackage[portuguese]{babel}
\begin{document}
!!START JAPANESE TEXT!!
三里塚闘争は、千葉県成田市の農村地区名称である三里塚とその近辺で継続している成田市・芝山町の地元住民及び新左翼活動家らによる新東京国際空港(成田国際空港)の建設・存続に反対する闘争のことを指す。成田闘争とも呼ばれる。
!!END JAPANESE TEXT!!
\end{document}

With this code, the xeCJK package is ignored with TeX4ht:

\ifdefined\HCode\else
\usepackage{xeCJK}
\fi

You can now compile it using:

$ tex4ebook -l ebooktest.tex

And this is the result:

enter image description here

4
  • I've tried LuaTex for that purpose, but it gave so much more trouble that I gave up. I'll certainly have a look at it with more attention now. Thanks! Jul 3, 2023 at 20:42
  • As for the installation, it is the most recent Debian version; but I understand that's usually not the latest version available for individual packages. Jul 3, 2023 at 20:44
  • I've checked and it's version 2018.20190227-2 (oldoldstable) 😐 I didn't imagine it would be THAT old. Jul 3, 2023 at 20:51
  • @SérgioDomingues 2018 is really old, so it is not a surprise that things don't work well, a lot of bugs were fixed in the meantime.
    – michal.h21
    Jul 4, 2023 at 10:09

You must log in to answer this question.

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