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é-Gonnard’s Guide to LuaLaTeX):
- Don’t load
inputenc
; just encode your source in UTF-8.- Don’t load
fontenc
ortextcomp
; loadfontspec
.babel
works with LuaLaTeX but you can loadpolyglossia
instead.- 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 thefontspec
package as well.For instance, the program
produces the same output when run under either pdfLaTeX or LuaLaTeX:
Likewise, the program
produces the same output when compiled with either pdfLaTeX or LuaLaTeX:
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 optionutf8
. With this adjustment made, the following codeonce again produces identical results when compiled under pdfLaTeX and LuaLaTeX:
Excerpting from the user guide of the
luainputenc
package: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 usingpdflatex
. Hence, in the long run it may nevertheless be a good idea to switch tofontspec
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?