# TeX to html (and from there, to .mobi) for

I am a complete beginner at TeX, but am trying to convert Euclid's Elements from Project Gutenberg's TeX format to html so that I can then use Calibre's command-line ebook-convert to go to .mobi for reading on my Kindle. PDF, even when I change the print settings in Preview to A5 (5.83"x8.27") and then print to PDF again, is too small for me to read comfortably, and the percentage read footer at the bottom gets in the way. For most of the following, I have renamed the TeX file to EuclidsElements1-6.tex. I have a MacBook pro, hence the Fink usage in the following.

Things I've tried (that I can remember):

1. tex2ebook.py (installing all required packages but Calibre using Fink). This didn't work fully because my ebook-convert path was broken due to my using the Calibre binary, but I found the .html output file and manually used ebook-convert to get it to .mobi. Unfortunately, the .mobi only included about 4 pages of the book's introduction. Possibly because of a lot of hevea and Bibtex warnings about \vfill \dotfill and \frontmatter "not found", "minipage, output may be poor", and a "Giving up command: \mbox" (should I include the copious output here?).

2. /sw/share/tex4ht/bin/mzlatex EuclidElements1-6.tex

This went well until here:

No file EuclidElements1-6.aux.
[1] [2] [1] [2] [3] [4]

LaTeX Warning: File images/f000.png' not found on input line 387.

l.387 --- TeX4ht warning --- Cannot determine size of graphic in   images/f000.png (no BoundingBox) ---
[5] [6] [7]
---------------------------------------------------------
l.459 --- TeX4ht warning --- If not done so, the index is to be processed by
tex '\def\filename{{EuclidElements1-6}{idx}{4dx}{ind}} \input idxmake.4ht'
makeindex -o EuclidElements1-6.ind EuclidElements1-6.4dx instead of
makeindex -o EuclidElements1-6.ind EuclidElements1-6.idx
On some platforms, the quotation marks ' should be
replaced by double quotation marks " or eliminated.
---------------------------------------------------------  ---
[1] [2]
No file EuclidElements1-6.4tc


. . . and so on with the missing images and lots of other warnings.

1. htlatex EuclidElements1-6.tex

TONs of errors, starting with:

LaTeX Warning: File images/f000.png' not found on input line 387.

l.387 --- TeX4ht warning --- Cannot determine size of graphic in images/f000.png (no BoundingBox) ---
[4] [5] [6]


and so on with the images that it could never find. Also, never ending instances of:

?
! Undefined control sequence.
\Link ->\let \:attr \empty \futurelet \let:val
\HRefT:ag
l.14915 ...lo's\index{Philo, proofs by} solution,}


I finally had to Ctrl-Z out of htlatex. httex didn't even load the .sty files at the beginning, so I'd guess that's going in the wrong direction.

Can anyone point me in the right direction?

• Welcome! In most shells, ctrl-Z pauses a process. It does not stop it. – cfr Aug 13 '16 at 1:45
• You need to download everything at gutenberg.org/files/21076/21076-t, including the contents of the sub-directory and make sure that the directory you work in has the .tex file and the images sub-directory, containing all the figures. I'm not saying it will work. But this will at least give it a chance. Start by compiling with pdflatex to PDF as that's probably what they did. If that doesn't work, fix the problems before trying tex4ht. Only try tex4ht once you know you've sorted the basic problems. – cfr Aug 13 '16 at 1:52
• Probably gutenberg.org/files/21076 might download everything you need, though I haven't checked. – cfr Aug 13 '16 at 1:54
• This didn't work fully because my ebook-convert path was broken due to my using the Calibre binary, .... I don't understand this, but since you seem to, shouldn't you fix this before proceeding? If by any chance you installed TeX using Fink don't. Undo the installation and install MacTeX. (Personally, I wouldn't trust Fink at all, but don't use it for TeX at any rate.) – cfr Aug 13 '16 at 1:57
• you can try tex4ebook, which is based on tex4ht and can convert to mobi automatically. files on Project Guttenberg often need some edits before it's possible to compile them using tex4ht. I will be offline next week, so I can't take a look at that now, unfortunately. – michal.h21 Aug 13 '16 at 6:23

First, it was important to download the images directory along with the .tex file from Project Gutenberg by clicking on "More Files" from the main title directory:

http://www.gutenberg.org/files/21076/

I downloaded the .zip file in that directory, and expanded/unzipped it in my working directory to get the .tex file and an images folder.

Next, I ran pdflatex from this working directory which contained the file and images folder, and successfully generated a .pdf file that looked pretty good when I opened it in Preview, in spite of the copious warnings it generated.

Finally, I uninstalled fink's texlive and installed MacTex instead, which includes tex4ebook. I had to add the convoluted install path to my $PATH variable thus: export PATH=$PATH:/usr/local/texlive/2016/bin/universal-darwin/


Actually I put it somewhere in the middle of my path by spelling out the whole path instead of using \$PATH, but I think the above should work and is more concise. At this point, from the same working directory as above, I ran tex4ebook -f mobi 21076-t.tex and it too generated a slew of warnings and errors. Finally I just set it to run uninterrupted ("R") and it eventually finished.

The output was an .epub instead of .mobi, but this was easily converted in Calibre's GUI. The text and old scanned images, if a tad wonky at times, look pretty good on the Kindle so far, although I haven't read carefully through the ebook to see if there are any continuity problems. Hearty thanks to @cfr and @michal.h21!