允许在没有空格或连字符的位置休息

允许在没有空格或连字符的位置休息

我有两个字母:A 和 B。在大多数情况下,我希望它们一起出现,没有空格,例如(“AB”),但是,如果 TeX 认为需要换行符或将它们分成两页,这是允许的。这可能显示为:

AB

或者:

A

我可以在两个字母(或长串字母)之间放置什么,以便可以将它们拆分到多个页面?

  • 这应该不留任何空间。
  • 这不应留下连字符。
  • 这应该使用与字母中确实有空格时相同的拆分规则。

答案1

如果您在字母之间引入一个小的 0pt 跳过,TeX 将不会将它们视为一个单词,并允许它们按您的意愿断开。您可以创建宏或在需要时使用它们。(为了方便和比较,我使用了来自 Schweinebacke 的相同示例)。

\documentclass{article}

\begin{document}
A\hskip0ptB vs. some text, some text, some text, some text, some text, some text, some
text A\hskip0ptB and some text.

A\hskip0ptB vs. some text, some text, some text, some text, some text, some text, some
text A\hskip0ptB and some text.
\end{document}

答案2

我只是用\discretionary它来定义一个宏来增加舒适度。

\documentclass{article}
\usepackage{xspace}% see http://ctan.org/pkg/xspace
\usepackage[textwidth=2.78in,textheight=0.9in]{geometry}% for demonstration only
\usepackage{showframe}% for demonstration only

\newcommand*{\AB}{\discretionary{A}{B}{AB}\xspace}

\begin{document}
\AB vs. some text, some text, some text, some text, some text, some text, some
text \AB and some text.

\AB vs. some text, some text, some text, some text, some text, some text, some
text \AB and some text.
\end{document}

我用过包展示架在我的示例中演示文本区域的宽度和高度(Werner 的建议)。我使用非常小的宽度和高度来演示换行和分页。

以下是第 1 页和第 2 页相关区域的快照: 第 1 页和第 2 页相关区域的快照

如果需要,你可以定义一个更通用的命令:

\documentclass{article}
\usepackage[textwidth=2.78in,textheight=0.9in]{geometry}% for demonstration only
\usepackage{showframe}% for demonstration only

\newcommand*{\breakchars}[2]{\discretionary{#1}{#2}{#1#2}}

\begin{document}
\breakchars AB vs. some text, some text, some text, some text, some text, some
text, some text \breakchars AB and some text.

\breakchars AB vs. some text, some text, some text, some text, some text, some
text, some text \breakchars AB and some text.

\breakchars VA vs. some text, some text, some text, some text, some text, some
text, some text \breakchars VA and some text.

\end{document}

在这种情况下,您不需要参数括号,因为没有第一个和第二个非空格字符(字母或其他)将用作第一个和第二个参数。

这个例子VA是为了表明,字距调整仍然适用于这个建议。

答案3

\documentclass[ngerman,english]{article}
\usepackage{babel}
\useshorthands{"}
\addto\extrasenglish{\languageshorthands{ngerman}}
\begin{document}

\begin{minipage}{1cm}% only for demonstration
foo bar baz A""B
and some other words
A""B and the same
\end{minipage}

\end{document}

在此处输入图片描述

相关内容