16

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?

  • You are confusing fontenc and fontspec in various places of your question. There are quite a number of font packages which also setup fonts for lualatex, e.g. libertine and other packages maintained by Bob Tennent. But as there exists so many fonts that you can't expect a package for everyone -- and when you get used to it you will see that calling the fonts with the fontspec commands is not so difficult. – Ulrike Fischer May 6 '15 at 15:31
  • Many fonts you find in the Font Catalogue are provided for pdflatex only ... fdfiles, tfm files etc. With LuaLaTeX, you can use open Type fonts. Some, some, font packages deal with the modern engines, check out the code for libertine.sty. – Johannes_B May 6 '15 at 15:32
  • @UlrikeFischer: Old habits... I think I have fixed all fontencs now. – Daniel May 6 '15 at 15:35
  • @Johannes_B: Sure. However, I am also sure that for most of them some OpenType version also exists, so it should be possible to describe a fontspec setup as well. – Daniel May 6 '15 at 17:05
  • I don't think it's the task of the fontspec manual to "translate" latex font commands any more than it would be the task of packages like fontenc and inputenc to "translate" fontspec's commands. I think more and more people start their latex lives directly with xelatex or lualatex, so it seems a bit anachronistic to me to include latex material into the fontspec manual. – Sverre May 13 '15 at 12:06
15

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?

  • 1
    No he will not be fine if he uses standard pdflatex packages with lualatex. Add Grüße to your example and you will see why. – Ulrike Fischer May 6 '15 at 16:35
  • 1
    @UlrikeFischer - Ummm, \documentclass{article} \usepackage[textwidth=1mm]{geometry} \usepackage[T1]{fontenc} \usepackage[utf8]{luainputenc} \usepackage{lmodern} \begin{document} x Grüße hoffen \end{document} does not hyphenate "Grüße" (but does hyphenate "hoffen") under either pdfLaTeX or LuaLaTeX. Which font are you using to get a different outcome? (I currently use MacTeX2015 pre, which features version 0.80.0 of LuaTeX and version 3.14159265-2.6-1.40.16 of pdfTEX.) – Mico May 6 '15 at 17:57
  • 1
    I've never cleaned it up, but I made small sample for LuaLaTeX with fontenc, unicode text and hyphenation: gist.github.com/michal-h21/aa57f226dc78f841dbde – michal.h21 May 13 '15 at 12:06
  • 1
    @Mico I've created Github project, I had some success, with some issues: github.com/michal-h21/luafontenc – michal.h21 May 28 '15 at 12:02
  • 1
    @koppor it would definitely need some polishing, I don't even remember that I wrote it :/ I am quite busy lately, so I cannot promise anything. but I will look at it – michal.h21 Mar 10 '18 at 6:59
4

The CMBright fonts are available in OpenType format as part of the cm-unicode project.

Granted that your file is UTF-8 encoded, you should get comparable results by doing

\documentclass{scrartcl}
\usepackage{ifluatex}

\ifluatex
  \usepackage{fontspec}
  \setmainfont{XCharter}
  \setsansfont{CMU Bright}[
    Scale=MatchUppercase
  ]
  \setmonofont{Ubuntu Mono}[ % or other monospaced font
    Scale=MatchUppercase
  ]
\else
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{charter}
  \usepackage{cmbright}
  \usepackage{beramono}
\fi

\usepackage{kantlipsum}

\begin{document}

\section{Section title}

\kant[1]

\texttt{Some text in monospaced font}

\section{Font list}

\begin{itemize}
\item Roman font: \expandafter\texttt\expandafter{\fontname\font}

\item {\sffamily Sans font: \expandafter\texttt\expandafter{\fontname\font}}

\item {\ttfamily TT font: \expandafter\texttt\expandafter{\fontname\font}}
\end{itemize}

\end{document}

There's no OpenType free version of the BeraMono fonts, as far as I know.

Output with pdflatex

enter image description here

Output with pdflatex after adding \usepackage{microtype}

enter image description here

Output with lualatex

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.