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).))

17
  • 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
    Commented Nov 3, 2015 at 20:26
  • See updated answer for that.
    – NVaughan
    Commented Nov 3, 2015 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
    Commented Nov 3, 2015 at 20:34
  • @Thérèse Thanks, although it is unrelated (it doesn't fix the problem).
    – NVaughan
    Commented Nov 3, 2015 at 20:39
  • 1
    @Thérèse It happens with all fonts; I think LetterSpace is broken in LuaTeX.
    – egreg
    Commented Nov 3, 2015 at 20:44

1 Answer 1

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.

9
  • 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
    Commented Nov 3, 2015 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
    Commented Nov 3, 2015 at 23:51
  • 1
    @egreg make a plain example and report on luatex list? Commented Nov 4, 2015 at 0:27
  • 1
    @DavidCarlisle I'm inclined to think it's more luaotfload than LuaTeX.
    – egreg
    Commented Nov 4, 2015 at 7:22
  • 1
    @UlrikeFischer WordSpace changes \fontdimen and acts globally.
    – egreg
    Commented Nov 4, 2015 at 11:23

You must log in to answer this question.

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