如何让 LaTeX 对包含破折号的单词进行连字符?
在我正在编写的 LaTeX 文档中,由于“多学科”一词恰好出现在行尾,我收到了 overfull hbox 警告。
我可以通过将其更改为multi-discipli\-nary
来摆脱这个特定的警告,但同样的问题也会发生在其他地方,因为这个词在论文中被大量使用。
我想改用 \hyphenation{}
命令,但显然我的暂定 \hyphenation{multi-disci-pli-na-ry}
不起作用,因为它无法正确理解第一个破折号。
我需要什么咒语才能在已经包含破折号的单词中获得正确的缩进?
额外问题:我自己在哪里可以找到这个问题的答案?
In a LaTeX document I'm writing, I get an overfull hbox warning because of the word "multi-disciplinary", which happens to be rendered at the end of a line.
I can get rid of this particular warning by changing it into multi-discipli\-nary
, but the same problem will happen elsewhere, since this word is used a lot in the paper.
I'd like to use the \hyphenation{}
command instead, but obviously my tentative \hyphenation{multi-disci-pli-na-ry}
does not work, because it does not understand the first dash correctly.
What incantation do I need to get correct indentation in a word that already contains a dash?
Bonus question: Where could I have found the answer to that question myself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
问题(正如 KennyTM 指出的)是 LaTeX 不会用连字符连接带有破折号的单词。幸运的是,有一个标准包(ncctools 的一部分)可以解决这个问题,称为 extdash。这定义了新的连字符和破折号命令,这些命令不会破坏连字号,并且可以允许或防止在连字符/破折号处换行。我更喜欢将其与
shortcuts
选项一起使用,因此我可以使用\-/
而不是\Hyphdash
。这就是您想要的:\usepackage[shortcuts]{extdash}
...
multi\-/cipliated
为了防止连字符被破坏,请使用
multi\=/ciplient
(旁白:《芝加哥风格手册》 建议删除连接“multi”等词缀的连字符,除非如果没有连字符,该词会含糊不清或难以理解。)
The problem (as KennyTM noted) is that LaTeX won't hyphenate words with dashes in them. Luckily, there's a standard package (part of ncctools) that addresses that very problem, called
extdash
. This defines new hyphen and dash commands that do not disrupt hyphenation, and which can allow or prevent line breaks at the hyphen/dash. I prefer to use it with theshortcuts
option, so I can use, e.g.,\-/
rather than\Hyphdash
. Here's what you want:\usepackage[shortcuts]{extdash}
...
multi\-/disciplinary
To prevent breaking at that hyphen, use
multi\=/disciplinary
(Aside: The Chicago Manual of Style advises dropping the hyphens attaching affixes like 'multi', unless the word is ambiguous or unintelligible without it.)
来自https://texfaq.org/FAQ-nohyph:
或者,您可以使用
\newcommand
扩展为multi-discipli\-nary
的命令(使用搜索 + 全部替换来替换现有单词)。From https://texfaq.org/FAQ-nohyph:
Or you could
\newcommand
a command that expands tomulti-discipli\-nary
(use Search + Replace All to replace existing words).我使用包
hyphenat
,然后编写复合词,例如芬兰语单词Internet-yhteys(英语Internet连接)作为Internet\hyp yhteys
。看起来很傻,但似乎是我发现的最优雅的方式。I use package
hyphenat
and then write compound words like Finnish word Internet-yhteys (Eng. Internet connection) asInternet\hyp yhteys
. Looks goofy but seems to be the most elegant way I've found.正如 kennytm 所解释的,
多学科
不会用连字符连接。但是,multi-\-subject
具有与multilingual
相同的连字符机会。我承认我不知道为什么会这样。它与此处描述的行为不同(强调我的):
multi-disciplinary
will not be hyphenated, as explained by kennytm. Butmulti-\-disciplinary
has the same hyphenation opportunities thatmultidisciplinary
has.I admit that I don't know why this works. It is different from the behaviour described here (emphasis mine):
例如,您可以定义 like
,然后编写
注意 babel 俄语语言包有自己的一组破折号,它们不禁止连字符,例如
"~
(双引号+波形符)。You can e.g. define like
and then write
Note that the babel Russian language package has its own set of dashes that do not prohibit hyphenation,
"~
(double quotation+tilde) for example.我也有同样的问题。我使用 连字符 加上以下宏:
请注意,使用latex3 中的expl3 包。
它使
-
成为活动字符,向前扫描以查看其后面是否有更多破折号。如果是这样,它会保留-
,以确保--
和---
继续工作。如果不是,它将变成来自连字符的\hyp
命令,从而在单词的其余部分中启用断词。这是一个通用的解决方案,可以使所有包含显式连字符的单词正常连字符。请注意,
-
会成为不可完全扩展的宏,因此请在加载其他可能不希望-
成为宏的包后尝试包含此宏编辑:< /strong> 这是我的第二个版本,当
{
或}
后跟连字符时,第一个版本的稳健性较差。这个不是,但与第一个版本不同,此版本中的-
不是完全可扩展的。编辑2:我用于修复此问题的模块最终发展为以下内容。由于我不再使用 Latex,而且我是在 10 多年前写这篇文章的,所以我不知道下面的内容是否仍然有效。买者自负!
I had the same problem. I use hyphenat plus the following macro:
Note that this uses the expl3 package from latex3.
It makes the
-
an active character that scans forward to see if it is followed by more dashes. If so, it stays a-
, to make sure--
and---
keep working. If not, it becomes the\hyp
command from hyphenat, enabling word breaks in the rest of the word. This is a generic solution that makes all words that contain explicit hyphens hyphenate normally.Note that
-
becomes a macro that is not fully expandable, so try to include this after loading other packages that may not expect-
to be a macroEdit: This is my second version, the first version was less robust when a
{
or}
followed a hyphen. This one is not, but unlike the first version the-
in this version is not fully expandable.Edit 2: My module for fixing this ended up growing into the following. As I no longer use Latex and it was over 10 years ago that I wrote this, I have no idea if the following still works. Caveat emptor!
西里尔语的 babel 包定义了命令
"=
,应该使用它来代替破折号:所以你可以写по"=своєму
并且它会正确地连字符该单词。但是,对于英语,未定义命令
"=
。您可以按如下方式定义它,
然后
pseudo"=metric
将被正确连字符。实际上,这是这里的答案:
https://tex.stackexchange.com/questions/ 99334/用双三破折号连接单词连字符
建议使用组合
"|
。使用
"=
的一个优点是,当您同时使用西里尔语和英语时,它现在可以在多语言文档中工作,并且与仅包含西里尔字母的文档兼容。The babel package for Cyrillic defines the command
"=
which should be used instead of dash: so you can writeпо"=своєму
and it will correctly hyphenate that word.However, for English language that command
"=
is not defined.You can define it as follows
Then
pseudo"=metric
will be correctly hyphenated.Actually, this is the answer from here:
https://tex.stackexchange.com/questions/99334/hyphenation-of-words-connected-with-a-double-triple-dash
where it is propose to use the combination
"|
.An advantage of usage
"=
is that it now works in multi-language documents when you have both Cyrillic and English, and is compatible with documents having Cyrillic only.由于 Latex 认为多学科是一个带有首选连字符的单词,因此您可以指示它们是两个单独的单词,例如:
多\hspace{0pt}纪律足以解决这个问题。
Since Latex thinks multi-disciplinary is a single word with preferred hyphenation, you can indicate that these are two separate words,e.g.:
multi-\hspace{0pt}disciplinary is sufficient to resolve this.
我在这里回答了类似的问题: LaTeX 分解了太多单词
我说:
你应该在序言中的某处设置连字符惩罚:
750 的值适合我对 12 pt 字体的信纸(8.5x11 英寸)上的两列布局的需求。调整该值以满足您的需要。数字越大,连字符越少。您可能还想看看 hyphenatpackage,它提供的不仅仅是连字符惩罚
I answered something similar here: LaTeX breaking up too many words
I said:
you should set a hyphenation penalty somewhere in your preamble:
The value of 750 suited my needs for a two column layout on letter paper (8.5x11 in) with a 12 pt font. Adjust the value to suit your needs. The higher the number, the less hyphenation will occur. You may also want to have a look at the hyphenatpackage, it provides a bit more than just hyphenation penalty
为了避免在已经连字符的单词中出现连字符,我将不间断空格
~
与后向空格\!
结合使用。例如,文本中使用的命令,抑制单词 3-D 中的连字符。可能不是最好的解决方案,但它对我有用!
To avoid hyphenation in already hyphenated word I used non-breaking space
~
in combination with backward space\!
. For example, commandused in the text, suppress hyphenation in word 3-D. Probably not the best solution, but it worked for me!