8

Why are my ligatures not working?

\documentclass[12pt,a4page]{article}
\usepackage{fontspec}
\setmainfont[FeatureFile=pytanie.fea,
 Path = /usr/share/fonts/dejavu/,
 Extension=.ttf]{DejaVuSerif}
\begin{document}
ambona amarant żółw flaming i filharmonia.

młot
\end{document}

File pytanie.fea

languagesystem DFLT dflt;
languagesystem latn dflt;
feature liga {
 sub \a \m by \fl;
 sub 0061 by uniF731;
 sub m ł by uni0062;
} liga;

I need convert am to standard ligature f_l, a to unicode char F731, and to b.

  • you do not need to specify Path = /usr/share/fonts/dejavu/. It is the system path and already searched for fonts. – user2478 Feb 16 '16 at 7:02
  • 1
    Your use of the term "ligatures" is somewhat nonstandard: To "ligate" two or more items is to join them in some way. Replacing with b or am with f_l probably shouldn't be called ligation; I'd use the term "glyph substitution" for such an activity. – Mico Feb 16 '16 at 8:13
5

I can't tell you why the featurefile-based approach isn't working. Fortunately, though, it's not too difficult to write a Lua function and a couple of TeX-side "wrapper" macros (named \myligsOn and \myligsOff) to perform the glyph substitutions directly.

In the code below, I've switched the font from DejaVuSerif to Garamond Premier Pro, as the former doesn't seem to have a glyph at position uniF731.

enter image description here

% !TEX TS-program = lualatex
\documentclass{article}

%% load fontspec package and specify main font
\usepackage{fontspec}
\setmainfont{Garamond Premier Pro}% -- DejaVuSerif has no glyph at pos. F731

%% Lua-side code 
\usepackage{luacode}
\begin{luacode*}
function myligs ( s )
   s = unicode.utf8.gsub ( s , '(\\?)([%a@]+)' , function( backslash, text )
   -- no substitutions inside (La)TeX macros
       if backslash=='' then 
           text = unicode.utf8.gsub (text, 'mł', 'b' )  
           text = unicode.utf8.gsub (text, 'am', 'fl' )  
           text = unicode.utf8.gsub (text, 'a', '\\char"F731' )  
       end
       return backslash .. text
   end)
   return s
end
\end{luacode*}

%% TeX-side code
\newcommand\myligsOn{\directlua{luatexbase.add_to_callback(
      "process_input_buffer", myligs, "myligs")}}
\newcommand\myligsOff{\directlua{luatexbase.remove_from_callback(
      "process_input_buffer", "myligs")}}

\begin{document}

\myligsOn
\small  % Note: The 'a' in '\small' is *not* being converted to '\char"F731'.
mł am a

\myligsOff
mł am a
\end{document}
  • Commands are not only the things with backslashs. Try out \begin{enumerate}. Also one would have to disable the callback at math. One the whole I find a replacement at the font label safer and easier to use as a change in the input buffer. – Ulrike Fischer Feb 16 '16 at 8:26
  • Wonderfull. Is posible to hypenation words with ligatures? \hyphenation{ła-ma-nie} \begin{minipage}[t]{32mm} Test: Bo tuto nasze łamanie wiersza jest trudne. mł am ta. \end{minipage} – Marko Lustro Feb 16 '16 at 9:43
  • is posible to add escaping other TeX constants? when i add text = unicode.utf8.gsub (text, 'c', '\\char"F731' ) i canot use 'cm' is possible to not using cm,mm,pt,m inch etc? – Marko Lustro Feb 16 '16 at 9:45
  • @MarkoLustro - Glad my answer is useful for you. The questions you raise in your follow-up comments are substantially new. May I therefore ask you to post new queries? By the way, are you really looking to replace (almost all) occasions of the letters a and c, or were they just meant as examples? – Mico Feb 16 '16 at 10:38
  • I create conlang, (BTW is possible to write to You email? my do1234staniesz_nowy@vp.pl without numbers) I need complicated ligatures and posiblility to write sounds. – Marko Lustro Feb 19 '16 at 14:44

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.