[Tex/LaTex] Switching to lualatex: How to translate font setups

fontsfontspecluatexpdftex

I am a long-term pdflatex user. Once in a while I want to give lualatex a try (e.g., to try the recent TikZ graph layout engine). A couple of good answers here at tex.se describe what to do in that case. For instance, the answer to How is a TeX document written when using LuaLaTeX? gives the following recipe (itself cited from Manuel Pé­gourié-Gon­nard’s Guide to LuaLaTeX):

  1. Don’t load inputenc; just encode your source in UTF-8.
  2. Don’t load fontenc or textcomp; load fontspec.
  3. babel works with LuaLaTeX but you can load polyglossia instead.
  4. Don’t use any package that changes the fonts; use fontspec commands instead.

I found all of that easy to follow advice, with the exception of point 4. The fontspec documentation is quite intimidating and gives no hint how to translate existing font setups to fontspec. For instance, last time I tried to switch I had the following font setup in my preamble:

\usepackage{lmodern}
\renewcommand{\sfdefault}{cmbr}
\usepackage{charter}
\usepackage[scaled=0.85]{beramono}

This is just an example, I typically pick my font setups from the LaTeX font catalogue, additionally load microtype, and that's it. Most font packages have reasonable setups with respect to all the fine details so the results are good enough for me.

However, with fontspec, I have the feeling I have to become a real font expert. In most cases I already failed to figure the font names to use, not speaking about all the other details.

So are there any translation tables for existing font packages?

Is there a technical reason that font packages not support lualatex out of the box, so one does not have to deal with intimidating fontspec commands?

Best Answer

The user guide of the fontspec package is indeed quite lengthy. However, I would not go as far as calling it intimidating. There's a huge and wonderful world out there related to OpenType and TrueType fonts, and it's not surprising (to me at least) that the manual that explains how to explore this world isn't brief.

In what follows, I will assume that your tex document is encoded according to the UTF8 standard. Aside: If your document uses only ASCII, it's automatically UTF8-compliant.

I have an educated guess as to why the user guide of the fontspec package doesn't explain how one might "translate" directives such as \usepackage{lmodern}, \renewcommand{\sfdefault}{cmbr}, \usepackage{charter}, or \usepackage[scaled=0.85]{beramono} to LuaLaTeX. The putative reason is quite simple: For the most part, no translation is necessary. If you're going to use font packages with LuaLaTeX that were designed originally for use under pdfLaTeX, just keep using them under LuaLaTeX and you'll be fine. (Do see below, though, for same caveats and exceptions.) If you do so, though, don't load the fontspec package as well.

For instance, the program

\documentclass{article}
\usepackage{lmodern}
\renewcommand{\sfdefault}{cmbr}
\begin{document}
The quick brown fox jumps over the lazy dog.

\sffamily
The quick brown fox jumps over the lazy dog.
\end{document}

produces the same output when run under either pdfLaTeX or LuaLaTeX:

enter image description here

Likewise, the program

\documentclass{article}
\usepackage{charter}
\usepackage[scaled=0.85]{beramono}
\begin{document}
The quick brown fox jumps over the lazy dog.

\sffamily
The quick brown fox jumps over the lazy dog.
\end{document}

produces the same output when compiled with either pdfLaTeX or LuaLaTeX:

enter image description here

The qualifier "for the most part" that was used above needs some explaining. As @UlrikeFischer points outs in a comment, an adjustment to the approach outlined above is necessary if the document contains "accented" characters which aren't included in the basic ASCII character set. (As noted above, I assume that the entire document is UTF-8 encoded.) If the document contains such characters, it is necessary to load the luainputenc package with the option utf8. With this adjustment made, the following code

\documentclass{article}
\usepackage[utf8]{luainputenc} % Not: "\usepackage[utf8]{inputenc}"
\usepackage{newtxtext}
\begin{document}
Grüße äöüÄÖÜ, \em Grüße äöüÄÖÜ
\end{document}

once again produces identical results when compiled under pdfLaTeX and LuaLaTeX:

enter image description here

Excerpting from the user guide of the luainputenc package:

From the user point of view, adapting an old document for LuaTEX is really easy: replacing inputenc by luainputenc in the preamble is enough. Note that luainputenc automatically loads inputenc if called with an old engine, so you will still be able to compile your documents with pdfTEX without changing them

That said, as @UlrikeFischer has pointed out in comments to this answer, some issues related to hyphenation may remain if you're using the luainputenc package. For instance, words with accented characters (like Grüße) may no longer be hyphenated, and LuaLaTeX's output may therefore not be exactly the same as if using pdflatex. Hence, in the long run it may nevertheless be a good idea to switch to fontspec in order to obtain optimal results.


When working with OpenType fonts, there are no packages -- with only a few exceptions (eg., the Libertine font family) -- that allow them to be used under pdf(La)TeX. To use OpenType fonts, one thus has to use either Xe(La)TeX or Lua(La)TeX -- typically in conjunction with the fontspec package. Since these fonts can't be used under pdfLaTeX anyway, a translation of instructions wouldn't be meaningful, right?