Redundancy in bib file: conditionally suppress url if same as doi? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How to get DOI links in bibliographyBiblatex: use doi only if there is no URLHow to sometimes suppress the printing of the URL fieldbiblatex error: invalid format of field 'date' - what's wrong?Biblatex: Print ISBN only if DOI is not definedBiblatex: Convert doi-url into doi fieldapacite: how to suppress url if doi is avalable?Why does biber increase compilation time of pdflatex runs dramatically (factor 2.8!!)?Define bibstyle output hierarchy for doi, url, isbn and issn in BiBTeXSuppress URL if DOI is present in biblatex-chicagoIs there an ebib-like bibliography manager for emacs designed for biblatex?BibTeX style file with hierachical use of DOI, URL fieldsMultiple doi, url, and eprint entries in biblatexBiblatex: Convert doi-url into doi fieldHow to fix the URL and DOI font? Say, make it smallernatbib + BibTeX: suppress url if doi is availableApacite: Supress URL % DOI except for Web PagesRemove period between DOI and urldateSuppress URL if DOI is present in biblatex-chicagoPrevent `biber --tool` from removing non-standard fields in .bib files

Should a wizard buy fine inks every time he want to copy spells into his spellbook?

Is it dangerous to install hacking tools on my private linux machine?

Select every other edge (they share a common vertex)

Is openssl rand command cryptographically secure?

What adaptations would allow standard fantasy dwarves to survive in the desert?

New Order #6: Easter Egg

I can't produce songs

Getting out of while loop on console

How can a team of shapeshifters communicate?

"klopfte jemand" or "jemand klopfte"?

What does 丫 mean? 丫是什么意思?

RSA find public exponent

Differences to CCompactSize and CVarInt

Cut your dress down to your length/size

Monty Hall Problem-Probability Paradox

What does this say in Elvish?

Is CEO the "profession" with the most psychopaths?

A term for a woman complaining about things/begging in a cute/childish way

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

How does the math work when buying airline miles?

How would a mousetrap for use in space work?

Positioning dot before text in math mode

Universal covering space of the real projective line?

How would you say "es muy psicólogo"?



Redundancy in bib file: conditionally suppress url if same as doi?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How to get DOI links in bibliographyBiblatex: use doi only if there is no URLHow to sometimes suppress the printing of the URL fieldbiblatex error: invalid format of field 'date' - what's wrong?Biblatex: Print ISBN only if DOI is not definedBiblatex: Convert doi-url into doi fieldapacite: how to suppress url if doi is avalable?Why does biber increase compilation time of pdflatex runs dramatically (factor 2.8!!)?Define bibstyle output hierarchy for doi, url, isbn and issn in BiBTeXSuppress URL if DOI is present in biblatex-chicagoIs there an ebib-like bibliography manager for emacs designed for biblatex?BibTeX style file with hierachical use of DOI, URL fieldsMultiple doi, url, and eprint entries in biblatexBiblatex: Convert doi-url into doi fieldHow to fix the URL and DOI font? Say, make it smallernatbib + BibTeX: suppress url if doi is availableApacite: Supress URL % DOI except for Web PagesRemove period between DOI and urldateSuppress URL if DOI is present in biblatex-chicagoPrevent `biber --tool` from removing non-standard fields in .bib files










32















Mathscinet gives bibtex entries with both a doi and a url field included. Typically they look something like



@article some-article,
[…]
DOI = 10.1016/j.apal.2008.12.003,
URL = http://dx.doi.org/10.1016/j.apal.2008.12.003,



I'm using amsalpha.bst, modified with urlbst to process both these fields. Of course, this means that they both appear, completely redundantly, in my bibliography!



My question is: what's the principled way to deal with this? Here are the options I've thought of so far:



  • Modify the bib file so it checks for this redundancy, and doesn't typeset the url in such cases. This seems ideal if it's possible; has anyone already done something like this? If not, is it likely to be doable by someone with a little programming experience but no existing understanding of .bst files?


  • Use a bibstyle that typesets one of url and doi but not both. Not ideal: other bib entries might have only one but not both, or might have a url different from the doi.


  • Comment out (or delete) the `url' field by hand, in the bib file, in these cases. This is what I'm currently doing. Seems a little clunky; also, somewhat violates “separation of form from content”: having the fields the same is correct as content, it’s just inappropriate for them then to both be typeset.


Related question: How to get DOI links in bibliography










share|improve this question
























  • I wonder if bibtools has the resources to automagically make your .bib file suitable for one of your listed options... ctan.org/tex-archive/biblio/bibtex/utils/bibtools

    – Seamus
    Nov 20 '10 at 12:20











  • The problem with this is that since the url and doi fields won't be identical, even if they say the same thing, so you can't just check whether they are equal and conditionally print only one of them...

    – Seamus
    Nov 22 '10 at 15:46






  • 1





    @Seamus: true, but we know what to look for. I'm at the wrong computer just at the moment, but give me a couple of hours and I think I have a solution :-)

    – Joseph Wright
    Nov 22 '10 at 17:41















32















Mathscinet gives bibtex entries with both a doi and a url field included. Typically they look something like



@article some-article,
[…]
DOI = 10.1016/j.apal.2008.12.003,
URL = http://dx.doi.org/10.1016/j.apal.2008.12.003,



I'm using amsalpha.bst, modified with urlbst to process both these fields. Of course, this means that they both appear, completely redundantly, in my bibliography!



My question is: what's the principled way to deal with this? Here are the options I've thought of so far:



  • Modify the bib file so it checks for this redundancy, and doesn't typeset the url in such cases. This seems ideal if it's possible; has anyone already done something like this? If not, is it likely to be doable by someone with a little programming experience but no existing understanding of .bst files?


  • Use a bibstyle that typesets one of url and doi but not both. Not ideal: other bib entries might have only one but not both, or might have a url different from the doi.


  • Comment out (or delete) the `url' field by hand, in the bib file, in these cases. This is what I'm currently doing. Seems a little clunky; also, somewhat violates “separation of form from content”: having the fields the same is correct as content, it’s just inappropriate for them then to both be typeset.


Related question: How to get DOI links in bibliography










share|improve this question
























  • I wonder if bibtools has the resources to automagically make your .bib file suitable for one of your listed options... ctan.org/tex-archive/biblio/bibtex/utils/bibtools

    – Seamus
    Nov 20 '10 at 12:20











  • The problem with this is that since the url and doi fields won't be identical, even if they say the same thing, so you can't just check whether they are equal and conditionally print only one of them...

    – Seamus
    Nov 22 '10 at 15:46






  • 1





    @Seamus: true, but we know what to look for. I'm at the wrong computer just at the moment, but give me a couple of hours and I think I have a solution :-)

    – Joseph Wright
    Nov 22 '10 at 17:41













32












32








32


12






Mathscinet gives bibtex entries with both a doi and a url field included. Typically they look something like



@article some-article,
[…]
DOI = 10.1016/j.apal.2008.12.003,
URL = http://dx.doi.org/10.1016/j.apal.2008.12.003,



I'm using amsalpha.bst, modified with urlbst to process both these fields. Of course, this means that they both appear, completely redundantly, in my bibliography!



My question is: what's the principled way to deal with this? Here are the options I've thought of so far:



  • Modify the bib file so it checks for this redundancy, and doesn't typeset the url in such cases. This seems ideal if it's possible; has anyone already done something like this? If not, is it likely to be doable by someone with a little programming experience but no existing understanding of .bst files?


  • Use a bibstyle that typesets one of url and doi but not both. Not ideal: other bib entries might have only one but not both, or might have a url different from the doi.


  • Comment out (or delete) the `url' field by hand, in the bib file, in these cases. This is what I'm currently doing. Seems a little clunky; also, somewhat violates “separation of form from content”: having the fields the same is correct as content, it’s just inappropriate for them then to both be typeset.


Related question: How to get DOI links in bibliography










share|improve this question
















Mathscinet gives bibtex entries with both a doi and a url field included. Typically they look something like



@article some-article,
[…]
DOI = 10.1016/j.apal.2008.12.003,
URL = http://dx.doi.org/10.1016/j.apal.2008.12.003,



I'm using amsalpha.bst, modified with urlbst to process both these fields. Of course, this means that they both appear, completely redundantly, in my bibliography!



My question is: what's the principled way to deal with this? Here are the options I've thought of so far:



  • Modify the bib file so it checks for this redundancy, and doesn't typeset the url in such cases. This seems ideal if it's possible; has anyone already done something like this? If not, is it likely to be doable by someone with a little programming experience but no existing understanding of .bst files?


  • Use a bibstyle that typesets one of url and doi but not both. Not ideal: other bib entries might have only one but not both, or might have a url different from the doi.


  • Comment out (or delete) the `url' field by hand, in the bib file, in these cases. This is what I'm currently doing. Seems a little clunky; also, somewhat violates “separation of form from content”: having the fields the same is correct as content, it’s just inappropriate for them then to both be typeset.


Related question: How to get DOI links in bibliography







bibliographies bibtex conditionals urls doi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:35









Community

1




1










asked Nov 19 '10 at 23:09









Peter LeFanu LumsdainePeter LeFanu Lumsdaine

1,92122239




1,92122239












  • I wonder if bibtools has the resources to automagically make your .bib file suitable for one of your listed options... ctan.org/tex-archive/biblio/bibtex/utils/bibtools

    – Seamus
    Nov 20 '10 at 12:20











  • The problem with this is that since the url and doi fields won't be identical, even if they say the same thing, so you can't just check whether they are equal and conditionally print only one of them...

    – Seamus
    Nov 22 '10 at 15:46






  • 1





    @Seamus: true, but we know what to look for. I'm at the wrong computer just at the moment, but give me a couple of hours and I think I have a solution :-)

    – Joseph Wright
    Nov 22 '10 at 17:41

















  • I wonder if bibtools has the resources to automagically make your .bib file suitable for one of your listed options... ctan.org/tex-archive/biblio/bibtex/utils/bibtools

    – Seamus
    Nov 20 '10 at 12:20











  • The problem with this is that since the url and doi fields won't be identical, even if they say the same thing, so you can't just check whether they are equal and conditionally print only one of them...

    – Seamus
    Nov 22 '10 at 15:46






  • 1





    @Seamus: true, but we know what to look for. I'm at the wrong computer just at the moment, but give me a couple of hours and I think I have a solution :-)

    – Joseph Wright
    Nov 22 '10 at 17:41
















I wonder if bibtools has the resources to automagically make your .bib file suitable for one of your listed options... ctan.org/tex-archive/biblio/bibtex/utils/bibtools

– Seamus
Nov 20 '10 at 12:20





I wonder if bibtools has the resources to automagically make your .bib file suitable for one of your listed options... ctan.org/tex-archive/biblio/bibtex/utils/bibtools

– Seamus
Nov 20 '10 at 12:20













The problem with this is that since the url and doi fields won't be identical, even if they say the same thing, so you can't just check whether they are equal and conditionally print only one of them...

– Seamus
Nov 22 '10 at 15:46





The problem with this is that since the url and doi fields won't be identical, even if they say the same thing, so you can't just check whether they are equal and conditionally print only one of them...

– Seamus
Nov 22 '10 at 15:46




1




1





@Seamus: true, but we know what to look for. I'm at the wrong computer just at the moment, but give me a couple of hours and I think I have a solution :-)

– Joseph Wright
Nov 22 '10 at 17:41





@Seamus: true, but we know what to look for. I'm at the wrong computer just at the moment, but give me a couple of hours and I think I have a solution :-)

– Joseph Wright
Nov 22 '10 at 17:41










6 Answers
6






active

oldest

votes


















13














The modifications made by urlbst are quite clear, so the change you want is actually not too hard (by BibTeX standards). If you open up your .bst files, you need to search for a function called output.web.refs. It needs modifying to read



FUNCTION output.web.refs

new.block
output.url
addeprints eprint empty$ not and
format.eprint output.nonnull
'skip$
if$
adddoiresolver doi empty$ not and

url empty$
format.doi output.nonnull

doiurl doi * url =
'skip$
format.doi output.nonnull
if$

if$

'skip$
if$
addpubmedresolver pubmed empty$ not and
format.pubmed output.nonnull
'skip$
if$



All that has happened here is that I've added a test for an empty URL and a second for the URL being the same as the DOI once the prefix is added.






share|improve this answer

























  • Marvellous, works a charm! The one change I had to make (noting it in case others have the same issue): I had to excise the “addpubmedresolver” block, since my .bst file wasn’t set up to do pubmed data.

    – Peter LeFanu Lumsdaine
    Nov 27 '10 at 0:10











  • p.s. this has now given me the courage to start playing around with the .bst file myself for the first time, finding that (a) making minor tweaks is not as impossibly arcane as it had previously seemed, but (b) my goodness, it’s a strange language!

    – Peter LeFanu Lumsdaine
    Nov 27 '10 at 0:33


















20














The original question is about a standard BibTeX style, but inspired by lockstep I've worked out a biblatex solution as a complement to my other answer. The method here is to add the appropriate prefix to the raw DOI, then test this for equivalence to the URL. The prefix needs to be processed with detokenize as this is how the URL field is formatted.



documentclassarticle

usepackagebiblatex

renewbibmacro*doi+eprint+url%
iftogglebbx:doi
%
iffieldundefdoi

%
begingroup
edefURLorDOI%
detokenizehttp://dx.doi.org/%
thefielddoi%
%
iffieldequalsurlURLorDOI
endgroup
%
endgroup
printfielddoi%
%
%

%
newunitnewblock
iftogglebbx:eprint
usebibmacroeprint
%
newunitnewblock
iftogglebbx:url
usebibmacrourl+urldate


usepackagefilecontents

beginfilecontentsjobname.bib
@miscA01,
author = Author, A.,
year = 2001,
title = Alpha,
doi = 10.1016/j.apal.2008.12.003,


@miscB02,
author = Buthor, B.,
year = 2002,
title = Bravo,
url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
urldate = 2010-11-22,


@miscC03,
author = Cuthor, C.,
year = 2003,
title = Charlie,
doi = 10.1016/j.apal.2008.12.003,
url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
urldate = 2010-11-22,

endfilecontents

bibliographyjobname

begindocument

nocite*

printbibliography

enddocument





share|improve this answer

























  • +1 - This is much better than my attempt. However, shouldn't there be a makeatletter-makeatother combo? (And if not, why not?)

    – lockstep
    Nov 22 '10 at 20:48






  • 1





    @lockstep. No, I didn't need makeatletter as csname will always construct a control sequence name, even with non-letter tokens (although some may need string, for example active tokens). However, I realised that biblatex provides thefield, which avoids the need to access the internal macro at all.

    – Joseph Wright
    Nov 22 '10 at 20:52












  • Just to explain the begingroup ... endgroup in the above, I'm keeping URLorDOI local here, so outside of my test it does not exist. This is a good idea in many cases: it would allow me to use an otherwise taken macro name, for example.

    – Joseph Wright
    Nov 22 '10 at 20:54











  • @lockstep, @Joseph: thanks very much, these look marvellous! I’ll accept one as soon as I’ve tried them out/got them working :-)

    – Peter LeFanu Lumsdaine
    Nov 26 '10 at 22:12


















13














I didn't manage to test for "sort-of-identical" doi und url fields, but here's a solution using biblatex - url and urldate fields will only be typeset if the respective entry doesn't include a doi field.



documentclassarticle

usepackagebiblatex

DeclareFieldFormaturl%
iffieldundefdoi%
mkbibacroURLaddcolonspaceurl#1%
%
%


DeclareFieldFormaturldate%
iffieldundefdoi%
mkbibparensbibstringurlseenspace#1%
%
%


usepackagefilecontents

beginfilecontentsjobname.bib
@miscA01,
author = Author, A.,
year = 2001,
title = Alpha,
doi = 10.1016/j.apal.2008.12.003,


@miscB02,
author = Buthor, B.,
year = 2002,
title = Bravo,
url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
urldate = 2010-11-22,


@miscC03,
author = Cuthor, C.,
year = 2003,
title = Charlie,
doi = 10.1016/j.apal.2008.12.003,
url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
urldate = 2010-11-22,

endfilecontents

bibliographyjobname

begindocument

nocite*

printbibliography

enddocument





share|improve this answer


















  • 1





    This was superbly useful - thank you. I only wish I could find stuff like this by searching the site rather than having to half-write questions first! I have just extended this to print the url iff neither doi nor eprinttype is defined. Seems to work for my simple test case...

    – cfr
    Sep 27 '14 at 0:25


















6














This is really a comment to Joseph Wright's answer above, but with included code.



I only just now stumbled across this answer (I'm the author of urlbst).



This is great, Joseph -- thanks. I've incorporated something rather like this into the urlbst repository at https://bitbucket.org/nxg/urlbst, and this should appear in the next release of urlbst (whenever that is).



FUNCTION output.web.refs

new.block
inlinelinks
'skip$ % links were inline -- don't repeat them
% If the generated DOI will be the same as the URL,
% then don't print the URL (thanks to Joseph Wright for this code,
% at http://tex.stackexchange.com/questions/5660)
adddoiresolver
doiurl doi empty$ "X" doi if$ * % DOI URL to be generated
url empty$ "Y" url if$ % the URL, or "Y" if empty
= % are the strings equal?
and
'skip$
output.url
if$
addeprints eprint empty$ not and
format.eprint output.nonnull
'skip$
if$
adddoiresolver doi empty$ not and
format.doi output.nonnull
'skip$
if$
addpubmedresolver pubmed empty$ not and
format.pubmed output.nonnull
'skip$
if$

if$



The difference is that this avoids printing the URL if it would equal the DOI, rather than the other way round, and also checks if either or both is empty.



For what it's worth, my response to the initial problem would be to delete the semi-redundant URL field in the .bib file. I would only have both if the URL gave an alternative (possibly openly available) version of the reference.






share|improve this answer























  • Norman, it there a way to only print isbn/issn if there is no url/doi in BibTeX? Something like this: tex.stackexchange.com/questions/76534/…

    – TobiasDK
    Jun 4 '15 at 17:59











  • Not in urlbst, but if you're willing to edit your .bst file, then something like isbn url empty$ doi empty$ and and format.isbn output.nonnull format.url output.nonnull format.doi output.nonnull if$ would (I think; not tested) call the format.isbn function only if url and doi were empty, and call format.url and format.doi if either is non-empty. The .bst file would have to define functions format.isbn and and. Does that point the way to the logic you need?

    – Norman Gray
    Jun 4 '15 at 21:41












  • Thank you for the answer and I have tried using your ideas, but its not easy to figure out.. I have posted a new question to deal with my problem. Maybe you have time to look at it: [tex.stackexchange.com/questions/248732/…. Thanks in advance.

    – TobiasDK
    Jun 5 '15 at 9:47


















1














A quick solution, without BST manipulation, can be a sed script that deletes the URL field if followed by a DOI field, or similar. Worked for me; I have a bib library of dblp bib entries from which I extract the relevant ones with bibtool, and then delete the spurious URL fields with sed.



Here is my sed script, acknowledging https://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string for the magic incantation.



# First, a magic incantation to turn sed from a line-based editor
# to an editor on the whole input.

1h;2,$H;$!d;g

# Then, the actual command, replacing url=A,doi=B by doi=B

s/s*urls*=s*[^]*},(s*dois*=s*[^]*})/1/g

# Note that s matches a whitespace character (including n).





share|improve this answer


















  • 1





    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.

    – Martin Schröder
    Apr 17 '17 at 13:42


















0














When using BibLaTeX, this can be very easily done on the data level, without fuddling with output templates or even changing the .bib file.



Just use the iffieldundeffield nameundefined casedefined case macro:



AtEveryBibitem
iffieldundefurlclearfielddoi



Note that this doesn't do the if DOI and URL are the same test as suggested by the OP, but just the simpler only show DOI when there's no URL case as some of the other answers.





share























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "85"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f5660%2fredundancy-in-bib-file-conditionally-suppress-url-if-same-as-doi%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    6 Answers
    6






    active

    oldest

    votes








    6 Answers
    6






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    13














    The modifications made by urlbst are quite clear, so the change you want is actually not too hard (by BibTeX standards). If you open up your .bst files, you need to search for a function called output.web.refs. It needs modifying to read



    FUNCTION output.web.refs

    new.block
    output.url
    addeprints eprint empty$ not and
    format.eprint output.nonnull
    'skip$
    if$
    adddoiresolver doi empty$ not and

    url empty$
    format.doi output.nonnull

    doiurl doi * url =
    'skip$
    format.doi output.nonnull
    if$

    if$

    'skip$
    if$
    addpubmedresolver pubmed empty$ not and
    format.pubmed output.nonnull
    'skip$
    if$



    All that has happened here is that I've added a test for an empty URL and a second for the URL being the same as the DOI once the prefix is added.






    share|improve this answer

























    • Marvellous, works a charm! The one change I had to make (noting it in case others have the same issue): I had to excise the “addpubmedresolver” block, since my .bst file wasn’t set up to do pubmed data.

      – Peter LeFanu Lumsdaine
      Nov 27 '10 at 0:10











    • p.s. this has now given me the courage to start playing around with the .bst file myself for the first time, finding that (a) making minor tweaks is not as impossibly arcane as it had previously seemed, but (b) my goodness, it’s a strange language!

      – Peter LeFanu Lumsdaine
      Nov 27 '10 at 0:33















    13














    The modifications made by urlbst are quite clear, so the change you want is actually not too hard (by BibTeX standards). If you open up your .bst files, you need to search for a function called output.web.refs. It needs modifying to read



    FUNCTION output.web.refs

    new.block
    output.url
    addeprints eprint empty$ not and
    format.eprint output.nonnull
    'skip$
    if$
    adddoiresolver doi empty$ not and

    url empty$
    format.doi output.nonnull

    doiurl doi * url =
    'skip$
    format.doi output.nonnull
    if$

    if$

    'skip$
    if$
    addpubmedresolver pubmed empty$ not and
    format.pubmed output.nonnull
    'skip$
    if$



    All that has happened here is that I've added a test for an empty URL and a second for the URL being the same as the DOI once the prefix is added.






    share|improve this answer

























    • Marvellous, works a charm! The one change I had to make (noting it in case others have the same issue): I had to excise the “addpubmedresolver” block, since my .bst file wasn’t set up to do pubmed data.

      – Peter LeFanu Lumsdaine
      Nov 27 '10 at 0:10











    • p.s. this has now given me the courage to start playing around with the .bst file myself for the first time, finding that (a) making minor tweaks is not as impossibly arcane as it had previously seemed, but (b) my goodness, it’s a strange language!

      – Peter LeFanu Lumsdaine
      Nov 27 '10 at 0:33













    13












    13








    13







    The modifications made by urlbst are quite clear, so the change you want is actually not too hard (by BibTeX standards). If you open up your .bst files, you need to search for a function called output.web.refs. It needs modifying to read



    FUNCTION output.web.refs

    new.block
    output.url
    addeprints eprint empty$ not and
    format.eprint output.nonnull
    'skip$
    if$
    adddoiresolver doi empty$ not and

    url empty$
    format.doi output.nonnull

    doiurl doi * url =
    'skip$
    format.doi output.nonnull
    if$

    if$

    'skip$
    if$
    addpubmedresolver pubmed empty$ not and
    format.pubmed output.nonnull
    'skip$
    if$



    All that has happened here is that I've added a test for an empty URL and a second for the URL being the same as the DOI once the prefix is added.






    share|improve this answer















    The modifications made by urlbst are quite clear, so the change you want is actually not too hard (by BibTeX standards). If you open up your .bst files, you need to search for a function called output.web.refs. It needs modifying to read



    FUNCTION output.web.refs

    new.block
    output.url
    addeprints eprint empty$ not and
    format.eprint output.nonnull
    'skip$
    if$
    adddoiresolver doi empty$ not and

    url empty$
    format.doi output.nonnull

    doiurl doi * url =
    'skip$
    format.doi output.nonnull
    if$

    if$

    'skip$
    if$
    addpubmedresolver pubmed empty$ not and
    format.pubmed output.nonnull
    'skip$
    if$



    All that has happened here is that I've added a test for an empty URL and a second for the URL being the same as the DOI once the prefix is added.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 22 '10 at 20:55

























    answered Nov 22 '10 at 20:17









    Joseph WrightJoseph Wright

    206k23566895




    206k23566895












    • Marvellous, works a charm! The one change I had to make (noting it in case others have the same issue): I had to excise the “addpubmedresolver” block, since my .bst file wasn’t set up to do pubmed data.

      – Peter LeFanu Lumsdaine
      Nov 27 '10 at 0:10











    • p.s. this has now given me the courage to start playing around with the .bst file myself for the first time, finding that (a) making minor tweaks is not as impossibly arcane as it had previously seemed, but (b) my goodness, it’s a strange language!

      – Peter LeFanu Lumsdaine
      Nov 27 '10 at 0:33

















    • Marvellous, works a charm! The one change I had to make (noting it in case others have the same issue): I had to excise the “addpubmedresolver” block, since my .bst file wasn’t set up to do pubmed data.

      – Peter LeFanu Lumsdaine
      Nov 27 '10 at 0:10











    • p.s. this has now given me the courage to start playing around with the .bst file myself for the first time, finding that (a) making minor tweaks is not as impossibly arcane as it had previously seemed, but (b) my goodness, it’s a strange language!

      – Peter LeFanu Lumsdaine
      Nov 27 '10 at 0:33
















    Marvellous, works a charm! The one change I had to make (noting it in case others have the same issue): I had to excise the “addpubmedresolver” block, since my .bst file wasn’t set up to do pubmed data.

    – Peter LeFanu Lumsdaine
    Nov 27 '10 at 0:10





    Marvellous, works a charm! The one change I had to make (noting it in case others have the same issue): I had to excise the “addpubmedresolver” block, since my .bst file wasn’t set up to do pubmed data.

    – Peter LeFanu Lumsdaine
    Nov 27 '10 at 0:10













    p.s. this has now given me the courage to start playing around with the .bst file myself for the first time, finding that (a) making minor tweaks is not as impossibly arcane as it had previously seemed, but (b) my goodness, it’s a strange language!

    – Peter LeFanu Lumsdaine
    Nov 27 '10 at 0:33





    p.s. this has now given me the courage to start playing around with the .bst file myself for the first time, finding that (a) making minor tweaks is not as impossibly arcane as it had previously seemed, but (b) my goodness, it’s a strange language!

    – Peter LeFanu Lumsdaine
    Nov 27 '10 at 0:33











    20














    The original question is about a standard BibTeX style, but inspired by lockstep I've worked out a biblatex solution as a complement to my other answer. The method here is to add the appropriate prefix to the raw DOI, then test this for equivalence to the URL. The prefix needs to be processed with detokenize as this is how the URL field is formatted.



    documentclassarticle

    usepackagebiblatex

    renewbibmacro*doi+eprint+url%
    iftogglebbx:doi
    %
    iffieldundefdoi

    %
    begingroup
    edefURLorDOI%
    detokenizehttp://dx.doi.org/%
    thefielddoi%
    %
    iffieldequalsurlURLorDOI
    endgroup
    %
    endgroup
    printfielddoi%
    %
    %

    %
    newunitnewblock
    iftogglebbx:eprint
    usebibmacroeprint
    %
    newunitnewblock
    iftogglebbx:url
    usebibmacrourl+urldate


    usepackagefilecontents

    beginfilecontentsjobname.bib
    @miscA01,
    author = Author, A.,
    year = 2001,
    title = Alpha,
    doi = 10.1016/j.apal.2008.12.003,


    @miscB02,
    author = Buthor, B.,
    year = 2002,
    title = Bravo,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,


    @miscC03,
    author = Cuthor, C.,
    year = 2003,
    title = Charlie,
    doi = 10.1016/j.apal.2008.12.003,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,

    endfilecontents

    bibliographyjobname

    begindocument

    nocite*

    printbibliography

    enddocument





    share|improve this answer

























    • +1 - This is much better than my attempt. However, shouldn't there be a makeatletter-makeatother combo? (And if not, why not?)

      – lockstep
      Nov 22 '10 at 20:48






    • 1





      @lockstep. No, I didn't need makeatletter as csname will always construct a control sequence name, even with non-letter tokens (although some may need string, for example active tokens). However, I realised that biblatex provides thefield, which avoids the need to access the internal macro at all.

      – Joseph Wright
      Nov 22 '10 at 20:52












    • Just to explain the begingroup ... endgroup in the above, I'm keeping URLorDOI local here, so outside of my test it does not exist. This is a good idea in many cases: it would allow me to use an otherwise taken macro name, for example.

      – Joseph Wright
      Nov 22 '10 at 20:54











    • @lockstep, @Joseph: thanks very much, these look marvellous! I’ll accept one as soon as I’ve tried them out/got them working :-)

      – Peter LeFanu Lumsdaine
      Nov 26 '10 at 22:12















    20














    The original question is about a standard BibTeX style, but inspired by lockstep I've worked out a biblatex solution as a complement to my other answer. The method here is to add the appropriate prefix to the raw DOI, then test this for equivalence to the URL. The prefix needs to be processed with detokenize as this is how the URL field is formatted.



    documentclassarticle

    usepackagebiblatex

    renewbibmacro*doi+eprint+url%
    iftogglebbx:doi
    %
    iffieldundefdoi

    %
    begingroup
    edefURLorDOI%
    detokenizehttp://dx.doi.org/%
    thefielddoi%
    %
    iffieldequalsurlURLorDOI
    endgroup
    %
    endgroup
    printfielddoi%
    %
    %

    %
    newunitnewblock
    iftogglebbx:eprint
    usebibmacroeprint
    %
    newunitnewblock
    iftogglebbx:url
    usebibmacrourl+urldate


    usepackagefilecontents

    beginfilecontentsjobname.bib
    @miscA01,
    author = Author, A.,
    year = 2001,
    title = Alpha,
    doi = 10.1016/j.apal.2008.12.003,


    @miscB02,
    author = Buthor, B.,
    year = 2002,
    title = Bravo,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,


    @miscC03,
    author = Cuthor, C.,
    year = 2003,
    title = Charlie,
    doi = 10.1016/j.apal.2008.12.003,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,

    endfilecontents

    bibliographyjobname

    begindocument

    nocite*

    printbibliography

    enddocument





    share|improve this answer

























    • +1 - This is much better than my attempt. However, shouldn't there be a makeatletter-makeatother combo? (And if not, why not?)

      – lockstep
      Nov 22 '10 at 20:48






    • 1





      @lockstep. No, I didn't need makeatletter as csname will always construct a control sequence name, even with non-letter tokens (although some may need string, for example active tokens). However, I realised that biblatex provides thefield, which avoids the need to access the internal macro at all.

      – Joseph Wright
      Nov 22 '10 at 20:52












    • Just to explain the begingroup ... endgroup in the above, I'm keeping URLorDOI local here, so outside of my test it does not exist. This is a good idea in many cases: it would allow me to use an otherwise taken macro name, for example.

      – Joseph Wright
      Nov 22 '10 at 20:54











    • @lockstep, @Joseph: thanks very much, these look marvellous! I’ll accept one as soon as I’ve tried them out/got them working :-)

      – Peter LeFanu Lumsdaine
      Nov 26 '10 at 22:12













    20












    20








    20







    The original question is about a standard BibTeX style, but inspired by lockstep I've worked out a biblatex solution as a complement to my other answer. The method here is to add the appropriate prefix to the raw DOI, then test this for equivalence to the URL. The prefix needs to be processed with detokenize as this is how the URL field is formatted.



    documentclassarticle

    usepackagebiblatex

    renewbibmacro*doi+eprint+url%
    iftogglebbx:doi
    %
    iffieldundefdoi

    %
    begingroup
    edefURLorDOI%
    detokenizehttp://dx.doi.org/%
    thefielddoi%
    %
    iffieldequalsurlURLorDOI
    endgroup
    %
    endgroup
    printfielddoi%
    %
    %

    %
    newunitnewblock
    iftogglebbx:eprint
    usebibmacroeprint
    %
    newunitnewblock
    iftogglebbx:url
    usebibmacrourl+urldate


    usepackagefilecontents

    beginfilecontentsjobname.bib
    @miscA01,
    author = Author, A.,
    year = 2001,
    title = Alpha,
    doi = 10.1016/j.apal.2008.12.003,


    @miscB02,
    author = Buthor, B.,
    year = 2002,
    title = Bravo,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,


    @miscC03,
    author = Cuthor, C.,
    year = 2003,
    title = Charlie,
    doi = 10.1016/j.apal.2008.12.003,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,

    endfilecontents

    bibliographyjobname

    begindocument

    nocite*

    printbibliography

    enddocument





    share|improve this answer















    The original question is about a standard BibTeX style, but inspired by lockstep I've worked out a biblatex solution as a complement to my other answer. The method here is to add the appropriate prefix to the raw DOI, then test this for equivalence to the URL. The prefix needs to be processed with detokenize as this is how the URL field is formatted.



    documentclassarticle

    usepackagebiblatex

    renewbibmacro*doi+eprint+url%
    iftogglebbx:doi
    %
    iffieldundefdoi

    %
    begingroup
    edefURLorDOI%
    detokenizehttp://dx.doi.org/%
    thefielddoi%
    %
    iffieldequalsurlURLorDOI
    endgroup
    %
    endgroup
    printfielddoi%
    %
    %

    %
    newunitnewblock
    iftogglebbx:eprint
    usebibmacroeprint
    %
    newunitnewblock
    iftogglebbx:url
    usebibmacrourl+urldate


    usepackagefilecontents

    beginfilecontentsjobname.bib
    @miscA01,
    author = Author, A.,
    year = 2001,
    title = Alpha,
    doi = 10.1016/j.apal.2008.12.003,


    @miscB02,
    author = Buthor, B.,
    year = 2002,
    title = Bravo,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,


    @miscC03,
    author = Cuthor, C.,
    year = 2003,
    title = Charlie,
    doi = 10.1016/j.apal.2008.12.003,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,

    endfilecontents

    bibliographyjobname

    begindocument

    nocite*

    printbibliography

    enddocument






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 22 '10 at 20:51

























    answered Nov 22 '10 at 20:41









    Joseph WrightJoseph Wright

    206k23566895




    206k23566895












    • +1 - This is much better than my attempt. However, shouldn't there be a makeatletter-makeatother combo? (And if not, why not?)

      – lockstep
      Nov 22 '10 at 20:48






    • 1





      @lockstep. No, I didn't need makeatletter as csname will always construct a control sequence name, even with non-letter tokens (although some may need string, for example active tokens). However, I realised that biblatex provides thefield, which avoids the need to access the internal macro at all.

      – Joseph Wright
      Nov 22 '10 at 20:52












    • Just to explain the begingroup ... endgroup in the above, I'm keeping URLorDOI local here, so outside of my test it does not exist. This is a good idea in many cases: it would allow me to use an otherwise taken macro name, for example.

      – Joseph Wright
      Nov 22 '10 at 20:54











    • @lockstep, @Joseph: thanks very much, these look marvellous! I’ll accept one as soon as I’ve tried them out/got them working :-)

      – Peter LeFanu Lumsdaine
      Nov 26 '10 at 22:12

















    • +1 - This is much better than my attempt. However, shouldn't there be a makeatletter-makeatother combo? (And if not, why not?)

      – lockstep
      Nov 22 '10 at 20:48






    • 1





      @lockstep. No, I didn't need makeatletter as csname will always construct a control sequence name, even with non-letter tokens (although some may need string, for example active tokens). However, I realised that biblatex provides thefield, which avoids the need to access the internal macro at all.

      – Joseph Wright
      Nov 22 '10 at 20:52












    • Just to explain the begingroup ... endgroup in the above, I'm keeping URLorDOI local here, so outside of my test it does not exist. This is a good idea in many cases: it would allow me to use an otherwise taken macro name, for example.

      – Joseph Wright
      Nov 22 '10 at 20:54











    • @lockstep, @Joseph: thanks very much, these look marvellous! I’ll accept one as soon as I’ve tried them out/got them working :-)

      – Peter LeFanu Lumsdaine
      Nov 26 '10 at 22:12
















    +1 - This is much better than my attempt. However, shouldn't there be a makeatletter-makeatother combo? (And if not, why not?)

    – lockstep
    Nov 22 '10 at 20:48





    +1 - This is much better than my attempt. However, shouldn't there be a makeatletter-makeatother combo? (And if not, why not?)

    – lockstep
    Nov 22 '10 at 20:48




    1




    1





    @lockstep. No, I didn't need makeatletter as csname will always construct a control sequence name, even with non-letter tokens (although some may need string, for example active tokens). However, I realised that biblatex provides thefield, which avoids the need to access the internal macro at all.

    – Joseph Wright
    Nov 22 '10 at 20:52






    @lockstep. No, I didn't need makeatletter as csname will always construct a control sequence name, even with non-letter tokens (although some may need string, for example active tokens). However, I realised that biblatex provides thefield, which avoids the need to access the internal macro at all.

    – Joseph Wright
    Nov 22 '10 at 20:52














    Just to explain the begingroup ... endgroup in the above, I'm keeping URLorDOI local here, so outside of my test it does not exist. This is a good idea in many cases: it would allow me to use an otherwise taken macro name, for example.

    – Joseph Wright
    Nov 22 '10 at 20:54





    Just to explain the begingroup ... endgroup in the above, I'm keeping URLorDOI local here, so outside of my test it does not exist. This is a good idea in many cases: it would allow me to use an otherwise taken macro name, for example.

    – Joseph Wright
    Nov 22 '10 at 20:54













    @lockstep, @Joseph: thanks very much, these look marvellous! I’ll accept one as soon as I’ve tried them out/got them working :-)

    – Peter LeFanu Lumsdaine
    Nov 26 '10 at 22:12





    @lockstep, @Joseph: thanks very much, these look marvellous! I’ll accept one as soon as I’ve tried them out/got them working :-)

    – Peter LeFanu Lumsdaine
    Nov 26 '10 at 22:12











    13














    I didn't manage to test for "sort-of-identical" doi und url fields, but here's a solution using biblatex - url and urldate fields will only be typeset if the respective entry doesn't include a doi field.



    documentclassarticle

    usepackagebiblatex

    DeclareFieldFormaturl%
    iffieldundefdoi%
    mkbibacroURLaddcolonspaceurl#1%
    %
    %


    DeclareFieldFormaturldate%
    iffieldundefdoi%
    mkbibparensbibstringurlseenspace#1%
    %
    %


    usepackagefilecontents

    beginfilecontentsjobname.bib
    @miscA01,
    author = Author, A.,
    year = 2001,
    title = Alpha,
    doi = 10.1016/j.apal.2008.12.003,


    @miscB02,
    author = Buthor, B.,
    year = 2002,
    title = Bravo,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,


    @miscC03,
    author = Cuthor, C.,
    year = 2003,
    title = Charlie,
    doi = 10.1016/j.apal.2008.12.003,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,

    endfilecontents

    bibliographyjobname

    begindocument

    nocite*

    printbibliography

    enddocument





    share|improve this answer


















    • 1





      This was superbly useful - thank you. I only wish I could find stuff like this by searching the site rather than having to half-write questions first! I have just extended this to print the url iff neither doi nor eprinttype is defined. Seems to work for my simple test case...

      – cfr
      Sep 27 '14 at 0:25















    13














    I didn't manage to test for "sort-of-identical" doi und url fields, but here's a solution using biblatex - url and urldate fields will only be typeset if the respective entry doesn't include a doi field.



    documentclassarticle

    usepackagebiblatex

    DeclareFieldFormaturl%
    iffieldundefdoi%
    mkbibacroURLaddcolonspaceurl#1%
    %
    %


    DeclareFieldFormaturldate%
    iffieldundefdoi%
    mkbibparensbibstringurlseenspace#1%
    %
    %


    usepackagefilecontents

    beginfilecontentsjobname.bib
    @miscA01,
    author = Author, A.,
    year = 2001,
    title = Alpha,
    doi = 10.1016/j.apal.2008.12.003,


    @miscB02,
    author = Buthor, B.,
    year = 2002,
    title = Bravo,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,


    @miscC03,
    author = Cuthor, C.,
    year = 2003,
    title = Charlie,
    doi = 10.1016/j.apal.2008.12.003,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,

    endfilecontents

    bibliographyjobname

    begindocument

    nocite*

    printbibliography

    enddocument





    share|improve this answer


















    • 1





      This was superbly useful - thank you. I only wish I could find stuff like this by searching the site rather than having to half-write questions first! I have just extended this to print the url iff neither doi nor eprinttype is defined. Seems to work for my simple test case...

      – cfr
      Sep 27 '14 at 0:25













    13












    13








    13







    I didn't manage to test for "sort-of-identical" doi und url fields, but here's a solution using biblatex - url and urldate fields will only be typeset if the respective entry doesn't include a doi field.



    documentclassarticle

    usepackagebiblatex

    DeclareFieldFormaturl%
    iffieldundefdoi%
    mkbibacroURLaddcolonspaceurl#1%
    %
    %


    DeclareFieldFormaturldate%
    iffieldundefdoi%
    mkbibparensbibstringurlseenspace#1%
    %
    %


    usepackagefilecontents

    beginfilecontentsjobname.bib
    @miscA01,
    author = Author, A.,
    year = 2001,
    title = Alpha,
    doi = 10.1016/j.apal.2008.12.003,


    @miscB02,
    author = Buthor, B.,
    year = 2002,
    title = Bravo,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,


    @miscC03,
    author = Cuthor, C.,
    year = 2003,
    title = Charlie,
    doi = 10.1016/j.apal.2008.12.003,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,

    endfilecontents

    bibliographyjobname

    begindocument

    nocite*

    printbibliography

    enddocument





    share|improve this answer













    I didn't manage to test for "sort-of-identical" doi und url fields, but here's a solution using biblatex - url and urldate fields will only be typeset if the respective entry doesn't include a doi field.



    documentclassarticle

    usepackagebiblatex

    DeclareFieldFormaturl%
    iffieldundefdoi%
    mkbibacroURLaddcolonspaceurl#1%
    %
    %


    DeclareFieldFormaturldate%
    iffieldundefdoi%
    mkbibparensbibstringurlseenspace#1%
    %
    %


    usepackagefilecontents

    beginfilecontentsjobname.bib
    @miscA01,
    author = Author, A.,
    year = 2001,
    title = Alpha,
    doi = 10.1016/j.apal.2008.12.003,


    @miscB02,
    author = Buthor, B.,
    year = 2002,
    title = Bravo,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,


    @miscC03,
    author = Cuthor, C.,
    year = 2003,
    title = Charlie,
    doi = 10.1016/j.apal.2008.12.003,
    url = http://dx.doi.org/10.1016/j.apal.2008.12.003,
    urldate = 2010-11-22,

    endfilecontents

    bibliographyjobname

    begindocument

    nocite*

    printbibliography

    enddocument






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 22 '10 at 17:05









    locksteplockstep

    193k53594723




    193k53594723







    • 1





      This was superbly useful - thank you. I only wish I could find stuff like this by searching the site rather than having to half-write questions first! I have just extended this to print the url iff neither doi nor eprinttype is defined. Seems to work for my simple test case...

      – cfr
      Sep 27 '14 at 0:25












    • 1





      This was superbly useful - thank you. I only wish I could find stuff like this by searching the site rather than having to half-write questions first! I have just extended this to print the url iff neither doi nor eprinttype is defined. Seems to work for my simple test case...

      – cfr
      Sep 27 '14 at 0:25







    1




    1





    This was superbly useful - thank you. I only wish I could find stuff like this by searching the site rather than having to half-write questions first! I have just extended this to print the url iff neither doi nor eprinttype is defined. Seems to work for my simple test case...

    – cfr
    Sep 27 '14 at 0:25





    This was superbly useful - thank you. I only wish I could find stuff like this by searching the site rather than having to half-write questions first! I have just extended this to print the url iff neither doi nor eprinttype is defined. Seems to work for my simple test case...

    – cfr
    Sep 27 '14 at 0:25











    6














    This is really a comment to Joseph Wright's answer above, but with included code.



    I only just now stumbled across this answer (I'm the author of urlbst).



    This is great, Joseph -- thanks. I've incorporated something rather like this into the urlbst repository at https://bitbucket.org/nxg/urlbst, and this should appear in the next release of urlbst (whenever that is).



    FUNCTION output.web.refs

    new.block
    inlinelinks
    'skip$ % links were inline -- don't repeat them
    % If the generated DOI will be the same as the URL,
    % then don't print the URL (thanks to Joseph Wright for this code,
    % at http://tex.stackexchange.com/questions/5660)
    adddoiresolver
    doiurl doi empty$ "X" doi if$ * % DOI URL to be generated
    url empty$ "Y" url if$ % the URL, or "Y" if empty
    = % are the strings equal?
    and
    'skip$
    output.url
    if$
    addeprints eprint empty$ not and
    format.eprint output.nonnull
    'skip$
    if$
    adddoiresolver doi empty$ not and
    format.doi output.nonnull
    'skip$
    if$
    addpubmedresolver pubmed empty$ not and
    format.pubmed output.nonnull
    'skip$
    if$

    if$



    The difference is that this avoids printing the URL if it would equal the DOI, rather than the other way round, and also checks if either or both is empty.



    For what it's worth, my response to the initial problem would be to delete the semi-redundant URL field in the .bib file. I would only have both if the URL gave an alternative (possibly openly available) version of the reference.






    share|improve this answer























    • Norman, it there a way to only print isbn/issn if there is no url/doi in BibTeX? Something like this: tex.stackexchange.com/questions/76534/…

      – TobiasDK
      Jun 4 '15 at 17:59











    • Not in urlbst, but if you're willing to edit your .bst file, then something like isbn url empty$ doi empty$ and and format.isbn output.nonnull format.url output.nonnull format.doi output.nonnull if$ would (I think; not tested) call the format.isbn function only if url and doi were empty, and call format.url and format.doi if either is non-empty. The .bst file would have to define functions format.isbn and and. Does that point the way to the logic you need?

      – Norman Gray
      Jun 4 '15 at 21:41












    • Thank you for the answer and I have tried using your ideas, but its not easy to figure out.. I have posted a new question to deal with my problem. Maybe you have time to look at it: [tex.stackexchange.com/questions/248732/…. Thanks in advance.

      – TobiasDK
      Jun 5 '15 at 9:47















    6














    This is really a comment to Joseph Wright's answer above, but with included code.



    I only just now stumbled across this answer (I'm the author of urlbst).



    This is great, Joseph -- thanks. I've incorporated something rather like this into the urlbst repository at https://bitbucket.org/nxg/urlbst, and this should appear in the next release of urlbst (whenever that is).



    FUNCTION output.web.refs

    new.block
    inlinelinks
    'skip$ % links were inline -- don't repeat them
    % If the generated DOI will be the same as the URL,
    % then don't print the URL (thanks to Joseph Wright for this code,
    % at http://tex.stackexchange.com/questions/5660)
    adddoiresolver
    doiurl doi empty$ "X" doi if$ * % DOI URL to be generated
    url empty$ "Y" url if$ % the URL, or "Y" if empty
    = % are the strings equal?
    and
    'skip$
    output.url
    if$
    addeprints eprint empty$ not and
    format.eprint output.nonnull
    'skip$
    if$
    adddoiresolver doi empty$ not and
    format.doi output.nonnull
    'skip$
    if$
    addpubmedresolver pubmed empty$ not and
    format.pubmed output.nonnull
    'skip$
    if$

    if$



    The difference is that this avoids printing the URL if it would equal the DOI, rather than the other way round, and also checks if either or both is empty.



    For what it's worth, my response to the initial problem would be to delete the semi-redundant URL field in the .bib file. I would only have both if the URL gave an alternative (possibly openly available) version of the reference.






    share|improve this answer























    • Norman, it there a way to only print isbn/issn if there is no url/doi in BibTeX? Something like this: tex.stackexchange.com/questions/76534/…

      – TobiasDK
      Jun 4 '15 at 17:59











    • Not in urlbst, but if you're willing to edit your .bst file, then something like isbn url empty$ doi empty$ and and format.isbn output.nonnull format.url output.nonnull format.doi output.nonnull if$ would (I think; not tested) call the format.isbn function only if url and doi were empty, and call format.url and format.doi if either is non-empty. The .bst file would have to define functions format.isbn and and. Does that point the way to the logic you need?

      – Norman Gray
      Jun 4 '15 at 21:41












    • Thank you for the answer and I have tried using your ideas, but its not easy to figure out.. I have posted a new question to deal with my problem. Maybe you have time to look at it: [tex.stackexchange.com/questions/248732/…. Thanks in advance.

      – TobiasDK
      Jun 5 '15 at 9:47













    6












    6








    6







    This is really a comment to Joseph Wright's answer above, but with included code.



    I only just now stumbled across this answer (I'm the author of urlbst).



    This is great, Joseph -- thanks. I've incorporated something rather like this into the urlbst repository at https://bitbucket.org/nxg/urlbst, and this should appear in the next release of urlbst (whenever that is).



    FUNCTION output.web.refs

    new.block
    inlinelinks
    'skip$ % links were inline -- don't repeat them
    % If the generated DOI will be the same as the URL,
    % then don't print the URL (thanks to Joseph Wright for this code,
    % at http://tex.stackexchange.com/questions/5660)
    adddoiresolver
    doiurl doi empty$ "X" doi if$ * % DOI URL to be generated
    url empty$ "Y" url if$ % the URL, or "Y" if empty
    = % are the strings equal?
    and
    'skip$
    output.url
    if$
    addeprints eprint empty$ not and
    format.eprint output.nonnull
    'skip$
    if$
    adddoiresolver doi empty$ not and
    format.doi output.nonnull
    'skip$
    if$
    addpubmedresolver pubmed empty$ not and
    format.pubmed output.nonnull
    'skip$
    if$

    if$



    The difference is that this avoids printing the URL if it would equal the DOI, rather than the other way round, and also checks if either or both is empty.



    For what it's worth, my response to the initial problem would be to delete the semi-redundant URL field in the .bib file. I would only have both if the URL gave an alternative (possibly openly available) version of the reference.






    share|improve this answer













    This is really a comment to Joseph Wright's answer above, but with included code.



    I only just now stumbled across this answer (I'm the author of urlbst).



    This is great, Joseph -- thanks. I've incorporated something rather like this into the urlbst repository at https://bitbucket.org/nxg/urlbst, and this should appear in the next release of urlbst (whenever that is).



    FUNCTION output.web.refs

    new.block
    inlinelinks
    'skip$ % links were inline -- don't repeat them
    % If the generated DOI will be the same as the URL,
    % then don't print the URL (thanks to Joseph Wright for this code,
    % at http://tex.stackexchange.com/questions/5660)
    adddoiresolver
    doiurl doi empty$ "X" doi if$ * % DOI URL to be generated
    url empty$ "Y" url if$ % the URL, or "Y" if empty
    = % are the strings equal?
    and
    'skip$
    output.url
    if$
    addeprints eprint empty$ not and
    format.eprint output.nonnull
    'skip$
    if$
    adddoiresolver doi empty$ not and
    format.doi output.nonnull
    'skip$
    if$
    addpubmedresolver pubmed empty$ not and
    format.pubmed output.nonnull
    'skip$
    if$

    if$



    The difference is that this avoids printing the URL if it would equal the DOI, rather than the other way round, and also checks if either or both is empty.



    For what it's worth, my response to the initial problem would be to delete the semi-redundant URL field in the .bib file. I would only have both if the URL gave an alternative (possibly openly available) version of the reference.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 25 '12 at 20:21









    Norman GrayNorman Gray

    5,65111929




    5,65111929












    • Norman, it there a way to only print isbn/issn if there is no url/doi in BibTeX? Something like this: tex.stackexchange.com/questions/76534/…

      – TobiasDK
      Jun 4 '15 at 17:59











    • Not in urlbst, but if you're willing to edit your .bst file, then something like isbn url empty$ doi empty$ and and format.isbn output.nonnull format.url output.nonnull format.doi output.nonnull if$ would (I think; not tested) call the format.isbn function only if url and doi were empty, and call format.url and format.doi if either is non-empty. The .bst file would have to define functions format.isbn and and. Does that point the way to the logic you need?

      – Norman Gray
      Jun 4 '15 at 21:41












    • Thank you for the answer and I have tried using your ideas, but its not easy to figure out.. I have posted a new question to deal with my problem. Maybe you have time to look at it: [tex.stackexchange.com/questions/248732/…. Thanks in advance.

      – TobiasDK
      Jun 5 '15 at 9:47

















    • Norman, it there a way to only print isbn/issn if there is no url/doi in BibTeX? Something like this: tex.stackexchange.com/questions/76534/…

      – TobiasDK
      Jun 4 '15 at 17:59











    • Not in urlbst, but if you're willing to edit your .bst file, then something like isbn url empty$ doi empty$ and and format.isbn output.nonnull format.url output.nonnull format.doi output.nonnull if$ would (I think; not tested) call the format.isbn function only if url and doi were empty, and call format.url and format.doi if either is non-empty. The .bst file would have to define functions format.isbn and and. Does that point the way to the logic you need?

      – Norman Gray
      Jun 4 '15 at 21:41












    • Thank you for the answer and I have tried using your ideas, but its not easy to figure out.. I have posted a new question to deal with my problem. Maybe you have time to look at it: [tex.stackexchange.com/questions/248732/…. Thanks in advance.

      – TobiasDK
      Jun 5 '15 at 9:47
















    Norman, it there a way to only print isbn/issn if there is no url/doi in BibTeX? Something like this: tex.stackexchange.com/questions/76534/…

    – TobiasDK
    Jun 4 '15 at 17:59





    Norman, it there a way to only print isbn/issn if there is no url/doi in BibTeX? Something like this: tex.stackexchange.com/questions/76534/…

    – TobiasDK
    Jun 4 '15 at 17:59













    Not in urlbst, but if you're willing to edit your .bst file, then something like isbn url empty$ doi empty$ and and format.isbn output.nonnull format.url output.nonnull format.doi output.nonnull if$ would (I think; not tested) call the format.isbn function only if url and doi were empty, and call format.url and format.doi if either is non-empty. The .bst file would have to define functions format.isbn and and. Does that point the way to the logic you need?

    – Norman Gray
    Jun 4 '15 at 21:41






    Not in urlbst, but if you're willing to edit your .bst file, then something like isbn url empty$ doi empty$ and and format.isbn output.nonnull format.url output.nonnull format.doi output.nonnull if$ would (I think; not tested) call the format.isbn function only if url and doi were empty, and call format.url and format.doi if either is non-empty. The .bst file would have to define functions format.isbn and and. Does that point the way to the logic you need?

    – Norman Gray
    Jun 4 '15 at 21:41














    Thank you for the answer and I have tried using your ideas, but its not easy to figure out.. I have posted a new question to deal with my problem. Maybe you have time to look at it: [tex.stackexchange.com/questions/248732/…. Thanks in advance.

    – TobiasDK
    Jun 5 '15 at 9:47





    Thank you for the answer and I have tried using your ideas, but its not easy to figure out.. I have posted a new question to deal with my problem. Maybe you have time to look at it: [tex.stackexchange.com/questions/248732/…. Thanks in advance.

    – TobiasDK
    Jun 5 '15 at 9:47











    1














    A quick solution, without BST manipulation, can be a sed script that deletes the URL field if followed by a DOI field, or similar. Worked for me; I have a bib library of dblp bib entries from which I extract the relevant ones with bibtool, and then delete the spurious URL fields with sed.



    Here is my sed script, acknowledging https://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string for the magic incantation.



    # First, a magic incantation to turn sed from a line-based editor
    # to an editor on the whole input.

    1h;2,$H;$!d;g

    # Then, the actual command, replacing url=A,doi=B by doi=B

    s/s*urls*=s*[^]*},(s*dois*=s*[^]*})/1/g

    # Note that s matches a whitespace character (including n).





    share|improve this answer


















    • 1





      Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.

      – Martin Schröder
      Apr 17 '17 at 13:42















    1














    A quick solution, without BST manipulation, can be a sed script that deletes the URL field if followed by a DOI field, or similar. Worked for me; I have a bib library of dblp bib entries from which I extract the relevant ones with bibtool, and then delete the spurious URL fields with sed.



    Here is my sed script, acknowledging https://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string for the magic incantation.



    # First, a magic incantation to turn sed from a line-based editor
    # to an editor on the whole input.

    1h;2,$H;$!d;g

    # Then, the actual command, replacing url=A,doi=B by doi=B

    s/s*urls*=s*[^]*},(s*dois*=s*[^]*})/1/g

    # Note that s matches a whitespace character (including n).





    share|improve this answer


















    • 1





      Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.

      – Martin Schröder
      Apr 17 '17 at 13:42













    1












    1








    1







    A quick solution, without BST manipulation, can be a sed script that deletes the URL field if followed by a DOI field, or similar. Worked for me; I have a bib library of dblp bib entries from which I extract the relevant ones with bibtool, and then delete the spurious URL fields with sed.



    Here is my sed script, acknowledging https://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string for the magic incantation.



    # First, a magic incantation to turn sed from a line-based editor
    # to an editor on the whole input.

    1h;2,$H;$!d;g

    # Then, the actual command, replacing url=A,doi=B by doi=B

    s/s*urls*=s*[^]*},(s*dois*=s*[^]*})/1/g

    # Note that s matches a whitespace character (including n).





    share|improve this answer













    A quick solution, without BST manipulation, can be a sed script that deletes the URL field if followed by a DOI field, or similar. Worked for me; I have a bib library of dblp bib entries from which I extract the relevant ones with bibtool, and then delete the spurious URL fields with sed.



    Here is my sed script, acknowledging https://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string for the magic incantation.



    # First, a magic incantation to turn sed from a line-based editor
    # to an editor on the whole input.

    1h;2,$H;$!d;g

    # Then, the actual command, replacing url=A,doi=B by doi=B

    s/s*urls*=s*[^]*},(s*dois*=s*[^]*})/1/g

    # Note that s matches a whitespace character (including n).






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 17 '17 at 13:36









    andreas.abelandreas.abel

    111




    111







    • 1





      Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.

      – Martin Schröder
      Apr 17 '17 at 13:42












    • 1





      Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.

      – Martin Schröder
      Apr 17 '17 at 13:42







    1




    1





    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.

    – Martin Schröder
    Apr 17 '17 at 13:42





    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.

    – Martin Schröder
    Apr 17 '17 at 13:42











    0














    When using BibLaTeX, this can be very easily done on the data level, without fuddling with output templates or even changing the .bib file.



    Just use the iffieldundeffield nameundefined casedefined case macro:



    AtEveryBibitem
    iffieldundefurlclearfielddoi



    Note that this doesn't do the if DOI and URL are the same test as suggested by the OP, but just the simpler only show DOI when there's no URL case as some of the other answers.





    share



























      0














      When using BibLaTeX, this can be very easily done on the data level, without fuddling with output templates or even changing the .bib file.



      Just use the iffieldundeffield nameundefined casedefined case macro:



      AtEveryBibitem
      iffieldundefurlclearfielddoi



      Note that this doesn't do the if DOI and URL are the same test as suggested by the OP, but just the simpler only show DOI when there's no URL case as some of the other answers.





      share

























        0












        0








        0







        When using BibLaTeX, this can be very easily done on the data level, without fuddling with output templates or even changing the .bib file.



        Just use the iffieldundeffield nameundefined casedefined case macro:



        AtEveryBibitem
        iffieldundefurlclearfielddoi



        Note that this doesn't do the if DOI and URL are the same test as suggested by the OP, but just the simpler only show DOI when there's no URL case as some of the other answers.





        share













        When using BibLaTeX, this can be very easily done on the data level, without fuddling with output templates or even changing the .bib file.



        Just use the iffieldundeffield nameundefined casedefined case macro:



        AtEveryBibitem
        iffieldundefurlclearfielddoi



        Note that this doesn't do the if DOI and URL are the same test as suggested by the OP, but just the simpler only show DOI when there's no URL case as some of the other answers.






        share











        share


        share










        answered 1 min ago









        MarianMarian

        1818




        1818



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f5660%2fredundancy-in-bib-file-conditionally-suppress-url-if-same-as-doi%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Isabella Eugénie Boyer Biographie | Références | Menu de navigationmodifiermodifier le codeComparator to Compute the Relative Value of a U.S. Dollar Amount – 1774 to Present.

            Join wedge with single bond in chemfigHow to make only one part of double bond bold with chemfig?Crossing bonds in chemfigjoining atoms in chemfig. Two adjacent molculesHow do I selectively change bond length in chemfig?Ugly bond joints in chemfigchemfig: reaction above arrowUsing the mhchem and chemfig packages in conjunctionBonding to specific element letter using chemfigResonance hybrids in chemfigScale chemfig molecule in beamer with tikzWhy does this chemfig bond with a hook start in the middle of the atom?

            Are small insurances worth itIs insurance worth it if you can afford to replace the item? If not, when is it?Is accident insurance worth it for my kids who play sportsIs insuring property for more than it is worth allowed?At what point does it become worth it to file an insurance claim?Are wage loss insurance programs worth the cost compared to having an emergency fund?When is an event worth insuring against?Is insurance worth it if you can afford to replace the item? If not, when is it?FHA loan just commenced : Any way to get any of the up-front mortgage insurance back?Which types of insurances do I need to buy?Should I carry less renter's insurance if I can self-insure?Mortgage Adviser Signed Me Up For Multiple Home and Life Insurances (UK)Why many travel insurances don't cover country of nationality?