# Bibliography and URLs in references

The functions in the end are defined in my .bst file. What they do is, when I add the field

webpage={http://xxx.xxx.xxx...../}


to a bibitem, it displays at the end of the reference in the bibliography the text:

... URL: http://xxx.xxx.xxx...../


(where the three first dots indicate the rest of the reference: authors, title, journal, etc..) What I would like is that instead of showing the actual url, it became a link of the text URL. This way the reference would only show the text URL at the end (and not the url itself) which I could click and go to that link.

Is this possible?

FUNCTIONS

ENTRY
...
webpage
year
...
}

FUNCTION {format.webpage}
{
webpage "webpage" bibinfo.check
duplicate$empty$ 'skip${ new.block bbl.availableat " \url{" * swap$ *  "}" *
}
if$} FUNCTION {bbl.availableat} { "URL: " } FUNCTION {new.block} { output.state before.all = 'skip$
{ after.block 'output.state := }
if$} FUNCTION {bibinfo.check} { swap$
duplicate$missing$
{
pop$pop$
""
}
{ duplicate$empty$
{
swap$pop$
}
{ swap$pop$
}
if$} if$
}


# Edit

I tried Mico's suggestion and changed the webpagefunction like so:

FUNCTION {format.webpage}
{
webpage "webpage" bibinfo.check
duplicate$empty$ 'skip${ new.block " \href{" * swap$ *  "}{URL}" *
}
if$}  my bibfile contains only one item: @ARTICLE{Dummy2012, author = {{Vink}, J.~S. and {Gr{\"a}fener}, G.}, title = {{The Transition Mass-loss Rate: Calibrating the Role of Line-driven Winds in Massive Star Evolution}}, journal = {APJL}, year = {2012}, volume = {751}, pages = {L34}, month = jun, eid = {L34}, adsnote = {Provided by the SAO/NASA Astrophysics Data System}, archiveprefix = {arXiv}, doi = {10.1088/2041-8205/751/2/L34}, eprint = {1205.0394}, keywords = {stars: early-type, stars: evolution, stars: mass-loss, stars: winds,outflows }, primaryclass = {astro-ph.SR}, webpage = {http://adsabs.harvard.edu/abs/2012ApJ...751L..34V} }  And upon compiling I get the error: You can't pop an empty literal stack for entry Dummy2012  and the .bbl file looks like this: \begin{thebibliography}{1} \expandafter\ifx\csname natexlab\endcsname\relax\def\natexlab#1{#1}\fi \bibitem[{{Vink} y {Gr{\"a}fener}(2012)}]{Dummy2012} {\sc {Vink}, J.~S.} y {\sc {Gr{\"a}fener}, G.} \newblock {The Transition Mass-loss Rate: Calibrating the Role of Line-driven Winds in Massive Star Evolution}. \newblock {\em APJL\/}, vol. 751, p\'agina L34, \newblock http://adsabs.harvard.edu/abs/2012ApJ...751L..34V \href{2012}{URL}. \end{thebibliography}  - ## 1 Answer I'm assuming that you've also loaded the hyperref package. Then, instead of specifying webpage={http://xxx.xxx.xxx...../}  you could state webpage={\href{http://xxx.xxx.xxx...../}{URL}}  and correspondingly simplify the format.webpage and bbl.availableat BibTeX functions. Alternatively, if you don't want to change the content of the webpage field, you could rewrite one or both of these BibTeX functions to insert the URL provided by the webpage field inside the first argument of the \href function and specify URL as the second argument of \href. Looking at your code, I would guess that (i) you needn't invoke the bbl.availableat function at all and (ii) you may want to replace the string " \url{" * swap$ *  "}"


in the format.webpage function with

" \href{" * swap$* "}{URL}"  Note that I haven't been able to try this out fully because you haven't provided sufficiently many details about your custom .bst file. Addendum to follow up on the OP's additional information: Please try the following form of the BibTeX function format.webpage: FUNCTION {format.webpage} { webpage empty$
{ "" }
{ new.block " \href{" webpage * "}{URL}" * }
if\$
}


where the content of the webpage field should be a URL, e.g., http://adsabs.harvard.edu/abs/2012ApJ...751L..34V. Finally -- and you may already have done so, but I'll mention it for the sake of completeness -- be sure to include in your format.article function a line such as

format.webpage output

-
Thanks @Mico, I tried your suggestion but couldn't compile. Please take a look at the new Edit in the question. Oh, and I didn't put the .bst file because it's pretty big, but if you want to take a look at it, just tell me and I'll post it. –  Gabriel May 23 '12 at 13:31
@Gaba_p: Please see my follow-up comments and suggestions. –  Mico May 23 '12 at 14:22
Great! That worked perfectly, thank you so much! –  Gabriel May 23 '12 at 14:41