24

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.

14
  • 2
    Not sure this can be answered as it or the answers themselves are likely to be at least in part opinion-based, but there are real technical reasons why the recommendation is made.
    – Joseph Wright
    Nov 12, 2016 at 16:41
  • 3
    For most languages of the world, there are simply no good fonts usable in LaTeX without fontspec without massive effort. Nov 12, 2016 at 16:51
  • 2
    As is clear from Ulrike Fischer's answer, most of the alleged disadvantages of 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. Nov 12, 2016 at 22:21
  • 2
    @ShreevatsaR I agree with you, regarding unicode-math - for me using 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. Nov 13, 2016 at 12:08
  • 6
    Note that the slowness does not come from fontspec, but from luaofload which loads fonts using only Lua code and is quite slow as you have seen. If at some point a better and more performant font loader is made available for LuaTeX, the performance issue will be moot. Dec 2, 2016 at 2:04

2 Answers 2

14

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.

18

fontspec doesn't change the math setup to unicode math fonts -- this is done by unicode-math -- it only change some math alphabet like \mathrm and with the option no-math you could avoid this too. So if you have a good (sans-serif)math setup that works with pdflatex or with lualatex and luainputenc you can use it with lualatex and fontspec too.

Beside this you seem to have a quite "english writer" view and don't bother about other scripts. I believe you that you choose luatex because of the lua scripts. But most people switch to xelatex or lualatex to be able to use system fonts and to easily write in non-latin scripts -- you only need to look at lualatex related questions to see this.

17
  • 1
    @thewaywewalk Many standard font packages will load fontspec if XeLaTeX or LuaLaTeX is used anyway.
    – cfr
    Nov 12, 2016 at 19:42
  • 2
    @thewaywewalk: As I wrote the large majority of users use lualatex either because a non-latin script or/and because they want to use system fonts/house fonts etc. For both they need fontspec. Your case is quite special and so imho the default recommendation should be fontspec. Nov 12, 2016 at 20:58
  • 2
    @thewaywewalk: There are around 1890 question here with "lualatex" and only 54 of them also with "directlua" and 35 with "luacode". Beside this I'm quite active in other groups and also have quite a number of customers where the relation is similar. Nov 13, 2016 at 12:50
  • 4
    I don't know why the user in your question wants to use lualatex instead of pdflatex, but from the use of inputenc in his example it is obvious that he doesn't know much about the inner working of input encoding and font encodings. I wouldn't recommend to such a user a special system like luainputenc which make lots of chars active, installs a callback and works only for a restricted unicode block instead of a standard setup with fontspec. As argument against fontspec you only have the speed now that you removed the wrong remarks regarding math. Nov 13, 2016 at 16:12
  • 1
    @thewaywewalk You are talking about recommendations for beginners. They are much more likely to just say \usepackage{<font I want>} than to realise that it is loading fontspec and that they can disable this. So, with your recommendation, they will end up with not only the disadvantages of luainputenc but conflicts between what it is trying to do and what fontspec is trying to do. That will not make for a happy outcome.
    – cfr
    Nov 13, 2016 at 23:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .