I saw several questions like this one that request a solution for breaking apart URLs.

  1. I wonder if it is possible to hyphenate the words in a URL as it happens in normal text (i.e., breaking apart words with the help of the hyphenation engine without adding hyphens but a special character instead), see example 1.

    • Indicating line feed: To avoid a misleading interpretation of the hyphenated URL, I would like to see a special character such as the carriage return symbol at the hyphenation position.
    • Hyphens vs. dashes: I do not want that the hyphenation engine inserts new hyphens which could be misinterpretated as being part of the URL.
  2. If the hyphenation engine breaks the URL at the position of a dash (the dash is part of the URL), the special character must be inserted whatsoever, see example 2.

  3. If the hyphenation engine breaks the URL at the position of a slash (the slash is part of the URL), the special character must be inserted whatsoever, see example 3.

The desired hyphenation should work in paragraphs, footnotes and in the bibliography.


(1) http://www.w3.org/hypertext-transport-protocol/secure/test/appli↩

(2) http://www.w3.org/hypertext-transport-↩

(3) http://www.w3.org/hypertext-transport-protocol/secure/↩

Related work:

  • The solution posted by Peter Grill introduced a new command. I want to use the existing \url command. Also, his solution breaks words at every character, while I want to rely on the decision of the hyphenation engine using correct hyphenation.
  • 2
    I am not understanding the difference between what you want and the answer in the linked question Option to break urls with carriage-return symbol? -- the section labelled UPDATE: 2011-09-20: seems to produce exactly this sort of output. Sep 8, 2012 at 3:10
  • @PeterGrill I rephrased my question which hopefully helps to show my point.
    – JJD
    Sep 8, 2012 at 10:36

1 Answer 1


enter image description here

This works for T1 and OT1 encodings, would need modification for other encodings (basically needs some invisible character to use as a fake hyphenation character)

As can be seen if no break is added (first example) no arrow, or arrows will be added if it breaks after the URL syntax / or . (second example) or at a hyphenation point such as exam-ple (third example)

As posted the arrows stick into the right margin, if you prefer them to be within the text block remove the \rlap from the \discretionary.

Also as posted this defines \brkurl the question asks for the command to be called \url just globally delete brk if that is desired.







\setbox0=\vbox{\hsize=2pt\rightskip=0pt plus 1fill
\hyphenchar\font=\csname \f@encoding-zwidthchar\endcsname
\noindent \hskip0pt \addurlspace #1\relax
\setbox4 \lastbox
\ifvoid4 \else


 some text \brkurl{http://www.example.com/this/directory/here}
 some text \brkurl{http://www.example.com/this/directory/here} some text 
 some text \brkurl{http://www.example.com/this/directory/here} some text 

  • \hyphenchar\font="17 (compound word mark) for T1-encoded fonts. But you have to revert it at the end, because setting the \hyphenchar is global.
    – egreg
    Sep 17, 2012 at 19:49
  • @egreg, oops thanks: I added encoding specific setting (just for T1 and OT1 in this example) and restored hyphenchar at end. Sep 17, 2012 at 21:05
  • @DavidCarlisle The script stops on this URL: http://opendata.paris.fr/opendata/jsp/site/Portal.jsp?document_id=93&portlet_id=106.
    – JJD
    Sep 20, 2012 at 12:09
  • 1
    it doesn't do any catcode changes and so you would have to mark up & as \& as it's an error to have & in text Sep 20, 2012 at 18:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .