为何我的连字不起作用?
\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}
文件pytanie.fea
languagesystem DFLT dflt;
languagesystem latn dflt;
feature liga {
sub \a \m by \fl;
sub 0061 by uniF731;
sub m ł by uni0062;
} liga;
我需要转换am
为标准连字符f_l
、
a
unicode 字符F731
和mł
。b
答案1
我无法告诉你为什么基于特征文件的方法不起作用。不过幸运的是,编写一个 Lua 函数和几个 TeX 端“包装器”宏(名为\myligsOn
和\myligsOff
)来直接执行字形替换并不太难。
在下面的代码中,我将字体从 切换DejaVuSerif
为Garamond Premier Pro
,因为前者在位置 处似乎没有字形uniF731
。
% !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}