adding \url link to function in .bst file

1.1k views Asked by At

How can I add a \url{} command to a .bst function. In this case, if the URL field is empty I want it to fill it with data from the DOI field, See the code below. I need to add this to the 4th line, but every way I have tried just causes it to crash.

FUNCTION {format.url}
{ is.use.url
    { url empty$
      {"[Online]. Available: https://doi.org/" doi * }
      { this.to.prev.status
        this.status.std
        cap.yes 'status.cap :=
        name.url.prefix " " *
        "\url{" * url * "}" *
        punct.no 'this.status.punct :=
        punct.period 'prev.status.punct :=
        space.normal 'this.status.space :=
        space.normal 'prev.status.space :=
        quote.no 'this.status.quote :=
      }
    if$
    }
    { "" }
  if$
}

This comes from IEEE.bst file and can be found around line 1920

1

There are 1 answers

0
Austin Downey On BEST ANSWER

This is the code I developed to auto-fill the URL field from the DOI or arXiv number. All URLs are hyperlinked.

You must use

\usepackage[hidelinks]{hyperref}

for the hyperlinks to work. Here is the code I made for the .bst file.

FUNCTION {format.url}
{ is.use.url
    { url empty$
        { doi empty$
            { eprint empty$
                { "" 
                }
                { this.to.prev.status
                this.status.std
                cap.yes 'status.cap :=
                "\href{https://arxiv.org/pdf/" eprint * "}{ [Online]. Available: https://arxiv.org/pdf/" * eprint * "}" * output
                punct.no 'this.status.punct :=
                punct.period 'prev.status.punct :=
                space.normal 'this.status.space :=
                space.normal 'prev.status.space :=
                quote.no 'prev.status.quote :=    
                }
              if$
            }
            { this.to.prev.status
            this.status.std
            cap.yes 'status.cap :=
            "\href{http://dx.doi.org/" doi * "}{[Online]. Available: http://dx.doi.org/" * doi * "}" * output
            punct.no 'this.status.punct :=
            punct.period 'prev.status.punct :=
            space.normal 'this.status.space :=
            space.normal 'prev.status.space :=
            quote.no 'this.status.quote :=    
            }
          if$
        }
        { this.to.prev.status
            this.status.std
            cap.yes 'status.cap :=
            name.url.prefix " " *
            "\url{" * url * "}" *
            punct.no 'this.status.punct :=
            punct.period 'prev.status.punct :=
            space.normal 'this.status.space :=
            space.normal 'prev.status.space :=
            quote.no 'this.status.quote :=
        }
    if$
    }
    { "" }
  if$
}