Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

5 Answers

up vote 22 down vote accepted

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

share|improve this answer
1  
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 '12 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 '12 at 17:51
    
@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 '12 at 17:53
add comment

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".

share|improve this answer
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. –  Paul Stanley May 1 '12 at 18:39
1  
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 '12 at 20:34
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.