Using LuaTeX as a replacement for pdfTeX

In this question Differences between LuaTeX, ConTeXt and XeTeX various differences between LuaTeX and XeTeX (and ConTeXt) are discussed. And in this question Using XeLaTeX instead of pdfLaTeX a recipe for switching from pdfLaTeX to XeLaTeX is given. In this question, I would like a similar recipe for using LuaLaTeX. I'm particularly interested in the degree to which LuaTeX can be used as a drop-in replacement for pdfTeX. I'm not interested in things that LuaTeX can do that pdfTeX can't.

So the question is:

What do I need to do to use LuaLaTeX instead of pdfLaTeX to compile existing or new documents?

Some specific sub-questions:

1. What packages are compatible with pdfLaTeX but not with LuaLaTeX?
2. Are there any packages specific to LuaLaTeX that should be loaded in most LuaLateX documents?
• See `lualatex-doc`. – Reinstate Monica - M. Schröder Oct 22 '11 at 12:12
• @MartinSchröder Thanks! I had found the LuaTeX reference document, but I didn't realize this document existed too. It's very helpful. – Alan Munn Oct 22 '11 at 13:23

I think we don't need to do much. The only incompatible thing I know is the `UTF-8` encoding.

1. Any package related to input encodings and font encodings:

• `inputenc`. You should always use `UTF-8` encoding to input the text. For backward compatibility, use `luainputenc` instead.
• `fontenc`. Don't use it with `fontspec` explictly.
• `textcomp`. Use `xunicode` instead, which is loaded by `fontspec`.
• Most old font packages (esp. for text fonts) are better not to be used. For example, use `XITS`, `TeX Gyre Termes` or `Linux Libertine O` fonts with `fontspec` instead of `times` package, and use Unicode fonts for main text together with `mathptmx` and `txfonts` (font math fonts only) to get proper text fonts.
• `CJK` is not compatible with LuaTeX. Today only a few unofficial LaTeX packages in Korea and Japan are available. This may be not very important for western users.
2. `fontspec`. To load TrueType/OpenType fonts. This is the only necessary one, I think. Also, `luacode` and `unicode-math` are useful.

• I'm not quite sure about your font statement. Unicode maths fonts are only now approaching completion, so you may well still want to load something like `mathptmx` for the maths font, then set the text font using `fontspec`. – Joseph Wright Oct 22 '11 at 6:24
• @Khaled Hosny: I said, that we need packages like libertine.sty for the normal user! Not every user is interested in loading fonts like `\setmainfont[ItalicFont=Georgia Italic]{Chalkduster.ttf}` ... – user2478 Oct 22 '11 at 16:04
• @Herbert: but I disagree, as a normal user I want to just load the font I want, not wait for someone to write a package for me, and mixing roman and italic from different typefaces is not a common use case, and certainly not what a normal user would want. – Khaled Hosny Oct 22 '11 at 16:24
• @Khalid: I must say I agree with here. It is great that luatex and xetex now give you the power to shoot yourself to the foot by selecting any horribly clashing combination of fonts and sizes. I am all for it, on the other hand, there are combinations of fonts that are very good match, and having packages that make using such combination as easy would definitely be a plus. After all, the new engines should not make selecting a well designed and balanced combination of fonts harder than it was in the old engines, especially as it is entirely possible to have both ways. – Jan Hlavacek Oct 22 '11 at 16:41
• @GTK: `luatexja` does the stuff. It's rather new package, but usable. – Leo Liu Aug 11 '12 at 5:49

One thing you need to consider is:

If you are using (either directly or indirectly) `pdftex` primitives like e.g. `\pdffilemoddate` (see the `pdftex` manual) with LuaLaTeX then you need to load Heiko Oberdiek's `pdftexcmds` package which adds all these commands currently missing in LuaTeX. However, these are provided as macros not as primitives and therefore do not react 100% the same way. For example `\pdffilemoddate` requires one expansion step more. I programmed my `filemod` package accordantly to load it automatically for LuaLaTeX, but other packages might not check these commands so strictly.

I don't think this is an huge issue for most documents, but definitively worth mentioning.

From the front lines:

I switched to LuaLaTeX in mid 2013 because I wanted TTF fonts. I am strictly using *TeX through a Makefile that has been evolving for 20 years (actually 22, if memory serves correctly).

To make the switch I ultimately converted all my framework's files to UTF8 and switched to using UTF8 only. First of course I changed the Makefile to use `lualatex` instead of `pdftex`.

``````\RequirePackage{ifluatex}
\ifluatex
\PassOptionsToPackage{usenames,dvipsnames}{color}
\RequirePackage[latin1]{luainputenc}
\else
\RequirePackage[latin1]{inputenc}
\RequirePackage{times}
\fi
``````

and then of course the font thingy:

``````\ifluatex
\setmainfont[%
UprightFont = *-regular,
BoldFont    = *-bold,
ItalicFont  = *-italic,
BoldItalicFont  = LMRoman10-Bolditalic,
SmallCapsFont = lmromancaps10-regular,
SmallCapsFeatures = {Scale=MatchUppercase},
SlantedFont = LMRomanslant12-Regular,
BoldSlantedFont = LMRomanslant10-Bold,
Renderer=Basic
]{lmroman12}
\fontspec[FakeBold=4]{Latin Modern Roman Caps}
\setsansfont[Scale=MatchUppercase,
UprightFont = {* Regular},
BoldFont    = {* Bold},
ItalicFont  = {* Regular Italic},
BoldItalicFont = {* Bold Italic}
]{Nimbus Sans L}
\setmonofont[Scale=MatchLowercase]{Source Code Pro Light}
\else
\usepackage[scaled=.9]{helvet}
\fi
``````

That's it. My framework has been working ever since. There is only one thing I haven't fixed yet (too minor): With lualatex I always get a little space in the result when I do `--`.

So for me it has been serving as a drop in replacement for 3 years already. Yes it can always squeak a little when UTF8 vs latin1 happens, but apart from that it just works.

A compile run with lualatex takes considerably longer than pdftex. Therefore I often used to use pdftex while writing and switch to lualatex when appearance becomes more important. However, my new Laptop has an SSD. Haven't used pdftex since ...

Edit 2016-06-07

I found some other caveat(s) I apparently came across while using LaTeX beamer.

``````\iflualatex
\RequirePackage{newunicodechar}
\newcommand{\DeclareUnicodeCharacter[2]{%
\begingroup\lccode`|=\string"#1\relax
\lowercase{\endgroup\newunicodechar{|}}{#2}%
}
So when using LaTeX beamer the utf8 issue is solved differently and apparently pdftex knows `\DelcareUnicodeCharacter` while lualatex does not. Chances are I got the solution from this site ...
• Since you say you changed the input encoding of all files to utf8, why do provide the instruction `\RequirePackage[latin1]{luainputenc}`? – Mico May 31 '16 at 16:26