2

I have finally caved and made the switch to LuaLaTeX, allowing me the proper use of UTF-8 everywhere and, of course, the use of \usepackage{fontspec}:

\usepackage{fontspec}
\setmainfont[Numbers={OldStyle, Proportional}, Ligatures={TeX}]{Minion Pro}

My question is: Where are those common “TeX-Ligatures” defined, and how do I modify (read: add to) them? (I am not above hacking some core (Lua)(La)TeX files, mind you.)

-- becomes an n-dash, --- an m-dash: that is all good and proper, but there are a few others, most pressingly ... (three dots) becoming … (proper ellipsis).

9
  • The question "Where are those common “TeX-Ligatures” defined" is (most likely unintentionally) unclear: There are both "common ligatures" and "TeX ligatures" -- and the terms aren't synonyms. Please clarify what you're trying to achieve. – Mico Oct 31 '20 at 10:13
  • 1
    I guess I am referring to TeX-Ligatures and not “common” ligatures in the strict sense. When I enter -- (hyphen hyphen) in my document I am seeing – (endash) in the rendered PDF (created by LuaLaTeX), likewise --- (hyphen hyphen hyphen) becomes — (emdash). I would like to modify / add to that list. – Ingmar Oct 31 '20 at 10:28
  • 1
    Xelatex can use mapping files (search for xelatex teckit) which do regex replacement at font-level, for example, typing puo produces . You can create your own maps. They are activated as a fontspec option. Alternatively, with utf-8 file format, unicode characters can be typed in (or input via the text editor) directly, æ ¾ ą — ℉ ℊand so on. Alternatively again, for small volumes, the charcode method can be used: ^^^^^13153 produces 𓅓, Egyptian hieroglyph G017 owl. Figure dash, en dash and em dash (‒ – —) are U+2012, U+2013, U+2014. – Cicada Oct 31 '20 at 23:30
  • @Cicada That's an interesting approach, thanks for that. Too bad it's only available for XeTeX. (I already rely heavily on directly entered UTF-8 characters. I can certainly enter – (n-dash) and — (m-dash) directly, but there is no proper ellipsis in my keyboard layout.) – Ingmar Nov 4 '20 at 5:28
  • Mathematical symbols are not on the keyboard either. Why not use that same approach: define a macro \newcommand\mydots{^^^^2026} and use it: X \mydots Y. Does it have to be Tex ligatures? – Cicada Nov 4 '20 at 8:10
4

It is not really visible, but if you copy&paste you can see that it works:

\documentclass{article}
\usepackage{fontspec}
\directlua{
fonts.handlers.otf.addfeature{
    name = "dotlig",
    type = "ligature",
    data = {
      [0x2026] = { ".", ".", "." },
    },
  }

}
\setsansfont{texgyreheros}[RawFeature=+dotlig;]
\setmainfont{texgyretermes}[RawFeature=+dotlig;]
\begin{document}
some text .... some text

\sffamily 

some text .... some text 
\end{document}
1
  • 1
    +1. :-) Not sure what you mean by "not really visible", though. To my eye, there's a rather noticeable difference between the outputs of ... and .\kern0pt.\kern0pt. – Mico Oct 31 '20 at 12:00
3

There are several ways to accomplish your objective. One of them -- I trust additional methods will be posted by other readers -- is to employ LuaTeX's process_input_buffer callback to replace all instances of ... with \dots. This approach ensures that text-style ellipses will be used in text mode and math-style ellipses will be used in math mode. If you want text-mode ellipses throughout the entire document, you should replace

  s = s:gsub ( '%.%.%.', '\\dots{}' ) 

with

  s = s:gsub ( '%.%.%.', '\\char"2026{}' )

in the Lua function shown below.

An advantage of this preprocessor-based approach is that you have to run the code just once, for the entire document. A potential disadvantage could be that you can't disable or enable this feature selectively for some fonts but not for others.

enter image description here

\documentclass{article}
\usepackage{fontspec} % 'Ligatures={TeX,Common}' is enabled by default
\setmainfont{Minion Pro}[Numbers={OldStyle,Proportional}]
\setsansfont{Myriad Pro}[Numbers={OldStyle,Proportional}, Scale=MatchLowercase]

\usepackage{luacode}
\begin{luacode}
function dots2ellipsis ( s ) 
  s = s:gsub ( '%.%.%.', '\\dots{}' ) 
  return s
end
\end{luacode}

\AtBeginDocument{\directlua{luatexbase.add_to_callback ( 
   "process_input_buffer" , dots2ellipsis , "dots2ellipsis" )}}
   

\begin{document}
abc123 -- --- ... | $...$

\sffamily
abc123 -- --- ... | $...$
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.