我对 Latex 中的自动换行功能有疑问。现在我写了一些文本,其格式如下:
Lorem Ipsum is simply dummy text
of the printing and typesetting
industry. Lorem Ipsum has been
the industry’s standard dummy
text ever since the 1500s, when
an …
但我想要这样的东西:
Lorem Ipsum is simply dummy text
of the printing and typesetting i
ndustry. Lorem Ipsum has been the
industry’s standard dummy text ev
er since the 1500s, when an …
因此,每到一行的末尾,只需将单词的第一个字符保留到末尾,然后在新行中继续其余字符。也就是说,只是继续文本流,而不将单词连在一起。
这种格式在乳胶中可行吗?
答案1
使用标准连字是一种可能性。为了“随处”启用连字,应准备一组新模式。请参阅下文了解不同的方法;在下一个代码中,将设置\hyphenchar
为不可见的;必须手动恢复设置,因为的设置\hyphenchar
本质上是全局的。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\newenvironment{zerohyphen}
{\global\chardef\savedhyphenchar=\hyphenchar\font % save the current hyphenchar
\lefthyphenmin=1 \righthyphenmin=1 % no limits on hyphenation
\hyphenchar\font=23 }
{\par\hyphenchar\font=\savedhyphenchar}% eject the paragraph and restore
\begin{document}
\hyphenpenalty=-100 % just to make hyphenation more desirable
\begin{minipage}{3.5cm}
\begin{zerohyphen}
Lorem Ipsum is simply dummy text
of the printing and typesetting
industry. Lorem Ipsum has been
the industry’s standard dummy
text ever since the 1500s, when
an
\end{zerohyphen}
\end{minipage}
\end{document}
这是一种不同的方法(但请注意,与 UTF-8 的配合会很复杂);文本以空格分隔,每个单词按字母逐个打印,任意两个字母之间的惩罚为零。
\documentclass{article}
\usepackage{xparse,environ}
\ExplSyntaxOn
\NewEnviron{zerohyphen}
{
\par
\franx_zerohyphen:V \BODY
\par
}
\seq_new:N \l_franx_body_seq
\cs_new_protected:Npn \franx_zerohyphen:n #1
{
\seq_set_split:Nnn \l_franx_body_seq { ~ } { #1 }
\seq_map_inline:Nn \l_franx_body_seq { \franx_printword:n { ##1 } }
}
\cs_generate_variant:Nn \franx_zerohyphen:n { V}
\cs_new_protected:Npn \franx_printword:n #1
{
\tl_map_inline:nn { #1 } { ##1 \penalty0 \scan_stop: }
\c_space_tl
}
\ExplSyntaxOff
\begin{document}
\begin{minipage}{3.5cm}
\begin{zerohyphen}
Lorem Ipsum is simply dummy text
of the printing and typesetting
industry. Lorem Ipsum has been
the industry's standard dummy
text ever since the 1500s, when
an
\end{zerohyphen}
\end{minipage}
\end{document}