The chapter 14 "How TEX Breaks Paragraphs into Lines" in TeXbook explains the hyphenation is just TeX inserts \discretionary{\char\hyphenchar\font}{}{}
at every allowed word break when \hyphenchar
is a number from 0-255, so set it to -1
disables hyphenation, and now we want to "manually" insert \discretionary{}{}{}
between every characters. This seems scary, but it is easy with plain TeX macros, not even the token register is need.
\def\ub@{\discretionary{}{}{}}
\def\appe@#1#2\eol{\def\g{#2}%
\ifx\g\empty #1\else\ub@#1\appe@#2\eol\fi}
\def\protol@#1://#2\eol{#1:\kern-1.5pt/\kern-2.5pt/\appe@#2\eol}
\def\url#1{\begingroup\count0=\the\hyphenchar\font%
\hyphenchar\font=-1%
\protol@#1\eol
\hyphenchar\font=\count0\endgroup}
The work horse is the \appe@
macro, which takes the first character in the string as #1
and the rest of the string until token \eol
as #2
, and loops to insert \ub@
between them until #2
becomes empty. Note the use of %
to prevent
extra whitespace occurs in the result. The \protol@
macro is just something I use to prevent breaking at the protocol part of the url (https://
for example), and make the ://
a bit more compact.
And \begingroup
does not reset \hyphenchar
so remember to set it back.
[1] American Cornhole League. ``American Cornhole League Rules and
Regulations,'' November 13, 2019. Available:
\url{https://mysqlvm.blob.core.windows.net/acl-docs/ACL-Rules-Regs-2019-2020.pdf}.
[Accessed: April 17, 2024]\par
[2] American Cornhole Organization. ``Cornhole Rules,'' [online document].
Available:
\url{https://americancornhole.com/downloads/ACO-Season16/ACO-Cornhole-Rules-Sheet1.pdf}.
[Accessed: April 17, 2024]\par
If the long url spans the whole line, it is a good idea to
add extra glue around /
so TeX can stretch the line a little bit
to make it fit. Note that the glue itself would permit TeX to line break at it.
\def\appe@#1#2\eol{\def\g{#2}%
\ifx\g\empty #1\else\ifx#1/\hskip-.5pt plus 1pt/\hskip-1pt plus 1pt%
\else\discretionary{}{#1}{#1}\fi\appe@#2\eol\fi}
url
package. And welcome to TeX.SX!!url
withminiltx
:-)