Redundancy in bib file: conditionally suppress url if same as doi? Announcing the arrival of...
How can I prevent/balance waiting and turtling as a response to cooldown mechanics
What is the difference between CTSS and ITS?
Sally's older brother
Is openssl rand command cryptographically secure?
Trying to understand entropy as a novice in thermodynamics
I can't produce songs
New Order #6: Easter Egg
What to do with repeated rejections for phd position
Universal covering space of the real projective line?
As a dual citizen, my US passport will expire one day after traveling to the US. Will this work?
Can two person see the same photon?
Are the endpoints of the domain of a function counted as critical points?
Resize vertical bars (absolute-value symbols)
Select every other edge (they share a common vertex)
Special flights
What does it mean that physics no longer uses mechanical models to describe phenomena?
Did any compiler fully use 80-bit floating point?
Getting out of while loop on console
Would color changing eyes affect vision?
Tips to organize LaTeX presentations for a semester
How can a team of shapeshifters communicate?
Google .dev domain strangely redirects to https
What is the difference between a "ranged attack" and a "ranged weapon attack"?
How would a mousetrap for use in space work?
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
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
urlanddoibut 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
add a comment |
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
urlanddoibut 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
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
add a comment |
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
urlanddoibut 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
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
urlanddoibut 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
bibliographies bibtex conditionals urls doi
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
add a comment |
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
add a comment |
6 Answers
6
active
oldest
votes
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.
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
add a comment |
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.
documentclass{article}
usepackage{biblatex}
renewbibmacro*{doi+eprint+url}{%
iftoggle{bbx:doi}
{%
iffieldundef{doi}
{}
{%
begingroup
edefURLorDOI{%
detokenize{http://dx.doi.org/}%
thefield{doi}%
}%
iffieldequals{url}{URLorDOI}
{endgroup}
{%
endgroup
printfield{doi}%
}%
}%
}
{}%
newunitnewblock
iftoggle{bbx:eprint}
{usebibmacro{eprint}}
{}%
newunitnewblock
iftoggle{bbx:url}
{usebibmacro{url+urldate}}
{}}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
doi = {10.1016/j.apal.2008.12.003},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
urldate = {2010-11-22},
}
@misc{C03,
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},
}
end{filecontents}
bibliography{jobname}
begin{document}
nocite{*}
printbibliography
end{document}
+1 - This is much better than my attempt. However, shouldn't there be amakeatletter-makeatothercombo? (And if not, why not?)
– lockstep
Nov 22 '10 at 20:48
1
@lockstep. No, I didn't needmakeatletterascsnamewill always construct a control sequence name, even with non-letter tokens (although some may needstring, for example active tokens). However, I realised thatbiblatexprovidesthefield, which avoids the need to access the internal macro at all.
– Joseph Wright♦
Nov 22 '10 at 20:52
Just to explain thebegingroup...endgroupin the above, I'm keepingURLorDOIlocal 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
add a comment |
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.
documentclass{article}
usepackage{biblatex}
DeclareFieldFormat{url}{%
iffieldundef{doi}{%
mkbibacro{URL}addcolonspaceurl{#1}%
}{%
}%
}
DeclareFieldFormat{urldate}{%
iffieldundef{doi}{%
mkbibparens{bibstring{urlseen}space#1}%
}{%
}%
}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
doi = {10.1016/j.apal.2008.12.003},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
urldate = {2010-11-22},
}
@misc{C03,
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},
}
end{filecontents}
bibliography{jobname}
begin{document}
nocite{*}
printbibliography
end{document}
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
add a comment |
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.
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 inurlbst, but if you're willing to edit your.bstfile, then something likeisbn 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 theformat.isbnfunction only ifurlanddoiwere empty, and callformat.urlandformat.doiif either is non-empty. The.bstfile would have to define functionsformat.isbnandand. 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
add a comment |
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).
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
add a comment |
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 iffieldundef{field name}{undefined case}{defined case} macro:
AtEveryBibitem{
iffieldundef{url}{}{clearfield{doi}}
}
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.
But then this doesn't answer the question...
– Phelype Oleinik
9 mins ago
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
edited Nov 22 '10 at 20:55
answered Nov 22 '10 at 20:17
Joseph Wright♦Joseph 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
add a comment |
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
add a comment |
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.
documentclass{article}
usepackage{biblatex}
renewbibmacro*{doi+eprint+url}{%
iftoggle{bbx:doi}
{%
iffieldundef{doi}
{}
{%
begingroup
edefURLorDOI{%
detokenize{http://dx.doi.org/}%
thefield{doi}%
}%
iffieldequals{url}{URLorDOI}
{endgroup}
{%
endgroup
printfield{doi}%
}%
}%
}
{}%
newunitnewblock
iftoggle{bbx:eprint}
{usebibmacro{eprint}}
{}%
newunitnewblock
iftoggle{bbx:url}
{usebibmacro{url+urldate}}
{}}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
doi = {10.1016/j.apal.2008.12.003},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
urldate = {2010-11-22},
}
@misc{C03,
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},
}
end{filecontents}
bibliography{jobname}
begin{document}
nocite{*}
printbibliography
end{document}
+1 - This is much better than my attempt. However, shouldn't there be amakeatletter-makeatothercombo? (And if not, why not?)
– lockstep
Nov 22 '10 at 20:48
1
@lockstep. No, I didn't needmakeatletterascsnamewill always construct a control sequence name, even with non-letter tokens (although some may needstring, for example active tokens). However, I realised thatbiblatexprovidesthefield, which avoids the need to access the internal macro at all.
– Joseph Wright♦
Nov 22 '10 at 20:52
Just to explain thebegingroup...endgroupin the above, I'm keepingURLorDOIlocal 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
add a comment |
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.
documentclass{article}
usepackage{biblatex}
renewbibmacro*{doi+eprint+url}{%
iftoggle{bbx:doi}
{%
iffieldundef{doi}
{}
{%
begingroup
edefURLorDOI{%
detokenize{http://dx.doi.org/}%
thefield{doi}%
}%
iffieldequals{url}{URLorDOI}
{endgroup}
{%
endgroup
printfield{doi}%
}%
}%
}
{}%
newunitnewblock
iftoggle{bbx:eprint}
{usebibmacro{eprint}}
{}%
newunitnewblock
iftoggle{bbx:url}
{usebibmacro{url+urldate}}
{}}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
doi = {10.1016/j.apal.2008.12.003},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
urldate = {2010-11-22},
}
@misc{C03,
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},
}
end{filecontents}
bibliography{jobname}
begin{document}
nocite{*}
printbibliography
end{document}
+1 - This is much better than my attempt. However, shouldn't there be amakeatletter-makeatothercombo? (And if not, why not?)
– lockstep
Nov 22 '10 at 20:48
1
@lockstep. No, I didn't needmakeatletterascsnamewill always construct a control sequence name, even with non-letter tokens (although some may needstring, for example active tokens). However, I realised thatbiblatexprovidesthefield, which avoids the need to access the internal macro at all.
– Joseph Wright♦
Nov 22 '10 at 20:52
Just to explain thebegingroup...endgroupin the above, I'm keepingURLorDOIlocal 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
add a comment |
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.
documentclass{article}
usepackage{biblatex}
renewbibmacro*{doi+eprint+url}{%
iftoggle{bbx:doi}
{%
iffieldundef{doi}
{}
{%
begingroup
edefURLorDOI{%
detokenize{http://dx.doi.org/}%
thefield{doi}%
}%
iffieldequals{url}{URLorDOI}
{endgroup}
{%
endgroup
printfield{doi}%
}%
}%
}
{}%
newunitnewblock
iftoggle{bbx:eprint}
{usebibmacro{eprint}}
{}%
newunitnewblock
iftoggle{bbx:url}
{usebibmacro{url+urldate}}
{}}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
doi = {10.1016/j.apal.2008.12.003},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
urldate = {2010-11-22},
}
@misc{C03,
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},
}
end{filecontents}
bibliography{jobname}
begin{document}
nocite{*}
printbibliography
end{document}
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.
documentclass{article}
usepackage{biblatex}
renewbibmacro*{doi+eprint+url}{%
iftoggle{bbx:doi}
{%
iffieldundef{doi}
{}
{%
begingroup
edefURLorDOI{%
detokenize{http://dx.doi.org/}%
thefield{doi}%
}%
iffieldequals{url}{URLorDOI}
{endgroup}
{%
endgroup
printfield{doi}%
}%
}%
}
{}%
newunitnewblock
iftoggle{bbx:eprint}
{usebibmacro{eprint}}
{}%
newunitnewblock
iftoggle{bbx:url}
{usebibmacro{url+urldate}}
{}}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
doi = {10.1016/j.apal.2008.12.003},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
urldate = {2010-11-22},
}
@misc{C03,
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},
}
end{filecontents}
bibliography{jobname}
begin{document}
nocite{*}
printbibliography
end{document}
edited Nov 22 '10 at 20:51
answered Nov 22 '10 at 20:41
Joseph Wright♦Joseph Wright
206k23566895
206k23566895
+1 - This is much better than my attempt. However, shouldn't there be amakeatletter-makeatothercombo? (And if not, why not?)
– lockstep
Nov 22 '10 at 20:48
1
@lockstep. No, I didn't needmakeatletterascsnamewill always construct a control sequence name, even with non-letter tokens (although some may needstring, for example active tokens). However, I realised thatbiblatexprovidesthefield, which avoids the need to access the internal macro at all.
– Joseph Wright♦
Nov 22 '10 at 20:52
Just to explain thebegingroup...endgroupin the above, I'm keepingURLorDOIlocal 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
add a comment |
+1 - This is much better than my attempt. However, shouldn't there be amakeatletter-makeatothercombo? (And if not, why not?)
– lockstep
Nov 22 '10 at 20:48
1
@lockstep. No, I didn't needmakeatletterascsnamewill always construct a control sequence name, even with non-letter tokens (although some may needstring, for example active tokens). However, I realised thatbiblatexprovidesthefield, which avoids the need to access the internal macro at all.
– Joseph Wright♦
Nov 22 '10 at 20:52
Just to explain thebegingroup...endgroupin the above, I'm keepingURLorDOIlocal 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
add a comment |
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.
documentclass{article}
usepackage{biblatex}
DeclareFieldFormat{url}{%
iffieldundef{doi}{%
mkbibacro{URL}addcolonspaceurl{#1}%
}{%
}%
}
DeclareFieldFormat{urldate}{%
iffieldundef{doi}{%
mkbibparens{bibstring{urlseen}space#1}%
}{%
}%
}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
doi = {10.1016/j.apal.2008.12.003},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
urldate = {2010-11-22},
}
@misc{C03,
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},
}
end{filecontents}
bibliography{jobname}
begin{document}
nocite{*}
printbibliography
end{document}
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
add a comment |
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.
documentclass{article}
usepackage{biblatex}
DeclareFieldFormat{url}{%
iffieldundef{doi}{%
mkbibacro{URL}addcolonspaceurl{#1}%
}{%
}%
}
DeclareFieldFormat{urldate}{%
iffieldundef{doi}{%
mkbibparens{bibstring{urlseen}space#1}%
}{%
}%
}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
doi = {10.1016/j.apal.2008.12.003},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
urldate = {2010-11-22},
}
@misc{C03,
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},
}
end{filecontents}
bibliography{jobname}
begin{document}
nocite{*}
printbibliography
end{document}
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
add a comment |
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.
documentclass{article}
usepackage{biblatex}
DeclareFieldFormat{url}{%
iffieldundef{doi}{%
mkbibacro{URL}addcolonspaceurl{#1}%
}{%
}%
}
DeclareFieldFormat{urldate}{%
iffieldundef{doi}{%
mkbibparens{bibstring{urlseen}space#1}%
}{%
}%
}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
doi = {10.1016/j.apal.2008.12.003},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
urldate = {2010-11-22},
}
@misc{C03,
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},
}
end{filecontents}
bibliography{jobname}
begin{document}
nocite{*}
printbibliography
end{document}
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.
documentclass{article}
usepackage{biblatex}
DeclareFieldFormat{url}{%
iffieldundef{doi}{%
mkbibacro{URL}addcolonspaceurl{#1}%
}{%
}%
}
DeclareFieldFormat{urldate}{%
iffieldundef{doi}{%
mkbibparens{bibstring{urlseen}space#1}%
}{%
}%
}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
doi = {10.1016/j.apal.2008.12.003},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
urldate = {2010-11-22},
}
@misc{C03,
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},
}
end{filecontents}
bibliography{jobname}
begin{document}
nocite{*}
printbibliography
end{document}
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
add a comment |
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
add a comment |
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.
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 inurlbst, but if you're willing to edit your.bstfile, then something likeisbn 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 theformat.isbnfunction only ifurlanddoiwere empty, and callformat.urlandformat.doiif either is non-empty. The.bstfile would have to define functionsformat.isbnandand. 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
add a comment |
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.
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 inurlbst, but if you're willing to edit your.bstfile, then something likeisbn 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 theformat.isbnfunction only ifurlanddoiwere empty, and callformat.urlandformat.doiif either is non-empty. The.bstfile would have to define functionsformat.isbnandand. 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
add a comment |
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.
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.
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 inurlbst, but if you're willing to edit your.bstfile, then something likeisbn 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 theformat.isbnfunction only ifurlanddoiwere empty, and callformat.urlandformat.doiif either is non-empty. The.bstfile would have to define functionsformat.isbnandand. 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
add a comment |
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 inurlbst, but if you're willing to edit your.bstfile, then something likeisbn 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 theformat.isbnfunction only ifurlanddoiwere empty, and callformat.urlandformat.doiif either is non-empty. The.bstfile would have to define functionsformat.isbnandand. 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
add a comment |
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).
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
add a comment |
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).
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
add a comment |
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).
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).
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
add a comment |
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
add a comment |
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 iffieldundef{field name}{undefined case}{defined case} macro:
AtEveryBibitem{
iffieldundef{url}{}{clearfield{doi}}
}
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.
But then this doesn't answer the question...
– Phelype Oleinik
9 mins ago
add a comment |
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 iffieldundef{field name}{undefined case}{defined case} macro:
AtEveryBibitem{
iffieldundef{url}{}{clearfield{doi}}
}
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.
But then this doesn't answer the question...
– Phelype Oleinik
9 mins ago
add a comment |
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 iffieldundef{field name}{undefined case}{defined case} macro:
AtEveryBibitem{
iffieldundef{url}{}{clearfield{doi}}
}
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.
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 iffieldundef{field name}{undefined case}{defined case} macro:
AtEveryBibitem{
iffieldundef{url}{}{clearfield{doi}}
}
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.
answered 14 mins ago
MarianMarian
1818
1818
But then this doesn't answer the question...
– Phelype Oleinik
9 mins ago
add a comment |
But then this doesn't answer the question...
– Phelype Oleinik
9 mins ago
But then this doesn't answer the question...
– Phelype Oleinik
9 mins ago
But then this doesn't answer the question...
– Phelype Oleinik
9 mins ago
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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