There are multiple approaches one could take.
- Insert
\allowbreak
yourself. - Pick a rare Unicode character for people to insert explicitly, replace it with
\allowbreak
yourself. - Let LaTeX replace “breakable” characters
C
withC\allowbreak
: https://tex.stackexchange.com/questions/299/how-to-get-long-texttt-sections-to-break/247335#247335 - Insert soft hyphens via
\-
(drawback: there will be hyphens at the end of the line) - Helper that breaks at hyphens and soft hyphens (and only at those, not at dots, slashes etc.), use via
\texttt{\justify{}text-with-hyphens}
: https://tex.stackexchange.com/questions/299/how-to-get-long-texttt-sections-to-break/799#799
Add or remove characters to \UrlBreaks
as necessary; currently the whole alphabet is in there, which isn’t always necessary.
\usepackage{url}
\renewcommand{\UrlBreaks}{\do\-\do\.\do\_\do\/\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X\do\Y\do\Z}
\path{this-is-long-text-that.should.break}
\UrlBreaks
should work for \url{}
, too. In case it doesn’t, there is package breakurl
, which has the option anythingbreaks
.