![texttt 没有在现有连字符处换行](https://linux22.com/image/401955/texttt%20%E6%B2%A1%E6%9C%89%E5%9C%A8%E7%8E%B0%E6%9C%89%E8%BF%9E%E5%AD%97%E7%AC%A6%E5%A4%84%E6%8D%A2%E8%A1%8C.png)
我有较长的短语,它们之间用连字符分隔,我想用打字机字体排版。我希望 Latex 能断行,避免它们溢出:
\documentclass{article}
\begin{document}
Normal font breaks the line:
a-very-long-text-in-typewriter-font-separated-by-hyphens-that-should-break-the-line.
But typewriter font does not:
\texttt{a-very-long-text-in-typewriter-font-separated-by-hyphens-that-should-break-the-line.}
\end{document}
需要明确的是,我不希望乳胶添加更多的连字符,我只希望它在现有的连字符处断线。
答案1
\documentclass{article}
\begin{document}
\raggedright
Normal font breaks the line:
a-very-long-text-in-typewriter-font-separated-by-hyphens-that-should-break-the-line.
But typewriter font does not:
\texttt{%
\hyphenchar\font=`\- % enable hyphenation
\hyphenpenalty=10000 % disable it again
\exhyphenpenalty=-50 % enable (encourage) it at explicit hyphens
a-very-long-text-in-typewriter-font-separated-by-hyphens-that-should-break-the-line.}
\end{document}