After finish writing a book in LaTeX, I learned the many online books are published in the ePub format. Then I decided to learn a little bit of how to convert .tex (or .pdf) into .epub.
The book has equations (including align), figures (.png,.eps), tables and TikZ.
I use TeXstudio as editor and MikTeX on Windows.
First I tried Pandoc.
Quickly I learned that .pdf -> .epub does not seem to be a viable route.
Than I concentrated my effort into .tex -> (some route) -> .epub.
I did not find any route or combination of flags to make Pandoc work properly.
I've seen and tested (at least tried) some options:
latexml: Use LaTeX to produce Epub -- it seemed to be and still is a bit confusing to me;htlatex: How to Convert a LaTeX ebook to ePUB (LaTeX Advanced Tutorial-22) -- it worked well, (bonus for "User Command" in TeXstudio), but the ePub through Calibre will not work if the.htmlfile has some issue.tex4ebook: The tex4ebook package -- it achieved the best results.
The base command: tex4ebook %.tex, where % is the name of the file (suitable for quick user command in TeXstudio), worked quite well.
tex4ebook worked (incredible better than the first options I tried) for the following features:
Equation, including the math operators outside its environment: "$ ... $", "(...)" and "[ ... ]";
Tables;
Hyperref/url -- all links are working;
TikZ with the sintax
\ifdefined\HCode \def\pgfsysdriver{pgfsys-dvisvgm4ht.def} \fi
derived from tex4ebook: nodes vanishes for TikZ? Alternative TikZ drivers for tex4ht with the .css file from FriendsOfEpub/Blitz;
- So far so good until I tried to test figures.
I can insert .eps figures, but I have no ideia of how I can insert other types such as .jpg and .png.
How are figures inserted in the ePub through tex4ebook?
Which also includes:
- Does
graphicsandgraphicxmake any difference?; - Should I always insert the extension of the files? For
pdflatexit is not necessary; - Is there any preferable type of figure file to ePub?
I tried to follow the steps in
- Create e-Books from Latex tex files;
- How to include figures and other files in TeX4ebook;
- LaTeX Template for Ebooks;
- Images disappearing when compiling with tex4ebook.
Compiling the .tex with some options did not helped:
tex4ebook -l -t -c config_file.cfg %.tex
-l:LuaTeXjust showed me messages more clear;-t:Tidy, I did not understand its usage, and how to call it from anyfolder;-c: that's a point that intrigues me.
I found some config files but I cannot say exactly what they are doing. I do not know if I'm missing some file, such as the .css files at the command \Configure in some examples; or something related to make4ht; or if the problem derives from the usage or not of LuaTeX; or the usage of Tidy.
Sometimes I receive the following message (one for each figure in different coordinates):
dvipng warning: at (31,156) unimplemented \special{em: graph any.jpg,72bp,72bp}
independent of using a .cfg or not.
I have noticed that a .png file is created of some kinds of objects such as equation, math symbols and the .eps figures, but to the .jpg
and .png the figures are always empty.
I would speculate that it might have some relation of the option width or how it is understood in tex4ebook, but the examples I searched didn't give me any hint.
Below follows a MWE with some options I've tried so far and the resulting ePub. Note: "any", "some" and "fine" are generic filenames.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{epstopdf}
% \usepackage{tex4ebook} % Doesn't seem to make any difference for png jpg
\begin{document}
1 -- includegraphics alone.
\includegraphics{any.jpg}
2 -- includegraphics alone, but with parameters, jpg.
\includegraphics[width=1\linewidth]{any.jpg}
3 -- includegraphics png must have the explicit extension to work ate the \texttt{tex4ht} and with width.
\includegraphics[width=1\linewidth]{some.png}
\includegraphics[width=0.5\linewidth]{some.png}
4 -- Inside figure environment
\begin{figure}[!htb]
\centering
\includegraphics[width=0.8\linewidth]{any.jpg}
\caption{Figure inside figure environment.}
\end{figure}
4.1 -- Inside figure environment
\begin{figure}[!htb]
\centering
\includegraphics[width=600pt]{any.jpg}
\caption{Figure inside figure environment width pt.}
\end{figure}
5 -- eps figure
\includegraphics[width=1\linewidth]{fine.eps}
5.1 -- eps figure
\begin{figure}[!htb]
\centering
\includegraphics[width=1\linewidth]{fine.eps}
\caption{Figure eps inside figure environment width.}
\end{figure}
\end{document}


graphic.4ht), but the figures fo the book didn't appear on its epub. I will verify if there is any other mistake or detail. – FHZ Jan 24 '20 at 15:31pngendepsshould work. maybe try to runtex4eboowith-a debugoption, it should report report errors.epsfile needs to be converted to something that can be included in Epub first (png, svg), so maybe the conversion fails on your system. There should be some info near the end of the compilation. – michal.h21 Jan 24 '20 at 15:49graphics.4htandtex4ebook -a debug %.tex, the following message appears:[INFO] make4ht-lib: executing: t4ht "MWE_tex4ebook_figs_mixed.dvi" inadmissible parameter - fig_eps.pngat the
.lgfile appearsl. 73 --- needs --- "convert fig_eps.eps fig_eps.png" --- File: fig_eps.pngI also tested some different
epsfigures, but always with the same results.Should I find and install some
– FHZ Jan 24 '20 at 19:17epstopngconverter?