66

When typesetting URLs in LaTeX using the url package, they are set in a mono space font by default. While I just accepted that as a fact for a long time, I am now starting to wonder why?

In Browsers, for example, the URL in the address bar is also not monospace. It does not make the link more readable, in my opinion rather on the contrary. The only explanation I can come up with is that it sets the link apart from the remeaining text. But honestly, even that sometimes looks a bit obstrusive.

So is the reasons really just to set links apart from the text?

1
  • 3
    The answers to this question have some good design-based reasons for using monospaced fonts for URLs.
    – Mangara
    Aug 24, 2017 at 21:38

6 Answers 6

69

The default was chosen by the package author, according to the common way of setting URLs. Using a monospaced font helps distinguishing them, and this is the main reason.

However the font can be changed with \urlstyle that accepts one argument among

tt
rm
sf
same

The default is equivalent to \urlstyle{tt}; with \urlstyle{rm} and \urlstyle{sf} the font will be the roman or sans serif upright font. With \urlstyle{same} the current font will be used.

\documentclass{article}
\usepackage{url}
\begin{document}
\url{http://tex.stackexchange.com}

\urlstyle{rm}
\url{http://tex.stackexchange.com}

\urlstyle{sf}
\url{http://tex.stackexchange.com}

\urlstyle{same}
\url{http://tex.stackexchange.com}

\bfseries\urlstyle{same}
\url{http://tex.stackexchange.com}

\itshape\urlstyle{same}
\url{http://tex.stackexchange.com}

\mdseries\itshape\urlstyle{same}
\url{http://tex.stackexchange.com}

\end{document}

enter image description here

4
  • 4
    Thanks for the effort, but this question was really rather about why URLs are most of the time printed in monospace formate. This is not only the case for LaTeX, but you see it everywhere. I am wondering why. Is a serif font not better from a typographical point of view? Maybe I should have made myself clearer on this, sorry.
    – Ingo
    May 1, 2012 at 17:00
  • 1
    The question is: Where does what you call "the common way" come from, what is the rationale behind it?
    – doncherry
    May 1, 2012 at 17:51
  • 1
    @doncherry That's not really in topic here, I'm afraid. However the reason is just wanting to have the URL stick out from the context.
    – egreg
    May 1, 2012 at 17:53
  • @Ingo. For that question, you may be better asking on graphicdesign.stackexchange.com.
    – TRiG
    Jul 24, 2017 at 13:15
28

The first version of url.sty was written in 1996. While nowadays URLs are common and recognized by everyone, this wasn't the case at that time. At that time URLs were still heavily connected to computer code.

14

I'm guessing, but...

Computer code has traditionally been printed in a monospace (typewriter) font and in some sense a URL is computer code. I certainly think that a URL should be easily distinguished from surrounding text and using a font change does that (as would a change in colour, or underlining, or ...) but I think that monospace (typewriter) is now the expected means. Not all URLs as written include the http://www. preliminaries so a traditional scheme gives clues to even abbreviated URLs.

I know that not all computer code is in typewriter/monospaced as the literate programming systems (and the listings package) use different non-monospaced fonts when printing but I find code in that form much more difficult to understand than the simple (plagiarising Ford's remark on the colours of his cars) "any font you want provided it is monospaced".

2
  • 1
    I'm not sure that it is really that common. I think you'd find that ordinary publications, like newspapers and non science books, set URLs in roman. The LaTeX package default probably represents something of a frozen tradition. And it seems a rather purposeless one to me; a URL is more or less instantly recognisable. The only shadow of a justification for it seems to me to be that line breaking might sometimes cause doubt; but I can't think it happens often. Mostly I think it's the typographical equivalent of our grandfathers wearing hats: a thing done because others do it. May 1, 2012 at 18:39
  • 3
    It depends on the type of URL you are using. We have the luxury that URLs used today tend to be as easy as plain text to infer the usage of 1 vs l vs I from context. Even non-"coding-font" monospace fonts tend to distinguish well between the three due to the need to expand serifs to fill horizontal space.
    – Random832
    May 1, 2012 at 20:34
4

Monospace fonts are often used to typeset "computer text", such as what you would enter at a shell prompt or programming source code (or when you mentioned the url package). Although the browser doesn't use monospace to display the URL, I think the style of machine-readable text within human-readable text fits a URL pretty well.

3

I don't have an ancient browser at hand to check, but URLs in modern browsers are displayed in sans serif, not monospace fonts. You can tell because the "i" in the URL for this question is much narrower than the "w" next to it in the word "with".

URLs are essentially strings of symbols, not English text (or whatever). The fonts used for them lack ligatures, making it easier to interpret them as strings of symbols.

2

The real reason is usability. In many typefaces, the letters l (ell), 1 (one) and I (capital I) are virtually indistinguishable, especially in small sizes and on screens. The same applies to the letter (capital) O and the digit zero (0). In monospace (typewriter) fonts, the characters are more likely to be very distinct, so someone retyping the URI (from a book or printout) won't make the mistakes people do when the URI is printed in a sans-serif font. The trick when using a monospace font with URIs is to pick one that is sufficiently narrow (Courier is far too wide, for example).

You must log in to answer this question.

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