11

I have a problem with LuaLaTeX and interword spacing using fontspec. This is my MWE:

\documentclass{article}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX, Scale=MatchLowercase}
\setmainfont[Ligatures=Common,
  SmallCapsFeatures={Renderer=Basic},
  ]{Times New Roman}
\usepackage{microtype}
\begin{document}

\LARGE\addfontfeatures{LetterSpace=30.0}
THIS IS A TEST

\end{document}

This is the output:

enter image description here

As you can see, the interword space remains unchanged as the interchar space (letterspace) has augmented (in fact, it is even smaller than it). I had assumed the latter would change proportionally with respect to the former, as it actually happens when compiled using XeLaTeX. See the output of the same code compiles with XeLaTeX

enter image description here

How can I fix this automatically (i.e. without having to fiddle with fontspec's WordSpace argument)?

(I'm running TeXLive 2015 in Xubuntu Linux 15.10, with the latest updates. (LuaLaTeX version beta-0.80.0 (TeX Live 2015) (rev 5238).))

NVaughan
  • 8,175
  • Which TeX distribution, which vintage of both LuaTeX and XeTeX, and which version of fontspec in installed on your system? The reason I ask is that on my system -- MacTeX2015, LuaTeX 0.80.0, XeTeX 3.14159265-2.6-0.99992, fontspec 2.4e -- the outcome is the same when I compile your MWE under LuaLaTeX and XeLaTeX; what I get corresponds to the first of the two screenshots you've posted. – Mico Nov 03 '15 at 20:26
  • See updated answer for that. – NVaughan Nov 03 '15 at 20:33
  • Instead of SmallCapsFeatures={Renderer=Basic}, use something like SmallCapsFeatures={LetterSpace=5}. There’s no need for Renderer=Basic here. – Thérèse Nov 03 '15 at 20:34
  • @Thérèse Thanks, although it is unrelated (it doesn't fix the problem). – NVaughan Nov 03 '15 at 20:39
  • I'd use something like \textls[200]{THIS IS A TEST}. – egreg Nov 03 '15 at 20:41
  • 1
    @Thérèse It happens with all fonts; I think LetterSpace is broken in LuaTeX. – egreg Nov 03 '15 at 20:44
  • @Thérèse Yes, I tested it with other fonts and the problem persists. – NVaughan Nov 03 '15 at 20:46
  • @egreg Not sure what to expect from using \textls[200]{THIS IS A TEST} . I seem to get no change in the letter spacing. – NVaughan Nov 03 '15 at 20:47
  • Does your version of Times New Roman have the cpsp feature? Kerning=Uppercase is not broken, and it may serve your immediate needs, though it’s very unlikely to give you as much spacing as you seem to want. – Thérèse Nov 03 '15 at 21:01
  • @NVaughan It's the microtype way of specifying letter spacing. Remove the \addfontfeature instruction. – egreg Nov 03 '15 at 21:39
  • @egreg I don't understand. I need the extra spacing in that line. What you're saying is that I should request it using microtype instead of fontspec? – NVaughan Nov 03 '15 at 21:44
  • @NVaughan Yes, that's what I'm saying. With \textls (pr \lsstyle, which is the corresponding declaration) it works, at least on my machine. – egreg Nov 03 '15 at 21:44
  • @Thérèse No, it doesn't. – NVaughan Nov 03 '15 at 21:46
  • @egreg So I can either add WordSpace=3.0 to fontspec or instead use microtype's \lsstyle[3000]{...}, right? Is this a bug? – NVaughan Nov 03 '15 at 21:50
  • Monkeying with WordSpace is not recommended. I said in a previous comment that LetterSpace seems to be broken in LuaTeX. But using microtype features seems to work. Don't confuse \textls with \lsstyle. – egreg Nov 03 '15 at 21:59
  • The latest version of luaotfload, which is just making its way to CTAN mirrors today, seems to have fixed this problem. :-) – Thérèse Jan 25 '16 at 17:44
  • @egreg This bug is still present, contrary to what github.com/lualatex/luaotfload/issues/297 says, isn't it? I tested egreg's example and the six letters are still rendered as "A_B_C_D_E_F", not "A_B__C_D__E_F". Used LuaTeX Version 0.95.0 (TeX Live 2016), luaotfload-letterspace.lua is v2.7 but part of the 2.8rc3 bundle. – PhilipPirrip Dec 01 '16 at 09:57

1 Answers1

13

Let's try simplifying the example.

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Latin Modern Roman}
\begin{document}

\addfontfeatures{LetterSpace=30.0}

AB CD EF

\showoutput

\end{document}

This is the relevant part from the log file when compiling with LuaLaTeX:

....\hbox(0.0+0.0)x15.0, direction TLT
....\EU2/LatinModernRoman(1)/m/n/10 A
....\kern 3.0
....\EU2/LatinModernRoman(1)/m/n/10 B
....\glue 3.33 plus 1.66331 minus 1.1111
....\EU2/LatinModernRoman(1)/m/n/10 C
....\kern 3.0
....\EU2/LatinModernRoman(1)/m/n/10 D
....\glue 3.33 plus 1.66331 minus 1.1111
....\EU2/LatinModernRoman(1)/m/n/10 E
....\kern 3.0
....\EU2/LatinModernRoman(1)/m/n/10 F

and here's the same when XeLaTeX is used:

....\hbox(0.0+0.0)x15.0
....\EU1/LatinModernRoman(1)/m/n/10 AB
....\glue 6.33 plus 3.16182 minus 2.1121
....\EU1/LatinModernRoman(1)/m/n/10 CD
....\glue 6.33 plus 3.16182 minus 2.1121
....\EU1/LatinModernRoman(1)/m/n/10 EF

The model used for representing letter spacing is different, so XeTeX doesn't show the interletter kerns. However, this shows where LuaLaTeX (or more probably luaotfload) goes wrong: in XeTeX also the interword space is multiplied by the spacing factor, which it isn't in LuaTeX.

Between the two letter groups we have

....\glue 3.33 plus 1.66331 minus 1.1111

in LuaTeX, while it is

....\glue 6.33 plus 3.16182 minus 2.1121

If I remove the \addfontfeatures line, the glue is the same in both engines.

If I change the font to Times New Roman, I get

....\glue 2.5 plus 1.24875 minus 0.83415

in LuaTeX (just like when LetterSpace is not added), but

....\glue 5.5 plus 2.74724 minus 1.83516

in XeTeX.

To make the bug clear: in XeTeX the amount of letter spacing is also added to the interword space, but this is not done in LuaTeX.

My suggestion is to use microtype letter spacing in LuaLaTeX:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\usepackage{microtype}

\begin{document}

\textls[400]{AB CD EF}

\showoutput

\end{document}

produces

....\EU2/TimesNewRoman(0)/m/n/10/400ls A
....\EU2/TimesNewRoman(0)/m/n/10/400ls B
....\glue 3.5 plus 1.24875 minus 0.83415
....\EU2/TimesNewRoman(0)/m/n/10/400ls C
....\EU2/TimesNewRoman(0)/m/n/10/400ls D
....\glue 3.5 plus 1.24875 minus 0.83415
....\EU2/TimesNewRoman(0)/m/n/10/400ls E
....\EU2/TimesNewRoman(0)/m/n/10/400ls F

which is comparable to the XeTeX output and the result is

enter image description here

Here is a plain TeX example:

\input ifluatex.sty

\ifluatex
  \input luaotfload.sty
  \font\test=LatinModernRoman:mode=node;script=latn;language=DFLT;+tlig;+trep;letterspace=30
\else
  \font\test="Latin Modern Roman/OT:script=latn;language=DFLT;mapping=tex-text;letterspace=30"
\fi
\test

AB CD EF

\tracingoutput=1
\tracingonline=1
\showboxbreadth=\maxdimen
\showboxdepth=\maxdimen

\bye

If run with LuaTeX, the output shows

...\test A
...\kern 2.7
...\test B
...\glue 3.087 plus 1.54195 minus 1.03003
...\test C
...\kern 2.7
...\test D
...\glue 3.087 plus 1.54195 minus 1.03003
...\test E
...\kern 2.7
...\test F

If run with XeTeX, it shows

...\test AB
...\glue 6.33 plus 3.16182 minus 2.1121
...\test CD
...\glue 6.33 plus 3.16182 minus 2.1121
...\test EF

so the problem is not due to interaction with LaTeX. If the letterspace bit is removed, the interword glue turns out to be 3.087pt with LuaTeX and 3.33pt with XeTeX.

egreg
  • 1,121,712
  • 1
    Isn't this the same problem as I addressed in this question, for which you also provided an answer (but a very different one)? – Sverre Nov 03 '15 at 23:47
  • @Sverre I don't think so; I believe that in that context only XeLaTeX was of a concern. The problem was different, anyway. – egreg Nov 03 '15 at 23:51
  • 1
    @egreg make a plain example and report on luatex list? – David Carlisle Nov 04 '15 at 00:27
  • 1
    @DavidCarlisle I'm inclined to think it's more luaotfload than LuaTeX. – egreg Nov 04 '15 at 07:22
  • @egreg yes but the main part of that is extracted from context so pinging Hans on luatex list still works:-) – David Carlisle Nov 04 '15 at 07:46
  • @DavidCarlisle: The code (luaotfload-letterspace.lua) says in various place that "it is far inferior to the original" (context code) and "is quite inefficient compared to Context’s attribute based approach, but Xetex compatibility reduces our options significantly." So imho luaotfload is probably the part which must be improved. – Ulrike Fischer Nov 04 '15 at 09:12
  • @DavidCarlisle: Well I can't improve luaotfload, but I can add an issue. But I'm not quite sure that it is a bug or only a nuisance, after all you can change the word space too. It would be also interesting to know if there is luatex counterpart to \pdfinterwordspaceon – Ulrike Fischer Nov 04 '15 at 11:10
  • 1
    @UlrikeFischer WordSpace changes \fontdimen and acts globally. – egreg Nov 04 '15 at 11:23
  • @egreg: Yes I know, but normally I would add LetterSpace to a specific font face anyway (and not through \addfontfeatures), so imho it wouldn't matter much. – Ulrike Fischer Nov 04 '15 at 11:29