[Tex/LaTex] Can we stop recommending fontspec as first choice in case lualatex is used

font-encodingsfontsfontspecinput-encodingslualatexluatexpdflatex

This question may belong on Meta, please move it in that case, I'm not sure.


This answer made me think again why almost everybody is recommending loading fontspec in case is used. I see just a very few answers around, which share a neutral point of view. In my opinion the frequently given general advice is misleading and should not be given without mentioning the disadvantages as well. I'll try to explain.


Quite some time ago I changed from to for the following reasons:

  • natural support of unicode encoded source files, I know there are solutions for pdflatex as well, but there are cases you just can't fix any issues regarding umlauts and other accented characters, e.g. in bib files.
  • a lot of useful lua-only packages
  • support of lua-code in general

Using unicode fonts was never my intention.

Before I switched to lualatex, I read a lot here on TeX.se about what that actually means. And I always read "load fontspec", so I did. On the first sight using unicode fonts just seemed a very nice idea – until it comes to math. The number of supported unicode math fonts is rare, sans serif math fonts are even rarer and cost a lot of money. But even for my desired serif math font I spent days trying to fix all issues I encountered, without success. Apart from that fontspec is still very slow (see benchmark below) and it highly hampers my workflow.

So I dismissed fontspec and used luainputenc and fontenc, I never encountered any serious problem again and would highly recommend this combination to everybody. And it "hurts" me if fontspec is recommended to new users without mentioning its drawbacks.


So please enlighten me. Apart from being able to use all kinds of fancy unicode fonts, because the hundred non-unicode fonts don't make you happy, apart from that – is there any real reason why one should use fontspec?

And if not, can we please stop recommending it?


Regarding the comments

  • I have thrown fontspec and unicode-math into one pool, which may have been one step too far for my slightly provocative intention. Using unicode-math math as well appears to be the logical consequence though.*1
  • I agree with Ulrike Fischer, that there are languages or scripts which are in need of fontspec. But in this case users want to use fontspec and compile with lualatex as a consequence. I'm referring to the opposite case: a user compiles with lualatex and is told to use fontspec – which is not a logical consequence per se.

*1 Imagine you load fontspec, then you type \setsansfont and \setmainfont. The next logical step for a lot of beginners would be \setmathfont. There comes an error, so the user probably would rather load unicode-math, than dismissing \setmathfont and load a classic math font package.


Benchmark

In the comments there was an actual benchmark for my allegations requested, here it is.

I used the batch code from this answer to time the compilation multiple times:

@echo off
@setlocal 

set start=%time%

:: runs your command
lualatex.exe -synctex=1 -interaction=nonstopmode -enable-write18 document.tex

set end=%time%
set options="tokens=1-4 delims=:.,"
for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100

set /a hours=%end_h%-%start_h%
set /a mins=%end_m%-%start_m%
set /a secs=%end_s%-%start_s%
set /a ms=%end_ms%-%start_ms%
if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
if %hours% lss 0 set /a hours = 24%hours%
if 1%ms% lss 100 set ms=0%ms%

:: mission accomplished
set /a totalsecs = %hours%*3600 + %mins%*60 + %secs% 
echo command took %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)

pause 

I used it to execute the compilation of an article:

\documentclass[a4paper]{article}

\usepackage[utf8]{luainputenc}
\usepackage[T1]{fontenc}
\usepackage{pxfonts}

%\usepackage{fontspec}
%\setmainfont{Minion Pro}

\usepackage{pgffor}
\usepackage{blindtext}

\begin{document}

\foreach \n in {0,...,100}{
\blindmathpaper
}
\end{document}

and a beamer presentaton:

\documentclass{beamer}

\usepackage[utf8]{luainputenc}
\usepackage[T1]{fontenc}
\usepackage{pxfonts}

%\usepackage{fontspec}
%\setmainfont{Minion Pro}

\usepackage{pgffor}
\usepackage{lipsum}

\begin{document}

\foreach \n in {0,...,100}{
\begin{frame}
\lipsum
\end{frame}
}
\end{document}

And the results are

  • article without fontspec: 1.9 sec
  • article with fontspec: 7.2 sec
  • beamer without fontspec: 4.3 sec
  • beamer with fontspec: 8.8 sec

These seconds add up during the day.


Bottom Line

After all comments and answers I must seem very stubborn to you and I'm sorry for that. Thanks for your input, I agree with your arguments now. But I also think this case is not that trivial, as my initial approach just works great, despite all warnings in some manuals. And I don't know how many average users read manuals on font encoding or just copy&paste working code.

So it boils down to the fact that using fontspec is the way to go and should be recommended. It's slower, so we hope it gets faster in the future. Until then on could stubbornly ignore warnings and use luainputenc at own risk.

Thank you, I learned a lot.

Best Answer

One reason to rely on fontspec over luainputenc comes from the package documentation of the second package. The abstract says simply:

Input encoding management for LuaTeX, needed only for compatibility with old documents. For new documents, using UTF-8 encoding and Unicode fonts is strongly recommended. You’ve been warned!

Then, the first section of the document, entitled "Overview: When (not) to use this package" reads:

This package is strictly meant for compatibility. It is usefull [sic] in the two (overlapping) following cases:

  1. Your source is not encoded in UTF-8 and you don’t want to reencode it for some reason.
  2. Your document is using legacy 8-bit fonts (with fontenc), as opposed to modern Unicode fonts (most probably with fontspec or luaotfload and fontenc with option EU2).

The same section then continues (in part):

luainputenc has several modes of operation. By default, it basically turns LuaTEX into an 8-bit engine, which means you loose half of the benefits from using LuaTEX.

In any event, I think it is fairly clear that, as the author of the package himself does not recommend using luainputenc for "new" documents, there is little reason for others to recommend it to other users. It does not seem to be recommended for the purpose you are using the package. (Which is perhaps fine: you have taken the time to explore what best suits your needs.)

Of course, one may choose to use this package over fontspec (I wish LuaTeX-based documents compiled more quickly, too!), but it seems a stretch to say that fontspec (or luaotfload) should not be recommended---especially to new users---before luainputenc. I am certainly not inclined to do so.