3

There is nothing wrong with generating the epub file with the following code:

\documentclass{ctexart}

\begin{document}
Hello World
$x_1$
\end{document}
$ tex4ebook -f epub3 ./demo.tex

But when inserting unicode characters:

\documentclass{ctexart}

\begin{document}
你好!世界!
\end{document}

The following error occurs:

[STATUS]  tex4ebook: Conversion started
[STATUS]  tex4ebook: Input file: ./demo.tex
--- warning --- Couldn't find font `unisong75.htf' (char codes: 0--255)

----------------------------------------------------
environment file
----------------------------------------------------
% unix/tex4ht.env (2019-03-07), generated from tex4ht-env.tex, and
% modified by hand for TeX Live (unix).
% Copyright 2009-2019 TeX Users Group
% Copyright 1997-2009 Eitan M. Gurari
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Notes:                                                            %
%  1. Empty lines might be harmful                                  %
%  2. Tagged script segments <tag>...</tag> are scanned only if     %
%     their names are specified within -ctag switches of tex4ht.c   %
%     and t4ht.c. When -c switches are not supplied, a -cdefault    %
%     is implicitly assumed.                                        %
%        The tags <tag> and </tag>, but not their bodies, are       %
%     ignored if they are not located at the start of their lines.  %
%  3. Place this file in your work directory and/or root directory  %
%     and/or in directory `xxx' of your choice. In the latest case, %
%     compile tex4ht.c and t4ht.c with `#define ENVFILE xxx', or    %
%     provide the address of the file to tex4ht and t4ht throught   %
%     the -e switch                                                 %
%  4. Under kpathsea, the substring `%%~' may be employed in        %
%     commands to indirectly obtain the value of ${TEXMFDIST}.      %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% * Replace `path', and possibly what follows, with appropriate     %
%   content                                                         %
% * A path may start with:                                          %
%   ~ for environment variable HOME                                 %
%   ~~ for environment variable TEX4HTTFM                           %
%   %%~ for ${TEXMFDIST} of KPATHSEA                                %
% * A ! requests recursive search into subdirectories               %
% * Multiple t and i entries are allowed                            %
% * When supported by kpathsea                                      %
%   + t entries are ignored                                         %
%   + the path before /ht-fonts/ is ignored in i records that don't %
%     represent real addresses                                      %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
tpath/tex/texmf/fonts/tfm/!
......
----------------------------------------------------
--- warning --- Couldn't find font `unisong4e.htf' (char codes: 0--255)
--- warning --- Couldn't find font `unisongff.htf' (char codes: 0--255)
--- warning --- Couldn't find font `unisong59.htf' (char codes: 0--255)
--- warning --- Couldn't find font `unisong4f.htf' (char codes: 0--255)

What should I do to make tex4ebook support unicode characters?

0

2 Answers 2

4

Seems tex4ebook doesn't support ctexart class. This is working for me:

\documentclass{article}
\usepackage{ctex}
\begin{document}
你好!世界!
\end{document}
$ tex4ebook -f epub3 -l ./demo.tex
1

The problem is that ctexart uses fonts that are not supported by TeX4ht, as can be seen from your terminal output:

--- warning --- Couldn't find font `unisong75.htf'

The .htf files contain the mapping between font characters and Unicode characters. Without them, you cannot get correct text, especially for non-Latin texts. In further investigation, I found that there is a mapping for these fonts, but for their older version, where they were named differently. So it was just a matter of renaming the .htf files to the correct names. I've updated TeX4ht sources, so if you use TeX Live, the correct version should be available in a few days.

In the meantime, you can use LuaLaTeX to compile your file. You need to use some TeX4ht configuration files to prevent errors, but then it should compile.

Firstly, we need to tell TeX4ht, that we want to load configuration file before the class itself. It can be done in the usepackage.4ht file:

% usepackage.4ht (2022-03-16-14:13), generated from tex4ht-4ht.tex
% Copyright 2003-2009 Eitan M. Gurari
% Copyright 2009-2022 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2022-03-16-14:13}

   \def\:temp{tex4ht}\ifx \:temp\@currname
   \:warning{\string\usepackage{tex4ht} again?}
   \def\:temp#1htex4ht.def,tex4ht.sty#2!*?: {\def\:temp{#2}}
\expandafter\:temp \@filelist htex4ht.def,tex4ht.sty!*?: %
\ifx \:temp\empty  \else
   \:warning{if
    \string\RequirePackage[tex4ht]{hyperref} or
    \string\usepackage[tex4ht]{hyperref} was
    used try instead, repectively,
    \string\RequirePackage{hyperref} or
    \string\usepackage{hyperref}}
\fi

\fi
\gdef\a:usepackage{\use:package ,!*?: }
\gdef\use:package#1,{%
   \if :#1:\def\:temp##1!*?: {}\else
      \def\:temp{#1}\ifx \@currname\:temp
             \def\:temp##1!*?: {\input usepackage.4ht  }%
      \else \let\:temp=\use:package \fi
   \fi \:temp}
\Configure{PackageHooks}{titlesec.sty}{titlesec-hooks.4ht}
\Configure{PackageHooks}{biblatex-chicago.sty}{biblatex-chicago-hooks.4ht}
\Configure{PackageHooks}{cleveref.sty}{cleveref-hooks.4ht}
\Configure{PackageHooks}{xr.sty}{xr-hooks.4ht}
\Configure{PackageHooks}{xr-hyper.sty}{xrhyper-hooks.4ht}
\Configure{PackageHooks}{eso-pic.sty}{esopic-hooks.4ht}
\Configure{PackageHooks}{showframe.sty}{showframe-hooks.4ht}
\Configure{PackageHooks}{expl3.sty}{expl3-hooks.4ht}
\Configure{PackageHooks}{savetrees.sty}{savetrees-hooks.4ht}
\Configure{PackageHooks}{newcomputermodern.sty}{newcomputermodern-hooks.4ht}
\Configure{PackageHooks}{newcomputermodern.sty}{newcomputermodern-hooks.4ht}
\Configure{PackageHooks}{fontawesome5-utex-helper.sty}%
{fontawesome5-utex-helper-hooks.4ht}
\Configure{PackageHooks}{fontawesome5.sty}{fontawesome5-hooks.4ht}
\Configure{PackageHooks}{biblatex.sty}{biblatex-hooks.4ht}
\Configure{PackageHooks}{xeCJK.sty}{xecjk-hooks.4ht}
\Configure{PackageHooks}{unicode-math.sty}{unicode-math-hooks.4ht}
\Configure{PackageHooks}{ctex.sty}{ctex-hooks.4ht}
% \Configure{PackageHooks}{ctexart.cls}{ctexart-hooks.4ht}
\Configure{PackageHooks}{polyglossia.sty}{polyglossia-hooks.4ht}
\Configure{PackageHooks}{fontspec.sty}{fontspec-hooks.4ht}
\Configure{PackageHooks}{tikz.sty}{tikz-hooks.4ht}
\Configure{PackageHooks}{pdfbase.sty}{pdfbase-hooks.4ht}
\Configure{PackageHooks}{pdfx.sty}{pdfx-hooks.4ht}
\Configure{PackageHooks}{breakurl.sty}{breakurl-hooks.4ht}
\Configure{PackageHooks}{hyperref.sty}{hyperref-hooks.4ht}
\Configure{PackageHooks}{caption.sty}{caption-hooks.4ht}
\Configure{PackageHooks}{minted.sty}{minted-sty-hooks.4ht}
\Configure{PackageHooks}{graphics.sty}{graphics-hooks.4ht}
\Configure{PackageHooks}{graphbox.sty}{graphbox-hooks.4ht}
\Configure{PackageHooks}{xcolor.sty}{xcolor-hooks.4ht}
\Configure{PackageHooks}{imakeidx.sty}{imakeidx-hooks.4ht}
\Configure{PackageHooks}{fancyhdr.sty}{fancyhdr-hooks.4ht}
\Configure{PackageHooks}{exerquiz.sty}{exerquiz-hooks.4ht}
\Configure{PackageHooks}{hyperxmp.sty}{hyperxmp-hooks.4ht}
\Configure{PackageHooks}{datetime2.sty}{datetime2-hooks.4ht}
\AddToHook{class/ctexart/before}{\input{ctexart-hooks.4ht}}    

\endinput

And the ctextart-hooks.4ht file, which fixes fatal errors:

\ExplSyntaxOn

% prevent multiple execution of this file
\ifdefined\l_save_engine_str\endinput\fi
\str_new:N \l_save_engine_str 
% stop processing if the engine is pdftex, we want to change processing only for LuaTeX
\def\l_save_engine_str{pdftex}
\str_if_eq:NNTF \c_sys_engine_str\l_save_engine_str{\ExplSyntaxOff\endinput}{}

% the luatexja package causes fatal error
\:dontusepackage{luatexja}

% fix compilation errors 
\AddToHook{package/ctexhook/after}{
  % don't let ctex to insert any files
  \cs_set:Npn \ctex_file_input:n #1{}
  % define some macros that are declared in the input files, and which are needed in the class
  \cs_set:Npn \ctex_add_to_selectfont:n #1{}
  \dim_new:N \ccwd
  \skip_new:N \l__ctex_ccglue_skip
  \cs_set_protected:Npn \ctex_update_em_unit:
  { \dim_set:Nn \ccwd { \f@size \p@ } }
  \cs_set_protected:Npn \ctex_update_ccglue: {}
}


\ExplSyntaxOff
\endinput

You can then compile your file using:

 $ tex4ebook -l -f epub3 demo.tex

And this is the result:

enter image description here

You must log in to answer this question.

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