TransWikia.com

How to abbreviate author's firstname in bibliography

TeX - LaTeX Asked by mcandril on September 25, 2021

I am currently finalizing the bibliography of my thesis. I am using

bibliographystyle{unsrtdin}
bibliography{bibtex/library}

Now, my problem is that my Zotero library sometimes has the full first name of the authors and sometimes just the initials. This leads to an inconsistend bibliography. I don’t feel that the right solution is to remove information from my Zotero library, so I would like to have BibTeX abbreviate all first names.

The style is not fixed, I only need unsrt behavior and included URLs, since I cite online resources. (That’s why I use -din, the fact that some things are German is unde sired but not too critical.)

If Biber or other more sophisticated implementations simplify the solution: I tried to get it to work, but TeXlipse told me that cite was undefined, so I gave it up, as I didnt see too many advantages in this case.

If all that is too complicated, I could still hack the Zotero translator for .bib export.

5 Answers

Here are some possible alternatives for the solution. You can choose the one that fits you best.

1- switch to biblatex. It is a newer package to deal with bibliography; it is much easier to configure than bibtex styles. The manual might look scary, but you only have to change a few lines to get it working.

2- as already suggested in the comments, you can use an automated tool to generate a new bst file from scratch, if you have some liberty. You can use makebst, or the GUI program included in bib-it.

3 - hacking the bst files directly is also possible. You will need some programming experience to be able to understand what is going on, but since you speak of hacking Zotero, I guess this won't be a problem; keep in mind that bst files are written in a rather unusual stack-based language which might be difficult to understand at first. In your case, you probably only have to copy the format.name function used in abbrv.bst into unsrt.bst, replacing the existing one.

EDIT: maybe I should clarify what a bst file is. Bibliography styles in bibtex are handled through style files with extension .bst. If you use bibliographystyle{unsrtdin}, then the file that will be loaded is unsrtdin.bst. The default styles can be found inside the tex install directory (on my Ubuntu for instance it's /usr/share/texlive/texmf-dist/bibtex/bst/); but, if you wish, you can create a new one by yourself and drop it in the same folder as your .tex file (or use some more involved "local install" method, if you think you need it for multiple tex files).

Correct answer by Federico Poloni on September 25, 2021

Assuming that you're otherwise satisfied with the formatted output produced by the bibliography style unsrtdin -- i.e., if the only thing you want to change in the style file is to force BibTeX to always abbreviate first names down to their initials -- you could proceed as follows:

  • Make a copy of the file unsrtdin.bst and call it, say, myunsrtdin.bst. (Never edit the original style file directly.)

  • Open the file myunsrtdin.bst in your favorite text editor.

  • Search for the following line (in the function format.names):

    { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
    

    and change it to

    { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
    
  • Next, in the function format.crossref.editor, search for the line

        { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
    

    and change it to

        { editor #2 "{f. }{vv }{ll}{ jj}" format.name$ "others" =
    
  • Save the file and start using it by issuing the instruction bibliographystyle{unsrtdin}.


I can't help but make a few remarks about the use of Zotero. You've already discovered one inconsistency: Sometimes the tool provides full first names of authors and editors, at other times it provides only abbreviated first names. Sadly, this is likely going to be the least of your worries with Zotero's output. Be sure to always check the .bib file (or files) generated by this tool for correctness of all input fields. In my own experience with Zotero, its output can contain quite a few embarrassing typos and, much worse, outright errors, such as missing authors in a multi-author publication.

This piece of advice about double-checking the validity of the files generated by Zotero (or any other online tool like it!) is independent of whether you end up using unsrtdin/BibTeX or biblatex/biber: BibTeX and bibLaTeX can do nothing about errors contained in the inputs they operate on.

Answered by Mico on September 25, 2021

I tried to follow the description of Mico but needed some addaptions. This is the patch I applied to the current version of unsrtdin.bst (http://www.ctan.org/tex-archive/biblio/bibtex/contrib/german/din1505) to obtain abbreviated first names:

diff --git a/unsrtdin_mod.bst b/unsrtdin_mod.bst
index 5505961..5134bfb 100644
--- a/unsrtdin_mod.bst
+++ b/unsrtdin_mod.bst
@@ -448,7 +448,7 @@ FUNCTION {format.names}
        s nameptr "{ll}" format.name$ 't :=
        t capitalize 't :=
        s nameptr "{ jj}" format.name$ 'w :=
-       s nameptr "{, ff}{ vv}{ jj}" format.name$ 'u :=
+       s nameptr "{, f.}{ vv}{ jj}" format.name$ 'u :=
        u  text.length$  'lang :=
        #1 'zahl :=
        "" 'v :=
@@ -1192,7 +1192,7 @@ FUNCTION {format.crossref.editor}
     { pop$ ua.etal * }%% --->u. a.
     { #2 <
         'skip$
-        { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
+        { editor #2 "{f. }{vv }{ll}{ jj}" format.name$ "others" =
             { ua.etal }

             { " ; " * editor #2 "{vv~}{ll}" format.name$ * " (Hrsg.)" * }

Answered by Peter Pablo on September 25, 2021

Edit : For the current version (3.12) of biblatex, firstinits argument is depreciated. Use giveninits instead (cf. this question).


When using biblatex, just state this in your preamble:

usepackage[backend=bibtex,firstinits=true]{biblatex}

If you want to add an unsorted style use this:

  usepackage[backend=bibtex,style=numeric-comp,sorting=none,firstinits=true]{biblatex}

I currently use this line:

 usepackage[backend=bibtex,citestyle=numeric-comp,bibstyle=ieee,sorting=none,minbibnames=5,maxbibnames=5,defernumbers=true,firstinits=true]{biblatex}

This allows for multiple bibliographies, limits the amount of reference names to 5, and uses a different citing and bibliography style.

Answered by Caspar on September 25, 2021

# FILENAME: abbrv_bib.py

#!/usr/bin/env python3
from bibtexparser.bwriter import BibTexWriter
import bibtexparser
from pybtex.database import parse_file
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('input', help='input file name')
parser.add_argument('output', help='output file name')
parser.add_argument('--no-middle', action='store_true',
                    help='do not abbreviate middle name')
args = parser.parse_args()

# %%
# Parse the original bib file with pybtex
# pybtex can distinguish first/middle/last names
bib_database = parse_file(args.input)
for k in bib_database.entries.keys():
    item = bib_database.entries[k]
    persons = item.persons
    print(k)
    for i in range(len(persons['author'])):
        oldFirstNames = persons['author'][i].first_names
        newFirstNames = []
        for j in oldFirstNames:
            if j[-1] == '.':
                newFirstNames.append(j)
            else:
                newFirstNames.append(j[0].upper() + '.')

        oldMiddleNames = persons['author'][i].middle_names
        if args.no_middle:
            newMiddleNames = oldMiddleNames[:]
        else:
            newMiddleNames = []
            for j in oldMiddleNames:
                if j[-1] == '.':
                    newMiddleNames.append(j)
                else:
                    newMiddleNames.append(j[0].upper() + '.')

        oldName = ' '.join(
            [' '.join(persons['author'][i].last_names) + ','] + oldFirstNames + oldMiddleNames)
        newName = ' '.join(
            [' '.join(persons['author'][i].last_names) + ','] + newFirstNames + newMiddleNames)
        if (oldName != newName):
            print('  - {:s} => {:s}'.format(oldName, newName))
            persons['author'][i].first_names = newFirstNames
            persons['author'][i].middle_names = newMiddleNames


# %%
# Write the new bib file with bibtexparser
# I use bibtexparser here because pybtex prefers quote instead of curly bracket
# e.g.  pybtex:  title = "This is a paper"
#       bibtexparser: title = {This is a paper}
# This makes it escape some underscores incorrectly
with open(args.input, 'r', encoding='utf-8') as bibtex_file:
    bibtex_str = bibtex_file.read()
bib = bibtexparser.loads(bibtex_str)
for k in bib.entries_dict:
    bib.entries_dict[k]['author'] = ' and '.join(['{:s}, {:s} {:s}'.format(' '.join(p.last_names), ' '.join(p.first_names), ' '.join(p.middle_names))
                                                  for p in bib_database.entries[k].persons['author']])
writer = BibTexWriter()
with open(args.output, 'w', encoding='utf-8') as bibfile:
    bibfile.write(writer.write(bib))

I wrote a python script to do it manually. This avoids incompatibility of biblatex to other package. You can use it as

python3 abbrv_bib.py input.bib output.bib

If you don't want to abbreviate middle name, just add the argument --no-middle The script can abbreviate the following types of name:

Cruden, Brett A. => Cruden, B. A.
Johann Sebastian Bach => Bach, J. S.
Surname, Given Name III. => Surname, G. N. III.
Johann Sebastian Jr. Bach => Bach, J. S. Jr.

It also rearrange the name to Last name, First name Middle name

Answered by Han Luo on September 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP