adapt plainnat bibtex natbib style to only show the url if no doi is available

Since the URL in a bibtex entry is typically just duplicate information when the entry has a DOI, I want to hide it.1

Here’s how:

diff -r 5b78f551d0a0 plainnatnoturl.bst
--- a/plainnatnoturl.bst    Tue Apr 04 10:45:08 2017 +0200
+++ b/plainnatnoturl.bst    Tue Apr 04 10:52:25 2017 +0200
@@ -1,5 +1,7 @@
-%% File: `plainnat.bst'
-%% A modification of `plain.bst' for use with natbib package 
+%% File: `plainnatnoturl.bst'
+%% A modification of `plain.bst' and `plainnat.bst' for use with natbib package 
+%% 
+%% From /usr/share/texmf-dist/bibtex/bst/natbib/plainnat.bst
 %%
 %% Copyright 1993-2007 Patrick W Daly
 %% Max-Planck-Institut f\"ur Sonnensystemforschung
@@ -285,7 +288,11 @@
 FUNCTION {format.url}
 { url empty$
     { "" }
-    { new.block "URL \url{" url * "}" * }
+    { doi empty$
+      { new.block "URL \url{" url * "}" * }
+      { "" }
+      if$
+    }
   if$
 }

Just put this next to your .tex file, add a header linking the doi

\newcommand*{\doi}[1]{\href{http://dx.doi.org/#1}{doi: #1}}

and use the bibliography referencing plainnatnoturl.bst

\bibliographystyle{plainnatnoturl}
\bibliography{YOURBIBFILE}

That’s it. Thanks to toliveira from tex.stackexchange!

Footnotes:

1

Also I’m scraping at my page limit and cutting a line for roughly every second entry helps a lot :)

Inhalt abgleichen
Willkommen im Weltenwald!



Beliebte Inhalte

sn.1w6.org news