如何处理过满的水平盒子的通用解决方案与其他解决方案

如何处理过满的水平盒子的通用解决方案与其他解决方案

我知道乳胶有时允许过满的水平盒子,作为超出拉伸设置的替代方案,或作为右侧参差不齐的替代方案。

但是,在我的特定情况下,LaTeX 有时会允许溢出,这实际上是不可接受的。我在下面提供了一个最小的重现示例。

需要说明的是,我并不是在寻找针对这种情况的特定解决方案。我知道我可以使用\sloppy\raggedright或者使用 emergencystretch 和 tolerance 设置的某种组合。我正在寻找一个通用解决方案来告诉 latex 溢出时间超过X不可接受的时间任何状况之下。如果溢出大于,我希望 LaTeX 自动找到更好的解决方案X。对我来说,作为如此大的溢出的替代方案,不规则的右侧是完全可以接受的。

在 LaTeX 中需要调整哪些设置来避免这些问题?

复现示例:

\documentclass{article}
\usepackage{listings}

\newcommand{\lstinlinestyle}{\ttfamily}
\newcommand\codeinline{\lstinline[basicstyle={\lstinlinestyle}]}

\begin{document}
Lorem Ipsum is simply dummy text of the printing and typesetting \codeinline{Textthatcannotbehyphenated}.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
\end{document}

在此处输入图片描述

我希望输出看起来像这样,无需人工干预:

在此处输入图片描述

编辑:我是否需要关心坏盒子?没有回答我的问题,因为它只提到了\sloppy\emergencystretch作为问题的解决方案。这并不总是能解决问题,因为有时创建良好换行所需的拉伸量会导致段落看起来很奇怪。在这种情况下,参差不齐的右侧看起来会好得多。

编辑2:在测试解决方案时,我注意到我使用了它\texttt,并且它也溢出了。这是一个重现示例:

\documentclass{article}

\begin{document}
Lorem Ipsum is simply dummy text of the printing and typesetting \texttt{Textthatcannotbehyphenated}.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.  
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.  
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
\end{document}

因此,我仍在寻找比当前答案中提供的解决方案更通用的解决方案。

编辑3:这个问题与我想做的事情非常相关:换行而不是让水平盒子溢出?但从未得到满意的答复。

编辑 5:尚未找到令人满意的解决方案。如果您有任何想法,请告诉我!我正在考虑制作一个 LuaLaTeX 包,当段落具有特定的不良分数时,使用 raggedright 作为后备。

答案1

关于一般情况的一些注释

我是否需要关心坏盒子?

但对于这种情况,您可以将代码命令定义为具有不规则空间,该空间总计为 0pt,因此如果没有换行则不会产生任何影响。

在此处输入图片描述

\documentclass{article}
\usepackage{listings}

\newcommand{\lstinlinestyle}{\ttfamily}
\newcommand\codeinline{%
\hspace{0pt plus 3cm}\penalty100\hspace{0pt plus -3cm}%
\lstinline[basicstyle={\lstinlinestyle}]}

\begin{document}
Lorem Ipsum is simply dummy text of the printing and typesetting
\codeinline{Textthatcannotbehyphenated}.  Lorem Ipsum has been the
industry's standard dummy text ever since the 1500s, when an unknown
printer took a galley of type and scrambled 
\codeinline{Textthatcannotbehyphenated}
it to make a type specimen
book.  It has survived not only five centuries, but also the leap into
electronic typesetting, remaining essentially unchanged.  It was
popularised in the 1960s with the release of Letraset sheets
containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem
Ipsum.
\end{document}

答案2

如果您不介意使用 LuaLaTeX,您可以使用我的linebreaker包。它会挂接到换行回调中,检测溢出段落,并使用增加的tolerance和的值重新排版它们emergencystretch,直到找到好的解决方案或达到允许的最大循环次数。

您的样本已linebraker加载:

\documentclass{article}
\usepackage{listings}
\usepackage{linebreaker}

\newcommand{\lstinlinestyle}{\ttfamily}
\newcommand\codeinline{\lstinline[basicstyle={\lstinlinestyle}]}

\begin{document}
Lorem Ipsum is simply dummy text of the printing and typesetting \codeinline{Textthatcannotbehyphenated}.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
\end{document}

结果如下:

在此处输入图片描述

相关内容