Urls In Latex Bibliography Format

How to cite a URL in BibTeX
Mark Senn
February 11, 2015

How to cite a URL in BibTeX

To cite a URL in BibTeX, put

\usepackage{url} % By default the URLs are put in typewriter type in the body and the % bibliography of the document when using the \url command. If you are % using many long URLs you may want to uncommennt the next line so they % are typeset a little smaller. % \renewcommand{\UrlFont}{\small\tt} between your and command. You may want to uncomment the command, see the the instructions above.

Use, for example,

\cite{Senn:2009} to cite the URL in the text.

Your .bib file should contain, for example,

@manual{Senn:2009, title = "Using {\LaTeX} for Your Thesis", author = "Mark Senn", url = "http://engineering.purdue.edu/~mark/puthesis", year = "2009 (accessed February 3, 2014)" }

Or, if your bibliographystyle does not support the url field (you'll get errors when BiBTeX runs or the output will be wrong), use

@manual{Senn:2009, title = "Using {\LaTeX} for Your Thesis", author = "Mark Senn", note = "\url{http://engineering.purdue.edu/~mark/puthesis}", year = "2009 (accessed February 3, 2014)" }

Email me (see link on second line of this document) if you have questions or problems.

References:

Thanks to Derrick Kearney for sending correct url.sty link.

Revised: February 11, 2015
Created: July 6, 2006


14. How do you get nicely formatted URLs in the bibliography?


Answer

Use the url package by Donald Arseneau.


Example usage

In the preamble:

\usepackage{url} %% Define a new 'leo' style for the package that will use a smaller font. \makeatletter \def\url@leostyle{% \@ifundefined{selectfont}{\def\UrlFont{\sf}}{\def\UrlFont{\small\ttfamily}}} \makeatother %% Now actually use the newly defined style. \urlstyle{leo}

In a BibTeX entry:

@misc{ c.elmohamed, author = "Saleh Elmohamed", title = "Examples in {H}igh {P}erformance {F}ortran", howpublished = "Website", year = {1996}, note = {\url{http://www.npac.syr.edu/projects/ cpsedu/summer98summary/ examples/hpf/hpf.html}} }

Result, before


Result, after


Things to watch out for

I tweak the default url style to use a smaller version of the typewriter font because I otherwise find that the Adobe Courier font I use (see also the Using Courier tip) displays a bit too large for my tastes, but also because the larger font still causes more spacing ugliness (in terms of underfull hboxes), as illustrated by the following screenshot:

If strange ‘%’ signs start appearing in the list of references in the bibliography section, this is because BibTeX inserts those when it encounters a line it feels is too long:

This is purely a BibTeX thing: inside a URL being handled by the url package, the line won't actually be too long — after all the whole idea is for url to be responsible for splitting it. The solution, as shown in the listing given earlier, is to add some stray whitespace to the long url. BibTeX will then no longer think the line is too long, and \url{} ignores all whitespace anyway, so it will not appear in the output.

The biggest problem with the url package is that you do not use it in your LaTeX source file, but in your BibTeX source files, thus making your bibliographies non-portable: once you start using \url{} in your BibTeX entries, you will be forced to include the url package in all your LaTeX files that use that bibliography file.



Leo Breebaart (leo@lspace.org)
Last updated: 27 June 2016

0 Thoughts to “Urls In Latex Bibliography Format

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *