# Optimize LaTeX PDF Output for Kindle

Kindle can display PDFs, but usually the result is very hard to read. Normal PDFs are not suitable, especially when it comes to paper size for the, relatively, small display of the Kindle. For a forthcoming project, which I intend to write in LaTeX and read on Kindle, I looked into optimizing the document settings so the result will be rendered in a readable manner on Kindle.

I’ve started with the normal article class. The result, is not good at all:
While Kindle zooms-in automatically to remove, the usually very wide, margins LaTeX uses, the big (A4) paper size, still results in a tiny font on the Kindle display. Switching to Koma-Script, is a bit better, but mainly provides better mechanisms to control the paper size for later experiments.

The next try, is simply to use the A5 paper size. The result is getting better, but the paper size is still too big. Setting the paper size manually to 12cm by 9cm (the screen’s physical dimensions) and setting the pagestyle to empty (removes the page numbering among other things) results in a much better results because of the (still) wide margins and the auto-zoom in a font size that is too big and not enough content fits in a page:

Finally, by manually setting the text area to be a bit smaller (11cm by 8cm) than the paper size, results in small margins and very little auto-zoom. The output can be clearly read on the Kindle, and still quite a bit of text fits on a single page:

The LaTeX code for the last example is:

\documentclass[DIV=calc,paper=9cm:12cm,pagesize]{scrartcl}

\areaset{8cm}{11cm}
\pagestyle{empty}
\usepackage{lipsum}
\begin{document}
\lipsum
\end{document}


# KOMA-Script: Specifying Binding Correction for RTL Documents

The KOMA-Script bundle provides an option to specify the amount of binding correction needed in order to compensate for the width lost in the binding process. By default, it is added to the left margin, which is where the binding is applied for Left to Right languages. However, if a document is written in Hebrew or Arabic, one binds it on the right. The KOMA-Script manual does not consider that option. After a bit of playing I’ve found out that simply using a negative value for the binding correction works.

For example, if in an English document you would use

\documentclass[BCOR=8.25mm]{scrreprt}


For Hebrew you would set

\documentclass[BCOR=-8.25mm]{scrreprt}


# Hebrew with XeTeX Example

This is an example of a document in XeTeX (Actually XeLaTeX). I’ve used The fonts from the Culmus Project. Note that you’ll need Culmus 0.121 or newer in order to get the Frank Ruehl font in TrueType. As you can see, Nikud are placed correctly. The cantillation marks (טעמי המקרא) are in a small offset compared to the ideal position.

Overall, XeTeX works much better with Hebrew (and easier to use) than pdfTeX.

\documentclass{minimal} \usepackage{polyglossia} \setdefaultlanguage{hebrew} \setotherlanguage{english} \usepackage{fontspec} \setmainfont{Frank Ruehl CLM} \setmonofont{Miriam Mono CLM} \setsansfont{Simple CLM} % Use the following if you only want to change the font for Hebrew %\newfontfamily\hebrewfont[Script=Hebrew]{David CLM} %\newfontfamily\hebrewfonttt[Script=Hebrew]{Miriam Mono CLM} %\newfontfamily\hebrewfontsf[Script=Hebrew]{Simple CLM}       \makeatletter \makeatother \usepackage{bidi} \begin{document} טקסט רגיל \textbf{טקסט מודגש} \textit{טקסט נטוי} \textit{\textbf{טקסט מודגש ונטוי}} בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ:   \begin{english} In the beginning God created the heaven and the earth. \end{english}   \sffamily טקסט רגיל \textbf{טקסט מודגש} \textit{טקסט נטוי} \textit{\textbf{טקסט מודגש ונטוי}} בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ:   \begin{english} In the beginning God created the heaven and the earth. \end{english}     \ttfamily טקסט רגיל \textbf{טקסט מודגש} \textit{טקסט נטוי} \textit{\textbf{טקסט מודגש ונטוי}} בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ:   \begin{english} In the beginning God created the heaven and the earth. \end{english} \end{document}

# nameref Doesn’t Work Properly with Theorem Environment

I came across not-so-expected behavior in nameref, the package responsible for creating named references, when used in conjunction with theorem environments such as the one provided by amsthm. For example take a look at the following LaTeX document.

\documentclass{article} \usepackage{amsmath,hyperref}   \begin{document} \section{My Section} \newtheorem{theorem}{Theorem} \begin{theorem}[My Theorem] \label{theo:My}0=0 \end{theorem} This is a named reference: \nameref{theo:My} \end{document}

You would expect the named reference to refer to the theorem’s name. However in reality it refers to the section’s name.

# Separate Numbering for Problems in LaTeX

By default when using the amsthm to create environments such as theorems, claims and problems, they all use the same numbering. Sometimes it’s annoying, as the numbering for the problems should generally be unaffected by the theorems present (or lack of them). For example the default behavior produces:

Problem 1 Problem 2 Theorem 3 Problem 4

where the desired behavior would be (in my opinion):

Problem 1 Problem 2 Theorem 1 Problem 3

Fortunately, this can be done by redefining the problem environment.

\let\problem\@undefined % undefines the existing problem environment \theoremstyle{definition} % set the style of the new environment to 'definition' \newtheorem{problem}{\protect\problemname} % (re)define the 'problem' environment

The \theoremstyle can be one of three defaults plain, definition and remark or some custom style defined using \newtheoremstyle.

See amsthm‘s documentation for more information, such as subordinately numbering (numbering per section).

# Hebrew Support in Hyperref – Situation Review

It’s been a bit more than three years since I’ve written about a workaround for getting hyperref to play (almost) nicely with Hebrew. Over the past few weeks, I saw I rising interest in this and few people contacted me regarding this issue. So I thought it’s a good opportunity to better document the current situation, and possible ways that should be further investigated which I believe might lead to better solutions.

# Number Exercises Separately in LyX

Say you’ve got a document with a bunch of exercises and few lemmas. You may want the exercises numbered separately from the numbering of the lemmas and theorem, unlike LyX’s default behavior. This can be achieved by redefining xca, the environment LyX uses for exercises. Add the following to your LaTeX preamble:

\let\xca\@undefined \theoremstyle{plain} \newtheorem{xca}{\protect\exercisename}

LyX will still display the incorrect numbering, but the output will be correct nonetheless. The first line, undefines the LyX’s definition of xca, then we set the style to match the old one and we redefine xca, this time without a reference to the theorems’ counter.

# Expectation Symbol in LaTeX

After looking for a builtin expectation symbol in LaTeX, and coming up with none, I’ve defined one. Just add:

% Expectation symbol \DeclareMathOperator*{\E}{\mathbb{E}}

to your LaTeX preamble and you’re done. You’ll also need to add \usepackage{amsmath} or in LyX to tick “Use AMS math package” under Document->Settings->Math Options.

Using the starred version of \DeclareMathOperator makes sure subscripts goes beneath the symbol in display mode.

# LaTeX for TiddlyWiki – A MathJax Plugin

Update: The MathJax Plugin for TiddlyWiki has a new home: https://github.com/guyru/tiddlywiki-mathjax
Some time ago I came across MathJax, a nifty, Javascript based engine for displaying TeX and LaTeX equations. It works by “translating” the equation to MathML or HTML+CSS, so it works on all modern browsers. The result isn’t a raster image, like in most LaTeX solutions (e.g. MediaWiki), so it’s scales with the text around it. Furthermore, it’s quite easy to integrate as it doesn’t require any real installation, and you could always use MathJax’s own CDN, which makes things even simpler.

A tiddler with LaTeX equations.

 \lyxframeend {}\lyxframe{Outline} The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., \hobx'), type I' and the correct spelling (e.g., I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.`