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 lualatex 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 pdflatex to lualatex 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
andunicode-math
into one pool, which may have been one step too far for my slightly provocative intention. Usingunicode-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 usefontspec
and compile with lualatex as a consequence. I'm referring to the opposite case: a user compiles with lualatex and is told to usefontspec
- 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.
fontspec
you mention are simply false. They seem to arise from your trying to unicode-math, which is unrelated. (And moreover, the purpose of fontspec is to use fonts installed on your system; if you don't have an acceptable font installed that is not the fault of fontspec.) The only drawback is that, apparently, fontspec makes your compilation a bit slower (but you haven't elaborated by how much). I haven't seen this in practice, but it may be so. So your question is based almost entirely on false premises.unicode-math
as well is a logical consequence. The problem with the compilation speed remains though. If I'd knew a proper procedure to benchmark it, I'd be glad to do it. It does not feel just a bit slower, especially not with beamer. So, to say, that most disadvantages are false and my question is "based almost entirely on false premises" is not quite fair. But feel free to provide an answer and proof me wrong, because that's the entire purpose of this question. I want to provoke and I'd be happy proven wrong.