23

I cannot switch on ligatures for emdash (---) and endash (--) in LuaLaTeX. Here is my test file:

% !Mode:: "TeX:UTF-8"
\documentclass{article}
\usepackage{fontspec}
    \defaultfontfeatures{Ligatures=TeX}
    \setmainfont{Cambria}
    \setsansfont[Mapping=tex-text]{Calibri}
\usepackage{ifluatex,ifxetex}
\begin{document}

\ifxetex
    This is XeTeX
\else\ifluatex
    This is LuaTeX
\fi\fi

\section{rmfamily}
\rmfamily
\begin{enumerate}
\item <<double quote>> by ligatures \verb|<<ligatures>>|
\item «double quotes» by symbols \verb|«double quotes»|
\item en--dash by ligatures \verb|en--dash|
\item em---dash by ligatures \verb|em---dash|
\item en–dash by symbol \verb|en–dash|
\item em—dash by symbol \verb|em—dash|
\end{enumerate}

\section{sffamily}
\sffamily
\begin{enumerate}
\item <<double quote>> by ligatures \verb|<<ligatures>>|
\item «double quotes» by symbols \verb|«double quotes»|
\item en--dash by ligatures \verb|en--dash|
\item em---dash by ligatures \verb|em---dash|
\item en–dash by symbol \verb|en–dash|
\item em—dash by symbol \verb|em—dash|
\end{enumerate}

\end{document} 

When it is compiled with XeLaTeX, \sffamily loaded with the obsolete option Mapping=tex-text

    \setsansfont[Mapping=tex-text]{Calibri}

activates the ligatures --- and --, but in LuaTeX this options seemed to be equivalent to Ligatures=TeX, so that I don't know how to restore default (in LaTeX) behavior of these two ligatures.

Is it bug or a feature, introduced in a recent version of the fontspec package?

I've checked that the ligatures still work as expected under LuaTeX if I don't set OTF fonts by the commands

    \setmainfont{Cambria}
    \setsansfont[Mapping=tex-text]{Calibri}
5
  • I'm curious about your very last statement. Do you have an example where the ligatures work with Calibri as the font with LuaTeX?
    – Alan Munn
    Jun 13, 2011 at 5:01
  • @Alan, there is no such example. Jun 13, 2011 at 8:58
  • With XeTeX, I had to use the xunicode package to get em-dash working. Maybe you're missing that? \usepackage{xunicode}.
    – raphink
    Jun 13, 2011 at 10:17
  • 2
    @Raphink: As it is said in lualatex-doc.pdf the package xunicode should not be used with lualatex: Package xunicode’s main feature is to ensure that the usual control sequences for non-ASCII characters (such as \’e) do the right thing in a Unicode context. It could probably work with LuaTEX, but explicitly checks for X ETEX only. However, fontspec uses a trick to load it anyway. So, you can’t load it explicitly, but you don’t need to, since fontspec already took care of it. Jun 14, 2011 at 23:58
  • good to know.
    – raphink
    Jun 15, 2011 at 8:01

3 Answers 3

13

The TeX-ligatures in luatex are not a font property, they are "faked" features implemented in the font loader code. The problem could be the bug in the luaotfload/context code reported some month ago:

http://archive.contextgarden.net/message/20110310.181448.288f2a38.en.html

I think it has been corrected in context but I doubt that the new code has already found its way in luaotfload.

You can test the font directly (to exclude a fontspec problem and to test the both modes)

\documentclass{article}
\usepackage{luaotfload}
\begin{document}
 \font\test="Calibri:mode=node;+tlig" 

 \font\testb="Calibri:mode=base;+tlig" 
 \test -- --- abc 

 \testb -- --- abc 
\end{document}
5
  • can this be fixed temporarily by redefining \fontspec_init to set \l_fontspec_mode_tl to {base} instead of {node}? My minimal testing says yes, but I suspect that will screw up other things with other fonts. If so, is there a way to do this on a font by font basis?
    – Alan Munn
    Jun 13, 2011 at 14:58
  • 5
    @Alan: The issue is font dependant. Some fonts works with mode=base, some with mode=node, and some none at all. You can change the mode on font basis with the "Renderer" option: \setmainfont[Renderer=Basic,Ligatures=TeX]{Times New Roman} Jun 13, 2011 at 16:25
  • thanks. I've updated my answer to reflect your comments.
    – Alan Munn
    Jun 13, 2011 at 19:27
  • 1
    @UlrikeFischer: It's been a while since this issue was discussed and I'm surprised to find that the situation in LuaLaTeX still seems to be the same. I still need to set Renderer=Basic to get the em-dash with Times New Roman (\textemdash works fine though, even w/o this). Anyway: I'm wondering what the negative consequences of this are. I mean, "Basic" sounds like LuaLaTeX will not perform at its best...
    – Christoph
    Mar 17, 2013 at 3:16
  • 2
    @Christoph: There is currently - as far as I know - no development in the font handling in lualatex. The code in context is evolving but the changes are not transfered to luaotfload. Partly because keeping pace with the context code is painful (there is no real documentation), partly because the author of luaotfload has other things on his mind. Mar 17, 2013 at 14:50
11

This is partially a property of the font, and not a problem with fontspec. XeLaTeX and LuaTeX implement the ligature replacement with different mechanisms. XeLaTeX uses a teckit mapping file, whereas LuaTeX uses luaotfload to do the conversion. The latter is somehow dependent on how the font actually implements certain characters. Changing the font to Linux Libertine O, for example, causes the ligatures to appear correctly.

Update

As noted by Ulrike Fischer, you can change this on a font-by-font basis for fonts that don't work by specifying a value for the Renderer key when you load the font. There are two possible (relevant) values for this key in LuaLaTeX: Full (default) and Basic. Loading certain fonts with the Basic renderer will allow the ligatures. This will not work for all fonts, however. For more discussion, see the following thread on comp.text.tex: en-dash and em-dash in luatex.

The following modified version of your document shows how the problem doesn't arise with Linux Libertine O, and how it can be fixed for Cambria. (Calibri) works the same way.

As Ulrike notes in her answer, a more robust fix will propagate to luaotfload at some point in the future.

% !Mode:: "TeX:UTF-8"
\documentclass{article}
\usepackage{fontspec}
    \defaultfontfeatures{Ligatures={TeX}}
    \setmainfont{Cambria}
    \setsansfont{Calibri}
\usepackage{ifluatex,ifxetex}
\usepackage{expl3}
\begin{document}

\ifxetex
    This is XeTeX
\else\ifluatex
    This is LuaTeX

\fi\fi

\section{Cambria}

\begin{enumerate}
\item <<double quote>> by ligatures \verb|<<ligatures>>|
\item «double quotes» by symbols \verb|«double quotes»|
\item en--dash by ligatures \verb|en--dash|
\item em---dash by ligatures \verb|em---dash|
\item en–dash by symbol \verb|en–dash|
\item em—dash by symbol \verb|em—dash|
\end{enumerate}

\section{Linux Libertine O}
\fontspec{Linux Libertine O}\selectfont
\begin{enumerate}
\item <<double quote>> by ligatures \verb|<<ligatures>>|
\item «double quotes» by symbols \verb|«double quotes»|
\item en--dash by ligatures \verb|en--dash|
\item em---dash by ligatures \verb|em---dash|
\item en–dash by symbol \verb|en–dash|
\item em—dash by symbol \verb|em—dash|
\end{enumerate}

\section{Cambria + Basic Renderer}
\fontspec[Renderer=Basic]{Cambria}\selectfont
\begin{enumerate}
\item <<double quote>> by ligatures \verb|<<ligatures>>|
\item «double quotes» by symbols \verb|«double quotes»|
\item en--dash by ligatures \verb|en--dash|
\item em---dash by ligatures \verb|em---dash|
\item en–dash by symbol \verb|en–dash|
\item em—dash by symbol \verb|em—dash|
\end{enumerate}

\end{document}
4
  • your notation is important, but what to do if I want to use Calibri, Cambria, Times New Roman, Pallatino Linotype or many other fornt, which do not support such ligatures? As to me, I have macro written for WinEdt, wich convers --- and -- to appropriate symbols as soon as I type in --- or --. But what to do all others who have no similar macro? Jun 13, 2011 at 8:56
  • @Igor What you are doing is appropriate. There may be other ways to patch the font using lua, but I don't know how to do this. I would wait a bit to see if a more complete answer appears. (I edited my answer a bit to remove an inaccuracy in the explanation.)
    – Alan Munn
    Jun 13, 2011 at 11:26
  • Looking through fontspec.pdf, I concluded that Render key can acquire either Basic or Full value, and the latter is default. As to XeLaTeX, allowed values are AAT/ICU/Graphite. Is that correct? Jun 15, 2011 at 2:49
  • @Igor, yes that is correct. But AAT fonts are Mac only, and require a different driver (xdv2pdf) which I don't think is actively being developed. Graphite font support is minimal. See Using Graphite fonts with XeTeX.
    – Alan Munn
    Jun 15, 2011 at 4:12
7

I can't compete with the level of discussion between Ulrike and Alan. But thanks to the link provided by Alan, I found out how to get an en-dash with another of those Win-fonts: Corbel. I ran into the same problem two weeks ago and thanks to your help I know now how to handle it:

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Renderer=Basic,Ligatures=TeX]{Corbel}
\begin{document}
-- --- abc 
\end{document}

I get the en-dash and the em-dash this way. Or did I miss something and this way to get dashes is obsolete?

2
  • 2
    I guess this may well be font-dependent.
    – Joseph Wright
    Jun 19, 2011 at 9:23
  • This answer solves the two problems with quotes and en-dashed in this question This answer solves the two problems with quotes and en-dashed in this question tex.stackexchange.com/questions/118008/… for Cambria font.
    – alfC
    Jun 6, 2013 at 22:44

You must log in to answer this question.

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