LyX: Missing Title When Passing `ignorenonframetext` to Beamer

Passing ignorenonframetext as an option to Beamer causes it to ignore all text that is not inside a frame. It is useful when you want to add content for the article version of the presentation (or simply script lines for yourself) that would not show in the regular presentation. LyX puts the title elements outside any frame. Therefore, if you use ignorenonframetext, you end up missing the title frame. The solution is to manually wrap the title block (the title, author, institute, etc.) in a frame and append maketitle to it. This will cause the title frame to be rendered correctly.

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 would be rendered in a readable manner on Kindle.

I’ve started with the normal article class. The result is not good at all:
article 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.
scrartcl

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 (which removes the page numbering, among other things) results in much better results, but because of the (still) wide margins and the auto-zoom, the font size is too big and not enough content fits on a page:
scrartcl_12x9

Finally, 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 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, it is bound on the right. The KOMA-Script manual does not consider that option. After a bit of playing around, I’ve found 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}

Creating a Hebrew Document in LyX 2.1 with XeTeX

This post complements the basic LaTeX template I gave yesterday for typesetting Hebrew with XeTeX. I’ll walk through the (short) list of steps needed to configure LyX for XeTeX.

Prerequisites

  • LyX 2.1 or later (I’ve also tested the development version of 2.2). I had very limited success with LyX 2.0, so you should probably avoid it.
  • XeTeX – I’ve tested with version 3.1415926-2.4-0.9998, which comes with TeXLive 2012, but I guess any recent version will do.
  • The polyglossia and bidi packages. Again, I’ve used the versions that come with TeXLive 2012.
  • Good TrueType Hebrew fonts. I recommend Culmus 0.121 or newer. You may also try using the fonts that come with your operating system; they might work as well.

Setting up the document

Create a new document and open the settings dialog (Document -> Settings...).

  1. Pick a suitable Document class. I recommend “KOMA-Script Article,” but “Article” works just as well. Avoid “Hebrew Article,” as it is broken under XeTeX.
  2. Under Fonts, check the box next to `Use non-TeX fonts (via XeTeX/LuaTeX)` and select suitable fonts:
    • Roman: Frank Ruehl CLM. David CLM is also a good choice, with a somewhat better italic variant.
    • Sans Serif: Simple CLM.
    • Typewriter: Miriam Mono CLM.
    • There is no need to change the Math font.
  3. Under Language, select Hebrew as the document’s language.

That’s basically it. You can now write your document and compile it. I would suggest saving these settings as defaults (via “Save as Document Defaults”) or saving the document as a template so you won’t need to repeat these steps.

Writing in English

To insert English text into your Hebrew document, you need to change the current language. The easiest way to do so is to create a keyboard shortcut for it:

  1. Go to Tools -> Preferences -> Editing -> Shortcuts
  2. Type “language” under “Show key-bindings containing:”.
  3. Select “language” under “Cursor, Mouse and Editing Functions” and click “Modify” to set a keyboard shortcut (F12 is traditionally used for this).

Now you can toggle the current language between English and Hebrew by simply pressing F12.

Remark about Fonts

It is preferable to use fonts that provide both Hebrew and Latin scripts, as otherwise there might be significant style differences that make the document look weird. It is possible to set a different font for Hebrew and Latin, but care needs to be taken to match styles. To do so, add the following lines to the Preamble:

newfontfamilyhebrewfont[Script=Hebrew]{David CLM}
newfontfamilyhebrewfonttt[Script=Hebrew]{Miriam Mono CLM}
newfontfamilyhebrewfontsf[Script=Hebrew]{Simple CLM}

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 slightly offset compared to the ideal position.

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

heb-test

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
%newfontfamilyhebrewfont[Script=Hebrew]{David CLM}
%newfontfamilyhebrewfonttt[Script=Hebrew]{Miriam Mono CLM}
%newfontfamilyhebrewfontsf[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 Environments

I came across some unexpected 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.


Continue reading nameref Doesn’t Work Properly with Theorem Environments

Separate Numbering for Problems in LaTeX

By default, when using amsthm to create environments such as theorems, claims, and problems, they all use the same numbering. Sometimes this is annoying, as the numbering for the problems should generally be unaffected by the theorems present (or the 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.

letproblem@undefined % undefines the existing problem environment
theoremstyle{definition} % set the style of the new environment to 'definition'
newtheorem{problem}{protectproblemname} % (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 subordinate numbering (numbering per section).

Hebrew Support in Hyperref – Situation Review

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

Installing culmus-latex on Ubuntu 11.10

After someone complained to me that he can’t install culmus-latex on Ubuntu 11.10, I decided to check the issue. Apparently, culmus-latex can’t be installed as-is on Ubuntu 11.10 (and probably other new versions of Debian and Ubuntu). The problem has been reported in a few places such as Whatsup, but as I don’t frequent the forum lately, I wasn’t aware of it. Skip below if you’re just interested in the workaround.

Technical Details

The problem manifests itself as:

sudo make install
... snipped for brevity ...
mktexlsr: Done.
updmap-sys --enable Map=culmus.map
updmap: This is updmap, version $Id: updmap 14402 2009-07-23 17:09:15Z karl $
updmap: using transcript file `/var/lib/texmf/web2c/updmap.log'
updmap: initial config file is `/var/lib/texmf/web2c/updmap.cfg'
make: *** [install] Error 2

But if you look at updmap’s man page, there is no documentation for the return codes. Also, there is no explicit place where it exits with return code 2 in the code. After some strace’ing, I found the culprit in the combination of the set -e at the top of /usr/bin/updmap and the function pickLocalFile in /usr/share/tex-common/debianize-updmap, which overrides certain behaviors in updmap. The pickLocalFile function uses the following lines

localfile=""
localfile="`ls $debDirname/*local*cfg 2>/dev/null`"
if [ -n "$localfile" ]; then

To check if there is a local configuration file under /etc/texmf/updmap.d. If such a file doesn’t exist, instead of creating one (as the maintainers of debianize-updmap intended), it fails due to the set -e in /usr/bin/updmap. Thus, updmap exits with error code 2 instead of completing the installation.

Meanwhile, until the bug is fixed, there is a simple workaround.

Workaround

Before installing, execute

sudo touch /etc/texmf/updmap.d/10local.cfg

And now the regular sudo make install installation should finish successfully.

As the problem is a result of a Debian bug, I don’t expect to release a new version of culmus-latex. Instead, I’ll report the bug to the Debian team.

Number Exercises Separately in LyX

Say you’ve got a document with a bunch of exercises and a few lemmas. You may want the exercises numbered separately from the lemmas and theorems, 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:

letxca@undefined
theoremstyle{plain}
newtheorem{xca}{protectexercisename}

LyX will still display the incorrect numbering, but the output will be correct nonetheless. The first line undefines 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 theorem counter.