3

Using lualatex, TeXlive 2023.

I have discovered something that works using "brute force". Now, I would like to make it work "according to the rules".

Situation: In a word processor, two hyphens -- are converted to emdash. But it is three hyphens --- in plain text, which TeX Ligatures (feature tlig) converts to emdash. Having read TeX tutorials (!) the user types --- into a word processor, which is immediately changed to emdash followed by a hyphen. This is hard to notice. When the text is exported to plain text, then typeset by LuaLaTeX, the result is emdash followed by hyphen (also hard to notice in the PDF).

Desired result: Have LuaLaTeX convert the emdash hyphen, into only an emdash. There is no known occasion that requires emdash followed by hyphen.

Brute Force solution (works): In file luaotfload-features.lua add the following code, immediately after the emdash tlig is defined:

[0x2014] = {0x2014, 0x002D},

My question: Other than hacking file luaotfload-features.lua, how can that be done?

Comment: Literary authors often have to communicate with an editor, who will only review files in MS Word format (without any TeX markup).

1 Answer 1

7

First a note regarding the "Brute Force solution": While it does successfully turn —- into , it breaks the normal --- ligature which afterward gets turned into –- (an en-dash followed by a hyphen).

Generally changing the behavior of existing features is a bad idea since they no longer behave in expected ways and it's hard to find out where changes come from. Instead such changes can be done by adding a new custom feature (which then can be enabled by default in e.g. fontspec if desired). This could be done by adding in the preamble:

\directlua{
  fonts.handlers.otf.addfeature {
    name = 'rallg_hyphens',
    type = 'ligature',
    data = {
      [0x2014] = {0x2014, 0x002D},
    },
  }
}
% To enable it by default in fontspec similar to tlig also add:
\defaultfontfeatures+
 [\rmfamily,\sffamily]
 {RawFeature=rallg_hyphens}
1
  • Thanks. I had noticed custom features mentioned, but was not sure how they worked. I had not noticed that the ordinary -- would break.
    – user287367
    Commented May 4, 2023 at 18:18

You must log in to answer this question.