[Tex/LaTex] How to show URLs in a bibliography as (hyperlinked) stubs

bibtexhyperrefurls

\label{References}
\renewcommand{\bibname}{References}
\lhead{\emph{References}}
\bibliographystyle{abbrvnat}
\bibliography{Bibliography}

I want to have all urls in my references list to be hyperlinked say under the word "URL". I've 100+ urls and its not looking very nice. I'm using BibTeX; so far, abbrvnat is the best style that has worked for me.

I'm using a template, hyperref is working fine. (I can hyper jump within the document.)
Any quick solution, i.e. not having to do this manually with each bib entry?

Best Answer

The following solution operates only on the contents of url fields. URLs given in other fields are not treated. Since hyperlinking is being performed, the hyperref package must be loaded.

  • Find the file abbrvnat.bst in your TeX distribution. Make a copy of this file, naming the copy (say) myabbrvnat.bst. (Don't edit directly an original file from your TeX distribution.)

  • Open myabbrvnat.bst in a text editor. (The editor you use for your tex files will do fine.)

  • Locate the function format.url. In my copy of the file, the function starts on line 306.

  • In this function, replace the line

    { new.block "URL \url{" url * "}" * }
    

    with

    { new.block "\href{" url * "}{URL}" * }
    
  • Save the file myabbrvnat.bst, either in the directory where your main tex file is located, or in a directory that's searched by BibTeX. If you choose the latter method, be sure to update the filename database of your TeX distribution.

  • Start using the new bibliography style by specifying it as the argument of the \bibliographystyle instruction. Be sure to run LaTeX, BibTeX, and LaTeX twice more to propagate all changes.

In the pdf file version of the screenshot shown below, the blue "URL" stub is a hyperlink to this question.

enter image description here

The files main.tex and main.bib that generated this screenshot are as follows:

main.tex

\documentclass{article}
\bibliographystyle{myabbrvnat}
\usepackage{natbib}
\usepackage[colorlinks,urlcolor=blue]{hyperref}
\begin{document}
\nocite{*}
\bibliography{main}
\end{document}

main.bib

@misc{xyz,
  author = "User70997",
  title  = "How to show {URLs} in a bibliography as (hyperlinked) stubs?",
  year   = 2015,
  month  = "January",
  url    = "http://tex.stackexchange.com/q/224403/5001",
}