Creating Kindle-friendly versions of existing LaTeX documents

So let's say I have a large amount of documents (from ArXiv.org, suppose) that I have the LaTeX source for, and for which I would like to compile particularly Kindle-friendly versions. In particular, I would like to accomplish some combination of the following things:

• Generate at specifically 1200x824 and/or 600x800 resolution
• Make margins as small as possible since screen real estate is precious on the Kindle
• Generate diagrams directly to 4-bit grayscale (the Kindle will do this conversion anyway, but I have a feeling it will be easier if the diagrams are just generated that way)
• Do not draw boxes around links/references in the paper. These are useful on a computer but they still show up on the Kindle where it's not possible to click or select them anyway.

Does anybody know of the easiest way to apply settings such as these to a large number of document source files?

• Well, your problem can be reduced to that of providing replacement classes (or possible just one class) for article and report and the various revtex classes that does what you want, and coercing the displayed size and bit depth. Which doesn't help much except to point you at a small set of problems. – dmckee --- ex-moderator kitten Aug 13 '10 at 4:44
• @dmckee Thanks for the comment :) That's pretty much what I'm asking -- in particular, how can I "replace" the default article/report classes without re-implementing them entirely? Is there a way to "subclass" report/article so that I can override a few parameters but leave the rest untouched? – Adrian Petrescu Aug 13 '10 at 6:44
• What goes wrong if you simply change the page sizes and margins after the class has been loaded? – Andrew Stacey Aug 13 '10 at 7:50
• No subclassing as far as I know. But your latex system almost certainly provides some kind of search path for class files. You just need to arrange that your edited versions come earlier in the search than the standard ones. One warning, the tarballs I send to arXiv sometimes have the class file I want to use in them, and I'll given even odds that the search path includes . very early on... – dmckee --- ex-moderator kitten Aug 13 '10 at 7:56
• The Digital Mathematics Library project has aims that overlap with yours. fi.muni.cz/~sojka/dml-2010.html is a good place to start. – Jonathan Fine Aug 13 '10 at 8:21

This will only be possible with a lot of manual intervention. (Many arXiv documents use plain tex or context or amstex instead of latex. But your question specified latex, so I'll assume that much.)

The main problem is that tex isn't very good at doing fully-automated typesetting. In particular, it will not rebreak displayed equations to fit with your new margins. It also has a pretty perfectionist view of regular text. It will try to set what it thinks is a beautiful paragraph, but if it fails then rather than making a compromise paragraph it will just give up and make an underfull/overfull box for the author to deal with (by rewording the paragraph, by adding explicit \linebreaks, by telling tex about additional hyphenations). This isn't a problem when you're editing your own paper, but it's very bad when you want to batch convert a large number of documents in an automatic way. Some tricks are discussed in this FAQ answer.

However, here are partial solutions to the problems you pointed out.

Resolution

Tex generates DVI and pdftex generates PDF. Both of these are resolution independent. If you want to convert to a bitmap format, then you can use something like pdf2png (slow) or dvipng (fast).

Margins

The geometry package gives a lot of control of margins.

Figures in grayscale

Figures on the arXiv will be in a huge variety of formats. EPS, PNG, PDF, not to mention metapost code, PSTricks, PSFrag, and the latex picture environment. The standard formats can all be rasterized to a 4-bit PNG at a decent resolution using something like GraphicsMagick, but it will likely need manual intervention or some really clever scripting. Once you've got the bitmap, you need to feed it to latex, dealing with the fact that some submissions use latex (which doesn't understand png) and others use pdflatex (which doesn't understand eps), they will use a combination of packages, such as graphics, graphicx, epsfig and various journal classes with their own twists, so there will need to be some intelligent editing of the latex file. For metapost, PSTricks, PSFrag you will need more extensive editing.

This one is relatively easy. In many cases, simply compiling the arXiv tarball will do this already, because the arXiv uses hypertex to add these links, and if you compile with regular tex this won't happen. If the authors used the hyperref you can in many cases remove the \usepackage line, or, more safely since maybe the author used some commands from hyperref, add the colorlinks option to colour the links instead of drawing boxes (you can set the colour to black if you don't even want to see them that way).

• Thanks, Lev, for that interesting answer :) It answers my concerns very well. For the grayscaling, I think I will pick off some of the low-hanging fruits (included EPS/PNG/PDF figures) and let the Kindle grayscale the rest automatically when it loads the images/PDF. As for the hyperref, it looks like I can just do a \hypersetup{pdfborder={0,0,0}} to make them invisible. Most of these things should be scriptable. Thanks a lot! – Adrian Petrescu Aug 15 '10 at 23:50
• +1 for pointing out colorlinks, I've often wondered how to get rid of those boxes. (And of course the other info is good too) – David Z Aug 16 '10 at 1:51

As an astrophysicist, I wrote a simple python package to process arxiv/astro-ph posts for Kindle DX, but presumably it should be easy to incorporate math posts as well, e.g., by adding common math journal tex-style files.

• You are my hero. – Adrian Petrescu Jan 15 '13 at 23:38
• @AdrianPetrescu ;-) the code is very clunky and not well documented as it simply works out of the box for me (linux+astro-ph). Some more efforts are needed to make the mathematicians happy... – nye17 Jan 15 '13 at 23:46

These settings do a pretty good job (based on Lev Bishop's answer) for the impatient: \documentclass[12pt, oneside]{...}

\usepackage[a6paper,margin=0pt]{geometry}

\usepackage[pdftitle={Title},pdfauthor={First Last},colorlinks=true]{hyperref}

\renewcommand{\familydefault}{\sfdefault}

Unfortunately, Kindle keyboard does not pick up the Title and Author from the pdf. You may have better luck with later Kindle versions. You will have trouble with the margin settings if there is any margin content (notes, etc.). Since the Kindle has low resolution, Sans Serif fonts look better.

The package ebook can actually export a file specialized for phones (font, position, spacing, etc). Reducing the pagesize of templates specialized for wide screens/books isn't much quicker than this:

\documentclass{...}
\usepackage{ebook}
...
\begin{document}
\ebook    %  be careful if not the first command
...
\end{document}


It's easy to replace \begin{document} with \usepackage{ebook}/r\begin{document}/r\ebook. It can easily be switched back by commenting out \ebook. Compiling with XeLaTeX gives better result than pdfLaTeX (I don't know why).

I provided a lengthy response on a closely related thread, here: Effort to make (La)TeX eBook-friendly

The gist of it: You can put PDF on Kindle, but you might not get what you think you are getting. Unkless you must use TeX for equations and diagrams, it is better to use native ebook formats, especially if you intend to market licensed copies.