3

I'm working with a modified harvard.bst file to match the specific (and weird) requirements from my University guidelines. I must reference articles following this structure:

enter image description here

  1. if there's no doi, the reference ends just right after the pages numbers with a dot .
  2. If there's a doi, the doi info comes right after the page numbers, separeted by comma

This is what a have so far:

enter image description here

To accomplish this I made the following modifications (among many others). It works fine for me except that I have a '.' after the pages numbers, instead of ','

Any idea on how to sort this out?

FUNCTION {format.pages}
{ pages empty$
    { "" } %change pages line 285 0r 386
    { pages multi.page.check
        { "p. " pages n.dashify * }
        {  pages " p." * }
      if$
    }
  if$
}


FUNCTION {format.vol.num.pages}
{ volume field.or.null
  number empty$
    'skip$
    { ", no. " number *"" * *
      volume empty$
    { "there's a number but no volume in " cite$ * warning$ }
    'skip$
      if$
    }
  if$
  pages empty$
    'skip$
    { duplicate$ empty$
    { pop$ format.pages }
    { ", p.~" * pages n.dashify * }
      if$
    }
  if$
}

FUNCTION {article}
{ output.bibitem
  list.label.output
  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
  author "author" item.check
    title.field field.used =
    { skip$ }
    { title "title" output.check }
  if$
  crossref missing$
    { add.colon 
    journal
      ", v. " * format.vol.num.pages * output
    }
    { format.article.crossref output.nonnull
      "p " * format.pages * output
    }
  if$
  new.block
  note output
  fin.entry
  write.url
}

And this is my bib entry:

@article{coogan2006trace,
  title={Do the trace element compositions of detrital zircons require Hadean continental crust?},
  author={Coogan, Laurence A and Hinton, Richard W},
  journal={Geology},
  volume={34},
  number={8},
  pages={633--636},
  year={2006},
  publisher={Geological Society of America},
  url={10.1130/G22737.1.}
}

I remember that I tried to create a doi function (or modify it), but as I don't really know how to code this, I let it go - never got to get it working. I put it here anyway if anyone believes this is a better way.

FUNCTION {doilink}
{ duplicate$ empty$
{ pop$ "" }
{ doi empty$
    { skip$ }
    { "\href{http://dx.doi.org/" doi * "}{" * swap$ * "}" * }
  if$
}
if$
}
FUNCTION {add.doi}
{ duplicate$ empty$
    { skip$ }
    { doi empty$
        {}
        {"\href{http://dx.doi.org/" doi * "}{" * swap$ * "}" *}
      if$
    }
  if$
}
FUNCTION {format.jdoi}
{ doi missing$   
    { "" }
    {", doi: " doi * 
      }
    if$
     doilink 
}
3
  • Have you tried running the makebst utility, which is a part of the custom-bib package, to create a bespoke bst file?
    – Mico
    Dec 26, 2021 at 17:28
  • yes, but as I have almost all requirements nice and tight and I'm very short on time, I decided to make theses changes manually
    – raulindo
    Dec 26, 2021 at 19:18
  • 2
    Just in the author field, I can spot at least two significant differences between what you're achieving at present and what you're supposed to achieve. Hence, your optimism that "I have almost all requirements nice" may be, well, too optimistic. Also, given how almost trivially easy it is to employ the makebst utility, I actually doubt that you're saving much time, if any, by hand-editing an existing bst file.
    – Mico
    Dec 26, 2021 at 20:39

1 Answer 1

0

Well, I found a hack that works for me. I solved treating the doi as a note and modified the article function as follows:

FUNCTION {format.jdoi}
{ doi missing$   
    { "" }
    {" doi:" doi * 
      }
    if$
     doilink 
}

FUNCTION {article}
{ output.bibitem
  list.label.output
  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
  author "author" item.check
    title.field field.used =
    { skip$ }
    { title "title" output.check }
  if$
  crossref missing$
    { add.colon 
    journal
      ", v. " * format.vol.num.pages * output
    }
    { format.article.crossref output.nonnull
      "p " * format.pages * output
    }
  if$
  new,block
  format.jdoi output
  fin.entry
  write.url
}

Hacking bib entry:

@article{coogan2006trace,
  title={Do the trace element compositions of detrital zircons require Hadean continental crust?},
  author={Coogan, Laurence A and Hinton, Richard W},
  journal={Geology},
  volume={34},
  number={8},
  pages={633--636},
  year={2006},
  publisher={Geological Society of America},
  doi={10.1130/G22737.1.}
}


@article{pacca1998paleomagnetism,
  title="{Paleomagnetism of Paleoproterozoic mafic dyke swarm from the Uauá region, northeastern São Francisco Craton, Brazil: tectonic implications}",
  author={D'agrella Filho, M S and Pacca, I I G},
  journal={Journal of South American Earth Sciences},
  volume={11},
  number={1},
  pages={23--33},
  year={1998},
  publisher={Elsevier}
}

Example with bibentry with and without doi number:

enter image description here

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.