1

I want to make a hierarchy for printing doi, url, isbn and issn in BiBTeX. Something like this (here "real" means that the bib-field is availably/valid):

if "doi" real
   print doi
else
  if "url" real
     print url
  else
    if "isbn" real
       print isbn
    else
      if "issn" real
         print issn
      end
    end
  end
end

So "doi" is the most important field to print!

I have looked at Redundancy in bib file: conditionally suppress url if same as doi? and Biblatex: Print ISBN only if DOI is not defined to get some idears, but no luck.

MWE: tex-file

\documentclass{article}
\usepackage{natbib}
\begin{document}
\bibliographystyle{testplainnat}
\citep{test1,test2,test3,test4,test5,test6,test7,test8,test9,test10}
\bibliography{testbib}
\end{document}

BIB: BIB-file

@Article{test1,
  author =   {Author, A},
  title =    {Title A},
  journal =    {journal},
  year =     2001,
  doi =      {no.},
  note =     {(doi only!)}
}

@Article{test2,
  author =   {Author, B},
  title =    {Title B},
  journal =    {journal},
  year =     2002,
  url =      {no.},
  note =     {(url only!)}
}

@Article{test3,
  author =   {Author, C},
  title =    {Title C},
  journal =    {journal},
  year =     2003,
  isbn =     {no.},
  note =     {(isbn only!)}
}

@Article{test4,
  author =   {Author, D},
  title =    {Title D},
  journal =    {journal},
  year =     2004,
  issn =     {no.},
  note =     {(issn only!)}
}

@Article{test5,
  author =   {Author, E},
  title =    {Title E},
  journal =    {journal},
  year =     2005,
  url =      {no.},
  doi =      {no.},
  note =     {(doi and url)}
}

@Article{test6,
  author =   {Author, F},
  title =    {Title F},
  journal =    {journal},
  year =     2006,
  isbn =     {no.},
  doi =      {no.},
  url =      {no.},
  note =     {(doi, url and isbn)}
}

@Article{test7,
  author =   {Author, G},
  title =    {Title G},
  journal =    {journal},
  year =     2007,
  isbn =     {no.},
  issn =     {no.},
  doi =      {no.},
  url =      {no.},
  note =     {(doi, url, isbn and issn)}
}

@Article{test8,
  author =   {Author, H},
  title =    {Title H},
  journal =    {journal},
  year =     2008,
  isbn =     {no.},
  doi =      {no.},
  note =     {(doi and isbn)}
}

@Article{test9,
  author =   {Author, I},
  title =    {Title I},
  journal =    {journal},
  year =     2009,
  issn =     {no.},
  doi =      {no.},
  note =     {(doi and issn)}
}

@Article{test10,
  author =   {Author, J},
  title =    {Title J},
  journal =    {journal},
  year =     2010,
  isbn =     {no.},
  url =      {no.},
  note =     {(url and isbn)}
}

bst:

test-plainnat-bst-file

3

If you don't know too much about editing BST files, perhaps the declaration of the different publication types is the least error-prone way. At the very end of your testplainnat.bst-file you have functions for each doctype like:

FUNCTION {article}
{ output.bibitem
  format.authors "author" output.check
  author format.key output
  new.block
  format.title "title" output.check
  new.block
  crossref missing$
    { journal emphasize "journal" output.check
      eid empty$
        { format.vol.num.pages output }
        { format.vol.num.eid output }
      if$
      format.date "year" output.check
    }
    { format.article.crossref output.nonnull
      eid empty$
        { format.pages output }
        { format.eid output }
      if$
    }
  if$
  format.isbn output
  format.issn output
  format.doi output
  format.url output
  new.block
  note output
  fin.entry
}

So the interesting part is

  format.isbn output
  format.issn output
  format.doi output
  format.url output
  new.block

A IF-ELSE-Statement for "use doi or url or issn" looks like:

  format.isbn output
  format.doi empty$
  {
    format.url output empty$
    {
      format.issn output empty$
    }
    {
      format.url output
    }
  }
  {
    format.doi output
  }
  if$  
  new.block

I think you get the idea from this example. So basically it is

<value to test> empty$
{<run this cmd if empty>}
{<run this cmd if not empty>}

and a bit of nesting.

Of course you would need to repeat this for every doctype (like FUNCTION {book} etc.), but this is easier to handle than changing the format.* functions themselves.

(And this from someone that finds it easy to change bst files but has real issues adapting a biblatex style).

3

The recently developed Bibulous project handles this directly. For article-type entries in a *.bib file, an example template definition is the following::

article = <au>, \enquote{<title>,} <journal>, <volume>: [<startpage>--<endpage>|<startpage>|<eid>|] (<year>).[ <doi>| <url>| <isbn>| <issn>]

At the end of the template is a "option block" which has the effect that if it finds a doi field in the database entry, then it will insert it here. If it doesn't find one, then it looks for a url field, and inserts it if present. And likewise for isbn and issn. If none of these fields are present, then the entire [...] block is ignored.

This should produce exactly the requested behavior, albeit using Bibulous in place of Biblatex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.