# Why doesn't fontspec LetterSpace and WordSpace apply to ':' and '/' in a url?

I'd like to widen the space between each character in mono-spaced contexts (e.g. \url{} and coding example blocks). I figured fontspec's LetterSpace and WordSpace options would be the simplest way to do this, so I tried the following:

\setmonofont{Latin Modern Mono}[Scale=0.8, LetterSpace=150, WordSpace=150]


(I'm using a value of 150 here to make the issue more obvious)

This seems to work okay for {\tt http://example.com}, but \url{} gives funky results:

What's going on here? Are LetterSpace and WordSpace not the appropriate tools for the job? Is there a better approach or something else I need to set?

I'm using MacTeX 2016 and lualatex, if that's relevant.

As requested, here's a MWE:

\RequirePackage{luatex85}

\documentclass[oneside]{book}

\usepackage{fontspec}
\usepackage{hyperref}

\setmonofont{Latin Modern Mono}[Scale=0.8, LetterSpace=150, WordSpace=150]

\begin{document}

\url{http://apple.com/}

{\tt http://apple.com/}

\end{document}

• Please provide a complete example. If possible, use a font available in standard TeX distributions. If the problem cannot be reproduced except with Menlo, then please provide a link, if possible, to a suitable source. – cfr Aug 27 '16 at 22:12
• Just by way of general advice, if you're using lualatex, you should replace {\tt foo}, etc. with \texttt{foo} (or {\ttfamily foo} if you really want), {\tt foo}, {\it foo}, etc. are 20+ years deprecated. – Au101 Aug 27 '16 at 22:17
• @cfr I see the same behaviour with Latin Modern Mono, so this doesn't seem to be Menlo-specific. – splicer Aug 27 '16 at 22:51
• Not just if you are using LuaLaTeX - if you are using LaTeX at all. – cfr Aug 27 '16 at 22:51
• So better to use Latin Modern Mono in your example since almost everyone will have that. – cfr Aug 27 '16 at 22:52

The URL is typeset in maths mode with maths spacing. Forward slashes and full-stops are typeset as binary operators ('mathbin'), colons are typeset as relations ('mathrel'). The former are classified as 'Break' characters; the latter as 'BigBreak' characters. This is, of course, used to control which characters may be followed by a line break.

Hence, to change the spacing around these characters, you must change the configuration of maths mode spacing which is active when the URL is typeset. To do this, the url package provides a \Urlmuskip dimension which can be modified at will.

For example,

\documentclass[oneside]{book}
\usepackage{fontspec}
\usepackage{hyperref}
\setmonofont{Latin Modern Mono}[Scale=0.8, LetterSpace=150, WordSpace=150]
\urlstyle{tt}
\pagestyle{empty}
\Urlmuskip = 22mu plus 10mu
\begin{document}

\url{http://apple.com/}

\ttfamily{http://apple.com/}

\end{document}


produces

• "The URL is typeset in maths mode with maths spacing." That's really interesting, I never knew that, do you know why that's done? – Au101 Aug 27 '16 at 23:34
• No. I thought it was interesting, too. I only found it out answering this question. Try texdoc url. If I missed something or you figure something out, please let me know. – cfr Aug 28 '16 at 1:40
• @Au101 That is, it says that it allows context-sensitive linebreaking but I'm not really sure why that requires maths mode. I can see how it is used in terms of making different characters different kinds of maths atoms. But I'm not sure why it needed to be done that way. – cfr Aug 28 '16 at 1:43
• @cfr in inline math line breaking doesn't depend on hyphenation patterns but on \binoppenalty and \relpenalty which are break points. – Ulrike Fischer Aug 28 '16 at 9:21
• Imho it would be much more difficult with hyphenation patterns. E.g. you would need quite a lot patterns, to allow for more or less restricted breaks in urls. – Ulrike Fischer Aug 28 '16 at 13:22