我想利用这个答案的成对字距调整:https://tex.stackexchange.com/a/370469/75284使用fonts.handlers.otf.addfeature
连字符 调整字符对的字距-
。直接输入连字符可以正常工作,但我还想使用 babel 简写"=
和"~
并让它们也调整字距。如何做到这一点?
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\directlua{fonts.handlers.otf.addfeature
{
name = "ktest",
type = "kern",
data = {["-"] = { ["V"] = -300 }}}
}
\setmainfont[RawFeature=+ktest]{Times New Roman}
\begin{document}\obeylines
Test-Versuch
Test"=Versuch
Test"~Versuch
\end{document}
任何其他针对字距调整lualatex
和 Babel 简写的解决方案也都会受到欢迎。
答案1
我已成功将连字符和 V 之间的常规字距扩展到自由字距。不幸的是,我不知道如何访问用户定义的字距 :( 这就是为什么这不是真正的答案。
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{fontspec}
\directlua{
local function is_hyphen(item)
return item.id == node.id("glyph") and item.char == 45
end
%
local function insert_breakpoint(head)
for item in node.traverse(head) do
if is_hyphen(item) then
% Get current char and font
local char = item.char
local font = item.font
% Get next char and font
local next = node.next(item)
local nextchar = next.char
local nextfont = next.font
% Determine required skip size but only if fonts are equal
local hskip = node.new("glue",0) % subtype 0 = "userskip"
if font == nextfont then
local data = fonts.hashes.identifiers[font]
local kern = fonts.handlers.otf.getkern(data,char,nextchar)
hskip.width = kern
end
node.insert_after(head, item, node.copy(hskip))
end
end
end
%
luatexbase.add_to_callback("hyphenate",
function(head)
insert_breakpoint(head)
lang.hyphenate(head)
end,
"insert_breakpoints")
}
\setmainfont{TeX Gyre Termes}
\setlength\parindent{0pt} % Just for demonstration!!!
\begin{document}
Test"=Versuch
% Propagate kerning across the hyphen
Test-Versuch
% Inserted negative hskip facilitates line-breaking of next word
{\hsize=10pt Test-Versuch\par}
\end{document}
由于字距只有-52429sp
( -0.8pt
) 宽,所以几乎看不见。