Thanks from me, I could use this Question thread to solve my problems with URL citations. I think, my solution adds a bit flexibility.
This part extends the answer from @madit:
For online publications there is not only an URL, but also a DOI (See Wiki: https://en.wikipedia.org/wiki/Digital_object_identifier, example: https://doi.org/10.1002/andp.19163540702) for a specific source, for example in journals (i.e. Nature, Science, ...) and also academic eBooks.
So it is often desired to cite with a DOI instead of an URL with a date of access.
So in the same folder as main.tex are the style file bibstyle.bst and the bibliography source file myRefs.bib.
In main.tex, the bibliography is created by:
\bibliographystyle{bibstyle}
\bibliography{myRefs}
In bibstyle.bst multiple adjustments need to be made:
- At the beginning, new possible entries (
doi, url, urldate) need to be created:
ENTRY
{ address
...
doi
...
url
urldate
...
}
{}
{ label }
- Then, a new function needs to be created, that formats the new entries into a part of the final citation. Here, I worked from the code of @madit, but I included the preferred option for the DOI and I changed the return for no URL or DOI from
{ "" } to 'skip$. Unless the last adjustment is made, it may throw an error along the lines of ---the literal stack isn't empty for entry MyCitation. The reason is basically because LaTeX may not handle an emtpy string well instead of no return, when building the citation text. Additionally for the DOI output, I linked it via the official doi website (https://doi.org/) to guarantee that the link works and that it is displayed correctly via \detokenize even with characters like _ or \ in \texttt mode. So this results in:
FUNCTION {format.url}
{ doi empty$
{ url empty$
'skip$
{
". URL:~\url{" * url * "}" *
urldate empty$
{ "there is url but no urldate in " cite$ * warning$ }
{
"~(Accessed on: " * urldate * ")" *
}
if$
}if$
}
{". DOI:~\href{https://doi.org/" * doi * "}{\texttt{\detokenize{" * doi * "}}}" *
}if$
}
- The last step is to include
format.url "" output
new.block
before
note output
fin.entry
}
in all different source type functions, for example:
FUNCTION {booklet}
{ output.bibitem
format.authors output
format.title "title" output.check
howpublished "howpublished" bibinfo.check output
address "address" bibinfo.check output
format.date output
format.url "" output
new.block
format.note output
fin.entry
}
The advantage using this solution is: The bibliography handles URLs and DOIs automatically without using url = {\url{...}}, or url = {\href{...}{...}},. I hope this helps.
Note: To adjust the link-colors, I used in main.tex:
\usepackage{hyperref}
\hypersetup{
colorlinks,
citecolor=black,
filecolor=black,
linkcolor=black,
urlcolor=black
}% sets the style for links
natbibandbiblatex(with screenshot-snippets of the PDF) is here: http://nschloe.blogspot.de/2009/06/bibtex-how-to-cite-website_21.html – nutty about natty May 01 '13 at 08:17author = {{Jemison Laboratory}},. Works for natbib, at least. – Mars May 18 '16 at 16:50