当换行符落在故意连字符上时,如何设置自动使用双斜连字符?

当换行符落在故意连字符上时,如何设置自动使用双斜连字符?

假设你有一个复合词,其中的元素通常用连字符连接,而不是挤在一起,比如事实核查是和侦探不是,或者是那些花哨的带连字符的姓氏之一,如 Lloyd-Beeblebrox。在老式排版中,如果在连字符处发生换行,则行末的连字符将被替换为看起来像短的、略微倾斜的等号的字符,在 Unicode(U+2E17)中称为双斜连字符。那么,假设我想获得所有高调并将其用于文档或文档的一部分?有没有办法直接告诉 LaTeX 执行此操作?或者有一个可以帮我完成此操作的包?或者是否有我可以通过调用使用的 OpenType 功能(如果字体中提供)fontspec?对于上下文,我正在使用 LuaLaTeX,带有memoir类、fontspec包和 Linux Libertine O 字体(其中包括 U+2E17 字符),但没有包libertine

答案1

LuaTeX 有很多用于连字符的参数。我们这里需要的是\preexhyphencharpre因为双斜连字符应该插入在换行符之前,并且ex对于显式连字符,因为这应该只添加显式连字符点[也就是在没有换行时也出现的连字符])

因此我们得到

\documentclass{article}

% First some font setup
\DeclareFontFamily{TU}{libertine}{}
\DeclareFontShape{TU}{libertine}{m}{n}
  {<-> \UnicodeFontName{Linux Libertine O}{script=latn;}}{}

% The important command:
\preexhyphenchar"2E17

\begin{document}
% For demonstration purposes, we kindly ask TeX to insert lots of hyphens: (Never do this in a normal document!)
\pretolerance-1
\hyphenpenalty-1000
\exhyphenpenalty-1000

% Done. Now just add some text:
A detective was hired to do a fact-check.
A detective was hired to do a fact-check.
A detective was hired to do a fact-check.
A particularly skillful and talented detective was hired to do a fact-check.
\showoutput
\end{document}

在此处输入图片描述

如果您尝试使用 fontspec 执行此操作,事情会变得有点复杂,因为 fontspec 习惯于尽可能频繁地重置 LuaTeX 的连字符参数。我不认为这样做有什么真正的原因,因此您可以通过隐藏 fontspec 中的原始参数来解决这个问题:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}

% The important commands:
\let\realpreexhyphenchar\preexhyphenchar
\realpreexhyphenchar"2E17
\newcount\preexhyphenchar % Hide the primitive from fontspec
\begin{document}
% For demonstration purposes, we kindly ask TeX to insert lots of hyphens: (Never do this in a normal document!)
\pretolerance-1
\hyphenpenalty-1000
\exhyphenpenalty-1000

% Done. Now just add some text:
A \oldstylenums{detective} was hired to do a fact-check.
A detective was hired to do a fact-check.
A detective was hired to do a fact-check.
A particularly skillful and talented detective was hired to do a fact-check.
\showoutput
\end{document}

相关内容