我有同样的问题。我用连字符加上以下宏:
\RequirePackage{hyphenat}
\RequirePackage{expl3}
% The following defs make sure words that contain an explicit `-` (hyphen) are still hyphenated the normal way, and double- and triple hyphens keep working the way they should. Just don't use a `-` as the last token of your document. Also note that `-` is now a macro that is not fully expandable
\ExplSyntaxOn
% latex2e doesn't like commands starting with 'end', apparently expl3 doesn't have any problems with it
\cs_new:Npn \hyphenfix_emdash:c {---}
\cs_new:Npn \hyphenfix_endash:c {--}
\cs_new:Npn \hyphenfix_discardnext:NN #1#2{#1}
\catcode`\-=\active
\cs_new_protected:Npn -{
\futurelet\hyphenfix_nexttok\hyphenfix_i:w
}
\cs_new:Npn \hyphenfix_i:w {
\cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
%discard the next `-` token
\hyphenfix_discardnext:NN{\futurelet\hyphenfix_nexttok\hyphenfix_ii:w}
}{
% from package hyphenat
\hyp
}
}
\cs_new:Npn \hyphenfix_ii:w {
\cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
\hyphenfix_discardnext:NN{\hyphenfix_emdash:c}
}{
\hyphenfix_endash:c
}
}
\ExplSyntaxOff
请注意,这使用了Latex3的expl3软件包。
它使-
活动字符向前扫描以查看其后是否有更多破折号。如果是这样,它将保持为-
,以确保--
并---
继续工作。如果没有,它将成为\hyp
连字符命令,从而在其余单词中启用分词。这是一种通用解决方案,可以使所有包含显式连字符的单词正常连字符。
请注意,它-
变成了不能完全扩展的宏,因此请在加载其他可能不是-
宏的程序包后尝试将其包括在内
编辑:这是我的第二个版本,第一个版本在连字符{
或}
后接连字符时不那么可靠。这个不是,但是与第一个版本不同-
,该版本不能完全扩展。