# Line-breaking unformatted URLs that contain no hyphens

Minimal example:

\documentclass{article}
\begin{document}
\end{document}


Using XeLaTeX, I am trying to use a large number of unformatted URLs without using the hyperref package, and would like the URLs to break at /, as some of them don’t contain -. How could I do this?

EDIT:

I’ll try to be more specific. What I have is this:

http://link1.com/long/link/...
‹lots of random text›
‹lots of random text›
...
‹lots of random text›
...


It’s a team project, and I want the source to be able to be read, edited and easily understood by others who don’t use TeX. I have a master preamble/layout document and there I include all the other unformatted plaintext files.

• Are you allowed to use the url package, though? – Mico Mar 15 '15 at 13:20
• Sure, the only constraint is that all the links should be in a roman font (and preferably not be clickable if that’s possible). – user74027 Mar 15 '15 at 13:22
• By "roman" font, do you mean the serif font that's used as the main font of the document? – Mico Mar 15 '15 at 13:23
• Exactly! The links are entered without formatting in the source. – user74027 Mar 15 '15 at 13:25
• You've informed us that \url{...} is not acceptable because your co-authors "don't use TeX". What typesetting system do they use? Would they truly be unduly burdened by the occasional bit of TeX-style markup? – Mico Mar 15 '15 at 14:03

Are you allowed to load the url package, though? If so, encase the URL in a \url{...} macro. Issue the instruction \urlstyle{rm} to ensure that the font used for the URL string is the same as the main text font.

The following code compiles equally well under pdfLaTeX, XeLaTeX, and LuaLaTeX.

\documentclass{article}
\usepackage{url}
\urlstyle{rm} % roman font
\begin{document}
\noindent
\end{document}


Addendum: If using LuaLaTeX instead of XeLaTeX is an option for you, you could define a Lua function (to be registered with the process_input_buffer callback) that replaces all occurrences of / with \slash: The TeX macro \slash, unsurprisingly, inserts a slash symbol while allowing a line break immediately following this symbol. (The function also takes care not to allow a line break after the first of two consecutive / symbols, as such cases may occur quite frequently, viz., \http:// and \https://.)

I trust this setup meets your objective of not having to encase URL strings in \url directives and still get line breaks following slash symbols.

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{luacode}
\begin{luacode}
local function slash_to_slash ( ll )
ll = string.gsub ( ll, "/", "\\slash " )
ll = string.gsub ( ll, "\\slash \\slash ", "/\\slash " )
return ll
end