# Selectively disable dash ligatures in LuaLaTeX

With pdfLaTeX, I can print two hyphens using -{}-. This does not seem to work in LuaLaTeX.

Indeed, the following snippet

\documentclass{minimal}
\begin{document}
en dash -- two dashes -{}-
\end{document}


prints

en dash — two dashes --

when compiled with pdflatex, but

en dash — two dashes —

when compiled with lualatex.

How do I print -- in LuaLaTeX without disabling ligatures completely?

-

I suppose you don't want to introduce break points at the double hyphen. Here's a way.

\documentclass{article}
%\usepackage{fontspec} % works also with fontspec

\newcommand{\texthyphen}{} % ensure \texthyphen is not defined
\protected\def\texthyphen{\mbox{-}}

\begin{document}
en dash -- two dashes \texthyphen\texthyphen

\textit{en dash -- two dashes \texthyphen\texthyphen}

\textbf{en dash -- two dashes \texthyphen\texthyphen}

\strut \vrule-\vrule\ \textit{\vrule-\vrule} \textbf{\vrule-\vrule}
\end{document}


The \protected is just to avoid the command being expanded when in moving arguments, but it's not really necessary.

I add a graphic analysis of the hyphen's placement with respect to its bounding box.

-
Just to clarify: The methods that rely on using an italics correction, -\/-, or an explicit zero-width kern, -\kern0pt- don't allow line breaks either between the two dashes. –  Mico Nov 24 '13 at 18:51
@Mico This is true for LuaLaTeX, but not for pdflatex or XeLaTeX –  egreg Nov 24 '13 at 19:22

Indeed, the method of breaking up ligatures by inserting an empty TeX group, {}, does not work in LuaTeX and LuaLaTeX. To prevent the creation of an en-dash, then, you could insert a "zero-width kern", i.e.,

-\kern0pt-


or an explicit "italic correction", i.e.,

-\/-


With either method, LuaTeX will not insert a line break between the two dashes.

If you have many instances of such double-dashes, you may want to create a dedicated macro called, say, \dbldash, to streamline your typesetting:

\newcommand{\dbldash}{-\kern0pt-}


Here's an illustration of the result of using \dbldash:

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Latin Modern Roman}
\newcommand\dbldash{-\kern0pt-\ }
\begin{document}
dash - endash -- double-dash \dbldash
\end{document}


Aside: At least if the Computer Modern (and Latin Modern) font family is in use, employing either the -\kern0pt- or the -\/- method while in italics mode will result in slightly more whitespace being inserted between the two dashes; this amount is the same irrespective of which of the two methods is in use. The cause of this increased space between the dashes would appear to be the fact that the "side-bearing" (the glyph-associated white-space) in front of (but not the one behind) the dash-character is slightly more generous in the italic font shape than they are in the upright font shape.

Addendum: @egreg's parallel answer shows explicitly that there's a non-zero side-bearing in front of but not behind the dash character when it occurs in italic mode, at least for the Computer Modern font family. In contrast, there's a somewhat smaller non-zero side-bearing after, but not before, the dash character in the plain-upright and bold-upright font shapes. These differences in side-bearings cause the differences in whitespace between the plain-upright and italic font shapes.

-
Thanks for the detailed explanations! I wonder why {} doesn't work anymore though. –  Clément Nov 24 '13 at 16:48
@Clément - I guess you'd have to ask the authors of LuaTeX... I suppose they did so because various house-keeping chores are simplified if empty text-mode TeX groups (or anything that evaluates to an empty TeX group) are removed prior to commencing the paragraph-building process. –  Mico Nov 24 '13 at 17:00