# Typesetting a computer-science book with XeLaTeX+biber

For the next computer-science book I'm planning to edit, I'm considering switching from pdflatex+bibtex to a more modern setup. To get an idea of the contents, think of 400 pages in the style of "Introduction to Algorithms" by Cormen, Leiserson, and Rivest (mild mathematics, some pseudocode in a self-invented, GCL-like programming language, some self-drawn diagrams, a few images), but to be sent as a PDF file to Springer. The book's main language is going to be German, and there will be a tiny amount of typesetting in other languages (including mostly other Latin-based languages, Russian, and Hebrew math letters when I expend all the Latin letters). I am very likely to use babel and microtype as follows: \usepackage[USenglish,british,canadian,finnish,latin,russian,french,dutch,german,ngerman]{babel} (nongerman mostly used for typesetting bibliography) and \usepackage[babel=true,verbose=errors,protrusion=true,expansion=true,kerning=true]{microtype}. I am planning to produce an index (or indices) and a table of notation, ideally both with the glossaries package. The diagrams and graphs are likely to be drawn using TikZ.

Based on my experiences so far, I consider choosing XeLaTeX and/or biber. XeLaTeX would give me, as far as my tests go, the direct advantage that certain characters that now go as garbage to the text layer of the PDF file produced would become meaningful, selectable characters. With biber, typesetting a multilingual bibliography would get easier than with bibtex+babelbib.

An aside has to be made. I did consider LuaLaTeX as an alternative to XeLaTeX. But my tests showed that LuaLaTeX was way slower than XeLaTeX on my input, which would make my typesetter's daily life harder, especially for a huge book. (For the curious, my experiments showed the following quotients for the running time of pdflatex : xelatex : lualatex on the same contents while adapting the preamble to suit the compiler: 1 : 1.86 : 2.78. So, lualatex is 1.5 times slower than xelatex for my input. Thus, an often expressed claim that lualatex would be faster than xelatex, is in general misleading.) As for now, a whole compilation (from scratch rather a re-compilation) of a slighlty larger book with similar contents takes 2 minutes with pdflatex; I could probably tolerate 3 minutes with {xe|lua}latex, but not more. I had no experience with ConTeXt and cannot say anything about it so far. SILE apparently has no maths as of today, or at least I don't see it in the manual. Omega and NTS seem to be pretty dead as of today.

There is a high chance that SVMono will have to be adapted to XeLaTeX. The main font will be Times New Roman or similar; the secondary font (for headings of sections and chapters) will be Arial, Helvetica or similar. Therefore, I'm looking at TeX Gyre Termes and TeX Gyre Heros. Moreover, I took a look at Moving from pdfLaTeX to XeTeX - what do I need to know?, Frequently loaded packages: Differences between pdfLaTeX and XeLaTeX, Transparency in tikz, preview package and xelatex, PSTricks transparency does not work with MikTeX's XeLaTeX, and PDF Layers (OCG) using xelatex and considered them non-issues in my case.

Now, has anyone tried to use XeLaTeX+biber for tasks similar to the one described above, and, if so, what were your experiences? E.g.:

1. How hard was it to adapt SVMono to XeLaTeX and/or biber?

2. Was there a barrier that you could not overcome (or not overcome easily) and had to invest major unplanned effort or to switch back to pdflatex+bibtex?

3. Which pitfalls are to be avoided?

4. Was there any free lunch you did not expect?

• @TeXnician Are you saying it would work by default with XeLaTeX? (My very simple "Hello-world-like" tests show no error, but it may get nasty later.) – user49915 Aug 13 '18 at 14:29
• Sorry, I missed the part with PDF sending to Springer. I'm just saying that you should try to use it with XeLaTeX and adapt what doesn't work. But really your question is very localized on the one hand, asking for a special case, and too broad on the other hand, no clear issues, but many questions you want a answer to. It is not the best choice for our format here. – TeXnician Aug 13 '18 at 14:31
• @TeXnician Well, I don't expect an fully-covering, all-inclusive answer here. Sharing any experience will do. – user49915 Aug 13 '18 at 14:33
• But from my experience, having written a German computer sciene book in LaTeX, I would say it is possible to do so with XeLaTeX and biber (I have switched to LuaLaTeX after starting with XeLaTeX, but that's another story). Let's say I am a LuaLaTeX-only user nowadays (except for this site) and it works quite well, even adapting strange pdflatex templates, once you have the knowledge to do that. – TeXnician Aug 13 '18 at 14:33
• Well, I tried the switch from pdfLaTeX to XeLaTeX a couple of years ago, for a large set of documents (much bigger than your 400-page book project) with multiple languages (English, Greek, Hebrew, Arabic, etc...) I don't really remember the details, but I gave up pretty soon - there were a seemingly endless series of hassles with incompatibilities to overcome, for zero real benefit. And I find LuaTeX is too slow for doing any serious work - it reminds me too much of using of TeX on the original IBM PC back in the 1980s, taking several minutes per page of output! – alephzero Aug 13 '18 at 14:56

I have downloaded the template for SVMono from the link you provided in the question. Looking through the class file it doesn't look like anything needs special adaption for XeLaTeX. Only the main template file book.tex has to be adjusted.

# Fonts

The following lines load fonts which won't work with Xe/LuaLaTeX.

\usepackage{type1cm}
\usepackage{newtxtext}       %
\usepackage{newtxmath}       % selects Times Roman as basic font


According to your question, you'd like to replace those with TeX Gyre Fonts (you didn't specify a mono font, so I went with Latin Modern Mono).

\usepackage{amssymb}
\usepackage{unicode-math}
\setromanfont{texgyretermes}[
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic
]

\setsansfont{texgyreheros}[
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic
]

\setmonofont{lmmono10}[
Extension = .otf,
UprightFont = *-regular,
ItalicFont = *-italic,
]

\setmathfont{texgyretermes-math.otf}


With this setup the template typesets without errors on both XeLaTeX and LuaLaTeX. A few overfull boxes show up, but that sample text is going to be replaced anyway.

# Bibliographies

SVMono has a class option to use natbib, but that is not enabled by default, which allows you to use the bibliography processor of your choice. I verified that biblatex is usable by adding

\usepackage{biblatex}
\nocite{*}


in the preamble and \printbibliography just before \end{document}.

# Microtypography

The microtype package works as well, however, the kerning option is only available in pdfTeX and expansion is not available in XeTeX.

# Language

Unfortuantely, the babel package has some hickups with SVMono. Adding just \usepackage[english]{babel} to the preamble leads to an error when reading the aux file during the second run

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.5 \newlabel{intro}{{1}{3}}[
None]


This is due to SVMono loading the ntheorem package which installs its own version of \newlabel. To overcome this problem, one would normally load babel before \documentclass with \RequirePackage. Unfortunately, this doesn't work as well because babel tries to inspect the list of class options which does not exist before loading the class. This means that we have to save the definition of \@newl@bel before loading babel and restore it again afterwards:

\makeatletter
\let\ntheoremnewlabel\@newl@bel
\makeatletter
\makeatletter
\let\@newl@bel\ntheoremnewlabel
\makeatletter


# Summary

That should answer points 1. and 2. from your question. For point 3. and 4. I can't think of anything from the top of my head but there are always some unexpected situation along the way.

Regarding speed, typesetting the SVMono example with all the features from above it takes or average 2.55 s with LuaLaTeX and 3.02 s with XeLaTeX, so in this case LuaLaTeX seems to be faster than XeLaTeX. Of course, when adding a lot more text and many TikZ figures and such your mileage may vary.

• Svmono v5.6 contains \usepackage{ntheorem}, whereas v5.5 doesn't. The package ntheorem has bugs that prevented me from using it 2-3 years ago, and, moreover, is unmaintained since 2002 on CTAN and since 2011 according the authors' website on ntheorem. I'm not sure whether svmono works around the bugs or leaves them as they are. In any case, the transition from v5.5 to v5.6 seems nontrivial and is not necessarily an improvement. – user49915 Feb 7 at 0:32
• Anyhow, my OP concerns svmono in general, so, I guess, I'll have to use the new version of svmono (and live with ntheorem) for the new book, so, many thanks for showing the pitfalls... As for speed, I'll take another look into it; thanks!!! – user49915 Feb 7 at 0:32
• @user0 Regarding speed you just have to profile. There is no way to say in advance which is going to be faster. Only pdfTeX will always be faster than Xe/LuaTeX but that's because it doesn't handle UTF-8, which I think you need (at least judging from this question of yours). – Henri Menke Feb 7 at 0:39
• Btw., since the main language of the book is going to be German, you shouldn't have \usepackage[english]{babel} above but rather \usepackage[ngerman]{babel}. – user49915 Feb 14 at 20:47
• @user0 I just used \usepackage[english]{babel} to trigger the bug with ntheorem. Of course in your document you would use the language you actually write in. – Henri Menke Feb 14 at 20:52

I haven't done with the svmono but I just had to tweak another publisher class to use lualatex and so after a quick look at svmono I would say

1. I would prefer lualatex over xelatex due to the microtype capabilities and better graphic (pgf) support (and it is now faster than last year due to changes in expl3 and in the font loader).

2. I would expect 2-4 hours of work to move svmono to lualatex+biber, where most of the time is needed to check the code and consider if it could be problematic or not (mostly there will be no need to change something).

3. I wouldn't expect large problems, but would still expect to have to adjust small things later as one always overlooks something in such rather old classes ...

• You didn't answer “4. Was there any free lunch you did not expect?” whatever that is supposed to mean. – Henri Menke Feb 5 at 7:17
• @HenriMenke the "free lunch" I normally get from such projects, is that I discover some bug in one of the involved packages and have to write bug reports ;-). – Ulrike Fischer Feb 5 at 13:10
• @UlrikeFischer In any case, thanks for looking into it! – user49915 Feb 6 at 21:26