考虑一下下面这个荒谬的例子:
\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
答案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}