如何启用不带连字符的单词内断字?

如何启用不带连字符的单词内断字?

考虑一下下面这个荒谬的例子:

\documentclass{article}

\begin{document}

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

\end{document}

这会产生一个溢出的水平盒子。我想让单词在任意位置断开,而不用连字符。

当然,我可以像这样解决:

\documentclass{article}

\begin{document}

a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a\hspace{0pt}a

\end{document}

但这实在太丑陋了。

(我只想针对特定的单词启用此功能,因为我不想破坏整个文档。)

答案1

seqsplit包做得很好:

\documentclass{article}
\usepackage{seqsplit} 

\begin{document}

\noindent \seqsplit{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}

\end{document} 

在此处输入图片描述

答案2

如果不插入连字符,xurl 包将在所有地方失效

\documentclass{article}

\usepackage{xurl}
\DeclareUrlCommand\longword{\urlstyle{rm}}


\begin{document}

\longword{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}

\end{document}

答案3

\documentclass{article}

\def\zz#1{\zzz#1\relax}
\def\zzz#1{\ifx\relax #1\else #1\penalty0 \expandafter\zzz\fi}

\begin{document}

\zz{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}

\end{document}

相关内容