我正在用英语撰写文档,除非我将单词包含在命令中,否则不会对任何单词进行连字符处理\hyphenation{*}
。例如,除非我将单词“government”包含在序言中,否则单词“government”会突出到页边距中\hyphenation{gov-ern-ment}
。
我不认为这会成为\hyphenpenalty
or\lefthyphenmin
和 的问题\righthyphenmin
,因为一旦命令中包含单词,\hyphenation{*}
一切都会正常工作(因为我尝试摆弄这些参数,但没有解决任何问题)。我还尝试过加入\usepackage[english]{babel}
序言,但这并没有解决任何问题。我刚刚重新安装了 MiKTeX 并更新了所有软件包,所以我认为这不会成为问题。
编辑 4:这似乎是 TeXStudio 的问题,因为我的最小示例在命令行中使用 可以正常工作pdflatex hyphenation-example
。
编辑:我正在使用带有子文件的文档类,尽管我过去book
曾遇到过与文档类类似的问题。article
这是我的完整序言。我在定义任何自定义命令之前就遇到了这个问题,因此包部分可能是最相关的。
% LATEX PARAMETERS_________________________________________________________________________
%default values are 50
\hyphenpenalty = 50 % lower means more hyphenation
\tolerance = 50 % lower means less stretching between words, more likelihood of jagged edge, and more hyphenation
\lefthyphenmin = 2
\righthyphenmin = 2
% PACKAGES_________________________________________________________________________________
% general functionality
\usepackage{amsmath} % matrices
\usepackage{amssymb} % fancy maths letters
\usepackage{breqn} % equations over several lines
\usepackage{graphicx} % import figures
\usepackage{caption} % caption figures
\usepackage{subcaption} % subfigures
\captionsetup{font={small},labelfont={bf},labelsep=space}
\usepackage{xparse} % needed for shortenthis command and commands with an if-then structure
\usepackage[pagestyles,explicit,raggedright]{titlesec} % change title style
\usepackage{needspace} % insert pagebreak if not enough space
\usepackage[nottoc,notlot,notlof]{tocbibind} % inlcude bibliography in toc
\usepackage{subfiles}
% fonts
\usepackage[bitstream-charter]{mathdesign} % set font to BT Charter
\usepackage[T1]{fontenc} % font encoding
\newcommand{\sansfont}{\fontfamily{qag}\selectfont} % command to set font to TeX Gyre Heros
% ornaments
\usepackage{adforn} % fleurons
\newcommand{\ico}{\includegraphics[height=0.8 em]{Icosahedron}}
\newcommand{\flower}{\begin{center}\Large\adfflowerright\end{center}}
% draft formatting
\usepackage{setspace} % line spacing
\usepackage{lineno} % line numbering
% page formatting
\usepackage[left = 35mm, right = 25mm, top = 30mm, bottom = 30 mm, headsep = 12mm, footskip = 15mm]{geometry} % page margins
% making diagrams
\usepackage{tikz} % make diagrams in LaTeX
\usetikzlibrary{arrows.meta} % set arrow appearance
\tikzset{>={Latex[width=3mm,length=3mm]}}
\pgfdeclarelayer{bg} % for loops
\pgfsetlayers{bg,main}
% references
\usepackage{hyperref}
\newcommand{\doi}[1]{\textsc{doi}: \href{http://dx.doi.org/#1}{\nolinkurl{#1}}} % allows underscores in dois
% colors
\usepackage{color}
\definecolor{vp}{HTML}{440154} % viridis purple
\definecolor{vb}{HTML}{33638D} % viridis blue
\definecolor{vg}{HTML}{3CBB75} % viridis green
\definecolor{vy}{HTML}{FDE725} % viridis yellow
\definecolor{IBMb}{HTML}{648FFF} % IBM blue
\definecolor{IBMr}{HTML}{DC267F} % IBM red
\definecolor{IBMy}{HTML}{FFB000} % IBM yellow
\definecolor{IBMp}{HTML}{785EF0} % IBM purple
% COMMANDS_________________________________________________________________________________
% define the 'shortenthis' command, which I use in the definition abbreviations. sourced from Manuel on StackExchange, in an answer posted on 2014-03-01
\ExplSyntaxOn
\NewDocumentCommand\shortenthis{ m }
{\shorten_this:n { #1 }}
\seq_new:N \l_shorten_seq
\cs_new_protected:Npn \shorten_this:n #1
{\seq_set_split:Nnn \l_shorten_seq { ~ } { #1 }
\seq_map_inline:Nn \l_shorten_seq
{\tl_head:n { ##1 } }}
\ExplSyntaxOff
% define documentstyle option 'draft'. in draft documents certain commands will behave differently
\newif\if@myfilerough
\DeclareOption{rough}{\@myfileroughtrue}
\ProcessOptions\relax
\if@myfilerough
% in a rough rough text shows up and is noted in the margin
\newcommand{\rough}[1]{$<$#1$>$\marginpar{\color{magenta}\textbf{rough}}}
\newcommand{\citerough}[1]{[[#1]]\marginpar{\color{blue}\textbf{cite}}}
% in a rough definitions are noted in the margin, with an optional argument for an abbreviation
\NewDocumentCommand{\term}{o m}{%
\IfNoValueTF{#1}%
{\emph{#2}\marginpar{\textbf{``\shortenthis{#2}''}}}%
{\emph{#2} (#1)\marginpar{\textbf{``#1''}}}%
}
% roughs have 1.5x spacing and line numbers
\onehalfspacing
\linenumbers
\else
% in a non-rough rough text is not shown
\newcommand{\rough}[1]{}
\newcommand{\citerough}[1]{}
% in a non-rough definitions are emphasised but are not noted in the margin
\NewDocumentCommand{\term}{o m}{%
{\emph{#2}}%
}
\fi
%for use at end of chapters to make the next page occur on the left
\newcommand*\cleartoleftpage{%
\clearpage
\ifodd\value{page}\hbox{}\newpage\fi
}
% FORMATTING________________________________________________________________________________
\titleformat{\chapter}[hang]{\raggedright\sansfont\singlespacing\Huge}{\thechapter\hspace{20pt}\ico\hspace{20pt}}{0pt}{\Huge #1}[]%
\titleformat{\section}[hang]{\needspace{0.5in}\sansfont\singlespacing}{}{0pt}{\LARGE #1 \Large \hfill \ico~\thesection}[]%
\titleformat{\subsection}[hang]{\needspace{0.5in}\sansfont\singlespacing}{}{0pt}{\Large #1 \large \hfill \ico~\thesubsection}[]%
\titleformat{\subsubsection}[hang]{\needspace{0.5in}\sansfont\singlespacing\normalsize}{}{0pt}{\large #1 \hfill}[]%
% Redefine headers
\newpagestyle{main}{%
\sethead[\sansfont \thepage \hspace{.7cm} \textsl{\chaptertitle}][][]
{}{}{\sansfont \textsl{\thesection~\ {\ico} \ \sectiontitle} \hspace{.7cm} \thepage}
\setfoot{}{}{}
} % Define page style main
\pagestyle{main} % Use page style main
\renewpagestyle{plain}{%
\setfoot{}{}{}
} % Define page style plain (first pages of chapters etc)
\title{thesis}
\author{ben}
\endinput
编辑2:
这是一个最小的例子,其中文本宽度设置得很低,以表明连字不起作用:
\documentclass[draft]{book}
\textwidth=4cm
\usepackage[english,showlanguages]{babel}
\begin{document}
A pandemic is an event in which a disease spreads over a very large area, often crossing national borders. Pandemics often infect large numbers of people, can cause many deaths , and have negative effects on trade and the world economy. It is due to the large scale of the negative effects of pandemics that pandemic preparedness is seen as an important public health activity, despite the low frequency of pandemics in comparison to other disease outbreaks. Factors implicated in pandemic risk include travel, high population density, and changing agricultural practices.
\end{document}
这是日志文件:
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (MiKTeX 21.6) (preloaded format=pdflatex 2021.7.15) 15 JUL 2021 16:17
entering extended mode
**./hyphenation-example.tex
(hyphenation-example.tex
LaTeX2e <2021-06-01> patch level 1
L3 programming layer <2021-07-12>
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/latex/base/b
ook.cls
Document Class: book 2021/02/12 v1.4n Standard LaTeX document class
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/latex/base/b
k10.clo
File: bk10.clo 2021/02/12 v1.4n Standard LaTeX file (size option)
)
\c@part=\count182
\c@chapter=\count183
\c@section=\count184
\c@subsection=\count185
\c@subsubsection=\count186
\c@paragraph=\count187
\c@subparagraph=\count188
\c@figure=\count189
\c@table=\count190
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen138
)
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/generic/babe
l/babel.sty
Package: babel 2021/06/28 3.61 The Babel package
<*languages>
</languages>
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/generic/babe
l/babel.def
File: babel.def 2021/06/28 3.61 Babel common definitions
\babel@savecnt=\count191
\U@D=\dimen139
\l@unhyphenated=\language1
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/generic/babe
l/txtbabel.def)
\bbl@readstream=\read2
)
\bbl@dirlevel=\count192
*************************************
* Local config file bblopts.cfg used
*
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/latex/arabi/
bblopts.cfg
File: bblopts.cfg 2005/09/08 v0.1 add Arabic and Farsi to "declared" options of
babel
)
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/latex/babel-
english/english.ldf
Language: english 2017/06/06 v3.3r English support from the babel system
))
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/latex/l3back
end/l3backend-pdftex.def
File: l3backend-pdftex.def 2021-07-12 L3 backend support: PDF output (pdfTeX)
\l__color_backend_stack_int=\count193
\l__pdf_internal_box=\box50
) (hyphenation-example.aux)
\openout1 = `hyphenation-example.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 5.
LaTeX Font Info: ... okay on input line 5.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 5.
LaTeX Font Info: ... okay on input line 5.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 5.
LaTeX Font Info: ... okay on input line 5.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 5.
LaTeX Font Info: ... okay on input line 5.
LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 5.
LaTeX Font Info: ... okay on input line 5.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 5.
LaTeX Font Info: ... okay on input line 5.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 5.
LaTeX Font Info: ... okay on input line 5.
Overfull \hbox (3.46695pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 over a very large area, often|
[]
Overfull \hbox (6.6892pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 Pandemics often infect large|
[]
Overfull \hbox (9.60585pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 numbers of people, can cause|
[]
Overfull \hbox (24.52258pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 many deaths , and have negative|
[]
Overfull \hbox (11.85583pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 effects on trade and the world|
[]
Overfull \hbox (3.55031pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 seen as an important public|
[]
Overfull \hbox (3.21696pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 low frequency of pandemics|
[]
Overfull \hbox (14.74475pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 in comparison to other disease|
[]
Overfull \hbox (15.2911pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 outbreaks. Factors implicated|
[]
Overfull \hbox (19.63367pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 in pandemic risk include travel,|
[]
Overfull \hbox (8.13373pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 high population density, and|
[]
Overfull \hbox (21.05035pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 changing agricultural practices. |
[]
[1{/Users/user/Library/Application Support/MiKTeX/texmfs/data/pdftex/config/pdf
tex.map}
] (hyphenation-example.aux) )
Here is how much of TeX's memory you used:
1207 strings out of 480807
19477 string characters out of 2898544
325395 words of memory out of 3000000
18943 multiletter control sequences out of 15000+600000
403783 words of font info for 28 fonts, out of 8000000 for 9000
0 hyphenation exceptions out of 8191
40i,5n,52p,619b,149s stack positions out of 5000i,500n,10000p,200000b,80000s
</Users/user/Library/Application Support/MiKTeX/te
xmfs/install/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on hyphenation-example.pdf (1 page, 18944 bytes).
PDF statistics:
11 PDF objects out of 1000 (max. 8388607)
0 named destinations out of 1000 (max. 500000)
1 words of extra memory for PDF output out of 10000 (max. 10000000)
添加\hyphenation{*}
命令意味着可以进行连字。
\documentclass{book}
\textwidth=4cm
\usepackage[english,showlanguages]{babel}
\hyphenation{of-ten}
\begin{document}
A pandemic is an event in which a disease spreads over a very large area, often crossing national borders. Pandemics often infect large numbers of people, can cause many deaths , and have negative effects on trade and the world economy. It is due to the large scale of the negative effects of pandemics that pandemic preparedness is seen as an important public health activity, despite the low frequency of pandemics in comparison to other disease outbreaks. Factors implicated in pandemic risk include travel, high population density, and changing agricultural practices.
\end{document}
答案1
这microtype
也有助于减少连字符,并更好地分配单词之间的空间,但请注意,shrink
和stretch
选项的滥用可能比连字符和过满的 \hbox 更糟糕。
\documentclass[draft]{book}
\usepackage[margin=0.5cm,paperwidth=5cm,paperheight=12
cm]{geometry}
\usepackage[english,showlanguages]{babel}
\usepackage[protrusion=true, expansion=true, shrink=55, stretch=55,
tracking=true, kerning=true, spacing=true,
final]{microtype}
\hyphenation{he-alth}
\newcommand\zz{%
A pandemic is an event in which a disease spreads over a very large
area, often crossing national borders. Pandemics often infect large
numbers of people, can cause many deaths, and have negative effects
on trade and the world economy. It is due to the large scale of the
negative effects of pandemics that pandemic preparedness is seen as an
important public health activity, despite the low frequency of
pandemics in comparison to other disease outbreaks. Factors implicated
in pandemic risk include travel, high population density, and changing
agricultural practices.}
\begin{document}
\section*{Microtype}
\zz
\clearpage
\microtypesetup{expansion=false}
\microtypesetup{protrusion=false}
\microtypesetup{kerning=false}
\microtypesetup{tracking=false}
\section*{Emergency}
\zz\emergencystretch2em
\end{document}
答案2
TeX 可以将文本设置为如此窄的列,但您必须进行一些调整,特别是允许更多的空白拉伸,因为即使使用连字符,在标准空白限制下也没有足够的断点。以下是三种可能性。
\documentclass{book}
\textwidth=4cm
\oddsidemargin=.1cm
\evensidemargin=.1cm
\usepackage[english,showlanguages]{babel}
\hyphenation{of-ten}
\usepackage{ragged2e}
\pdfpagewidth=8cm
\newcommand\zz{%
A pandemic is an event in which a disease spreads over a very large
area, often crossing national borders. Pandemics often infect large
numbers of people, can cause many deaths , and have negative effects
on trade and the world economy. It is due to the large scale of the
negative effects of pandemics that pandemic preparedness is seen as an
important public health activity, despite the low frequency of
pandemics in comparison to other disease outbreaks. Factors implicated
in pandemic risk include travel, high population density, and changing
agricultural practices.}
\begin{document}
\section*{Sloppy}
\begin{sloppypar}
\zz
\end{sloppypar}
\clearpage
\section*{Emergencystretch}
{\emergencystretch=2em \zz\par}
\clearpage
\section*{Ragged2e}
{\RaggedRight\zz\par}
\end{document}
答案3
由于\tolerance = 1
您要求 TeX 只生成超漂亮的行 — 比它通常能生成的文本更好的行。因此它会一次又一次地失败,而且当它失败时,您不会得到很好的输出。如果您添加草稿选项,您\documentclass[draft]{book}
将看到它失败了哪些行。这是我得到的:
(顺便说一下,请注意那里确实有一些连字符。)如果您只是删除您的设置\tolerance
,\hyphenpenalty
您将获得更好的结果,会有更多 OK 线,但仍然有几条失败的线,这些非常窄的线:
一开始不错,但后来就太难了。你确实会看到更多带有你定义的例外模式的连字符,因为它们添加了一些 TeXs 算法找不到的连字符点。例如,它只连字符大流行并且不连字符旅行。
因此,也许这种解释对您开始遇到的问题没有任何帮助,因为当尝试修复该问题时,无论是什么问题,您添加的设置都无法正常工作。
答案4
最终,这是因为 TeXStudio 使用的是 MiKTeX 而不是 TeX Live。MiKTeX 没有正确安装连字词典。我通过卸载 MiKTeX 并重新安装 TeX Live 解决了这个问题,之后 TeXStudio 自动切换到使用 TeX Live 并成功构建了具有正确连字的文档。