# Convert XeLaTeX to ePub

Hi all,

I have a XeLaTeX file which once compiled gives that kind of pdf page :

What I need is to have from the tex file an ePub format instead of the pdf one.

So before posting all this message, I tried some solutions I could find on the web like Pandoc, latexml, and others I don't remember. But for each one I got an error. So maybe, you could help me to resolve theses errors or maybe you could help me with a new tool to get ePub format I didn't know.

To have an idea of what looks like the XeLateX code, here it's a good preview (MWE) :

% !TEX encoding = UTF-8 Unicode
\documentclass[a4paper, 11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{fontspec}
\usepackage{lmodern}
\usepackage{array}
\usepackage{verbatim}
\title{{\myfont GA 032''}}
\usepackage{layout}
\usepackage[nomarginpar, margin=0.7in]{geometry}
\pagestyle{plain}

\usepackage{polyglossia}
\setmainlanguage{french}
\setotherlanguage{greek}
\newfontfamily\greekfont{KoineGreek}
\newsavebox\TBox
\def\textoverline#1{\savebox\TBox{#1}%
\makebox[0pt][l]{#1}\rule[1.1\ht\TBox]{\wd\TBox}{0.7pt}}
% amélioration : ajouter un "padding" sur le tabular + agrandir le tabular et son contenu.

\usepackage{pageslts}
\usepackage{fancyhdr}
\makeatletter
\newcommand{\nospace}[1]{\nofrench@punctuation\texttt{#1}\french@punctuation}
\makeatother
\let\oldtabular\tabular\renewcommand{\tabular}{\large\selectfont\oldtabular} %fontsize{17pt}{20.5pt}

\newcounter{gospelbook}
\setcounter{gospelbook}{1}
\newcommand{\mygospelbook}[1]

\newcounter{gospelchapter}

\begin{document}
\renewcommand{\contentsname}{Sommaire}
\font\myfont=cmr12 at 21pt
%\layout
\maketitle % affiche le nom du manuscrit.
\pagenumbering{roman}
\thispagestyle{empty}\clearpage\setcounter{page}{1}
\newpage
\foreignlanguage{greek}{\tableofcontents}
\clearpage\pagenumbering{arabic}\setcounter{page}{1}
\clearpage
\newpage
{
\setlength\arrayrulewidth{1pt}
\begin{table}
\begin{center}
\begin{tabular}{ccc|l|ccc}
\cline{4-4} \\ [-1em]
\multicolumn{7}{c}{\mygospelbook{\foreignlanguage{greek}{ευαγγελιον κατα μαθθαιον}} \textbf{(\nospace{1:1})} } \\ \\ [-1em] % Si on veut ajouter les bordures latérales, remplacer {7}{c} par {7}{|c|}
\cline{4-4} \\
\cline{4-4}
&  &  & &  &  & \\ [-0.9em]
& \mygospelchapter &  & \foreignlanguage{greek}{βιβλοϲ γενεϲεωϲ \textoverline{ιυ} \textoverline{χυ} υιου δαυειδ} & 6 &  &  \\
&  & 7 & \foreignlanguage{greek}{υιου αβρααμ αβρααμ εγεννηϲεν τον} & 3 & \textbf{2} &  \\
&  & 4 & \foreignlanguage{greek}{ιϲαακ ιϲαακ δε εγεννηϲεν τον ια} & 9 &  &  \\
&  & 9 & \foreignlanguage{greek}{κωβ ιακωβ δε εγεννηϲεν τον ιουδαν} & 14 &  &  \\
&  & 15 & \foreignlanguage{greek}{και τουϲ αδελφουϲ αυτου ιουδαϲ δε} & 2 & \textbf{3} &  \\
&  & 3 & \foreignlanguage{greek}{εγεννηϲεν τον φαρεϲ και τον ζαρα} & 8 &  &  \\
&  & 9 & \foreignlanguage{greek}{εκ τηϲ θαμαρ φαρεϲ δε εγεννηϲεν} & 14 &  &  \\
&  & 15 & \foreignlanguage{greek}{τον εζρωμ εζρωμ δε εγεννηϲεν το̅} & 20 &  &  \\
&  & 21 & \foreignlanguage{greek}{αραμ αραμ δε εγεννηϲεν τον αμινα} & 5 & \textbf{4} &  \\
&  & 5 & \foreignlanguage{greek}{δαβ αμιναδαβ δε εγεννηϲεν τον} & 9 &  &  \\
&  & 10 & \foreignlanguage{greek}{νααϲϲων νααϲϲων δε εγεννηϲε̅} & 13 &  &  \\
&  & 14 & \foreignlanguage{greek}{τον ϲαλμων ϲαλμων δε εγεννηϲε̅} & 3 & \textbf{5} &  \\
&  & 4 & \foreignlanguage{greek}{τον βοοζ εκ τηϲ ραχαβ βοοζ δε εγε̅} & 11 &  &  \\
&  & 11 & \foreignlanguage{greek}{νηϲεν τον ωβηδ εκ τηϲ ρουθ ωβηδ} & 17 &  &  \\
&  & 18 & \foreignlanguage{greek}{δε εγεννηϲεν τον ειεϲϲαι ιεϲϲαι δε} & 2 & \textbf{6} &  \\
&  & 3 & \foreignlanguage{greek}{εγεννηϲεν τον δαυειδ τον βαϲιλεα} & 7 &  &  \\
&  & 8 & \foreignlanguage{greek}{δαυειδ δε ο βαϲιλευϲ εγεννηϲεν το̅} & 13 &  &  \\
&  & 14 & \foreignlanguage{greek}{ϲολομωντα εκ τηϲ του ουριου ϲολο} & 1 & \textbf{7} &  \\
&  & 1 & \foreignlanguage{greek}{μων δε εγεννηϲεν τον ροβοαμ} & 5 &  &  \\
&  & 6 & \foreignlanguage{greek}{ροβοαμ δε εγεννηϲεν τον αβια αβι} & 11 &  &  \\
&  & 11 & \foreignlanguage{greek}{α δε εγεννηϲεν τον αϲα αϲα δε εγε̅} & 3 & \textbf{8} &  \\
&  & 3 & \foreignlanguage{greek}{νηϲεν τον ιωϲαφατ ιωϲαφατ δε} & 7 &  &  \\
&  & 8 & \foreignlanguage{greek}{εγεννηϲεν τον ιωραμ ιωραμ δε εγε̅} & 13 &  &  \\
&  & 13 & \foreignlanguage{greek}{νηϲεν τον οζειαν οζειαϲ δε εγεννη} & 3 & \textbf{9} &  \\
&  & 3 & \foreignlanguage{greek}{ϲεν τον ιωαθαμ ιωαθαμ δε εγεννη} & 9 &  &  \\
&  & 9 & \foreignlanguage{greek}{ϲεν τον αχαζ αχαζ δε εγεννηϲεν} & 14 &  &  \\
&  & 15 & \foreignlanguage{greek}{τον εζεκιαν εζεκιαϲ δε εγεννηϲε̅} & 3 & \textbf{10} &  \\
&  & 4 & \foreignlanguage{greek}{τον μαναϲϲη μαναϲηϲ δε εγεννη} & 8 &  &  \\
&  & 8 & \foreignlanguage{greek}{ϲεν τον αμων αμων δε εγεννηϲεν} & 13 &  &  \\
&  & 14 & \foreignlanguage{greek}{τον ιωϲιαν ιωϲιαϲ δε εγεννηϲεν το̅} & 4 & \textbf{11} &  \\
[0.2em]
\cline{4-4}
\end{tabular}
\end{center}
\end{table}
}
\end{document}


Here is some errors I could have with the previous tools I used :

I'm using macOS Mojave 10.14.6

• Pandoc (v 2.7.3) :
Error at "source" (line 68, column 65):
unexpected \rule
& \mygospelchapter &  & \foreignlanguage{greek}{βιβλοϲ γενεϲεωϲ \textoverline{ιυ} \textoverline{χυ} υιου δαυειδ} & 6 &  &  \\

• text4ht (didn't find the version number but it should be the last one normaly) :
tex4ht.c (2012-07-25-19:36 kpathsea)
tex4ht test.tex
--- warning --- Can't find/open file test.dvi'
--- error --- Can't find/open file test.dvi'

• I don't remember from where I got this error :
Can't locate Alien/Libxml2.pm in @INC (you may need to install the Alien::Libxml2 module) (@INC contains: /usr/local/Cellar/perl/5.30.0/lib/perl5/site_perl/5.30.0/darwin-thread-multi-2level /usr/local/Cellar/perl/5.30.0/lib/perl5/site_perl/5.30.0 /usr/local/Cellar/perl/5.30.0/lib/perl5/5.30.0/darwin-thread-multi-2level /usr/local/Cellar/perl/5.30.0/lib/perl5/5.30.0 /usr/local/lib/perl5/site_perl/5.30.0/darwin-thread-multi-2level /usr/local/lib/perl5/site_perl/5.30.0) at Makefile.PL line 20.
BEGIN failed--compilation aborted at Makefile.PL line 20.

• When I did perl Makefile.PL on Makefile.PL from the LaTeXML folder to install latexml.
"/usr/local/Cellar/perl/5.26.1/bin/perl" -MParse::RecDescent - lib/LaTeXML/MathGrammar LaTeXML::MathGrammar Parse::RecDescent
Can't locate Parse/RecDescent.pm in @INC (you may need to install the Parse::RecDescent module) (@INC contains: /usr/local/Cellar/perl/5.26.1/lib/perl5/site_perl/5.26.1/darwin-thread-multi-2level /usr/local/Cellar/perl/5.26.1/lib/perl5/site_perl/5.26.1 /usr/local/Cellar/perl/5.26.1/lib/perl5/5.26.1/darwin-thread-multi-2level /usr/local/Cellar/perl/5.26.1/lib/perl5/5.26.1 /usr/local/lib/perl5/site_perl/5.26.1/darwin-thread-multi-2level /usr/local/lib/perl5/site_perl/5.26.1).
BEGIN failed--compilation aborted.
make: *** [blib/lib/LaTeXML/MathGrammar.pm] Error 2

• When I try to execute latexml (didn't find the version number but it should be the last one normaly):
Can't locate XML/LibXML.pm in @INC (you may need to install the XML::LibXML module) (@INC contains: /usr/local/Cellar/latexml/0.8.4/libexec/bin/../lib /usr/local/Cellar/latexml/0.8.4/libexec/lib/perl5/darwin-thread-multi-2level /usr/local/Cellar/latexml/0.8.4/libexec/lib/perl5 /usr/local/Cellar/perl/5.30.0/lib/perl5/site_perl/5.30.0/darwin-thread-multi-2level /usr/local/Cellar/perl/5.30.0/lib/perl5/site_perl/5.30.0 /usr/local/Cellar/perl/5.30.0/lib/perl5/5.30.0/darwin-thread-multi-2level /usr/local/Cellar/perl/5.30.0/lib/perl5/5.30.0 /usr/local/lib/perl5/site_perl/5.30.0/darwin-thread-multi-2level /usr/local/lib/perl5/site_perl/5.30.0) at /usr/local/Cellar/latexml/0.8.4/libexec/lib/perl5/LaTeXML/Common/Object.pm line 16.
BEGIN failed--compilation aborted at /usr/local/Cellar/latexml/0.8.4/libexec/lib/perl5/LaTeXML/Common/Object.pm line 16.
Compilation failed in require at /usr/local/Cellar/latexml/0.8.4/libexec/lib/perl5/LaTeXML/Common/Error.pm line 16.
BEGIN failed--compilation aborted at /usr/local/Cellar/latexml/0.8.4/libexec/lib/perl5/LaTeXML/Common/Error.pm line 16.
Compilation failed in require at /usr/local/Cellar/latexml/0.8.4/libexec/lib/perl5/LaTeXML/Core.pm line 18.
BEGIN failed--compilation aborted at /usr/local/Cellar/latexml/0.8.4/libexec/lib/perl5/LaTeXML/Core.pm line 18.
Compilation failed in require at /usr/local/Cellar/latexml/0.8.4/libexec/bin/latexml line 19.
BEGIN failed--compilation aborted at /usr/local/Cellar/latexml/0.8.4/libexec/bin/latexml line 19.

• When I try with the software called SimpleTeX4ht (v 3.3) :
Package: fontspec 2016/02/01 v2.5a Font selection for XeLaTeX and LuaLaTeX

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Fatal fontspec error: "cannot-use-pdftex"
!
! The fontspec package requires either XeTeX or LuaTeX.
!
! You must change your typesetting engine to, e.g., "xelatex" or
! "lualatex"instead of plain "latex" or "pdflatex".
!
! See the fontspec documentation for further information.
!
! For immediate help type H <return>.
!...............................................

l.28 \msg_fatal:nn {fontspec} {cannot-use-pdftex}

|'''''''''''''''''''''''''''''''''''''''''''''''
| This is a fatal error: LaTeX will abort.
|...............................................



Thanks for every help !

Your document compiles without problems with tex4ht, you just need to provide a small configuration file and require the XeTeX support, which is not used by default. As you want an ePub file, you can use tex4ebook which is LaTeX to Ebook converter based on tex4ht. I've found an additional issue that doesn't affect tex4ht itself, but does affect tex4ebook.

I had to modify your document slightly, in particular I moved the definition of \myfont before its first use:

\font\myfont=cmr12 at 21pt
\title{{\myfont GA 032''}}


It is necessary to declare used Unicode blocks for the tex4ht XeTeX support, so I've created a configuration file that adds support for Greek:

\Preamble{xhtml}
\xeuniuseblock{Greek}
\begin{document}
\makeatletter
\nofrench@punctuation%
\makeatother
\EndPreamble


The \nofrench@punctuation fixes a tex4ebook issue with active characters used in the TOC.

The document can be converted using:

tex4ebook -xc config.cfg filename.tex


This is the result:

• I have the following error when I compile with your solution : ! Undefined control sequence. l.2 \xeuniuseblock {Greek} ? Your post gave me unexpected hope, thanks! – gustav.b Oct 6 '19 at 11:45
• @gustav.b which TeX distribution do you use? It should work in TL 2019 and TL 2018. – michal.h21 Oct 6 '19 at 12:24
• I get this when I type tex -v : TeX 3.14159265 (TeX Live 2016) . So I'm going to see if I can update tex. – gustav.b Oct 6 '19 at 12:28
• @gustav.b ah, that is a really old distribution. it would be best to update it, if it is possible. – michal.h21 Oct 6 '19 at 12:33
• It works, yes. But would you know how I could have my personal font KoineGreek in this final ePub ? – gustav.b Oct 6 '19 at 19:32