21

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.

8
  • 1
    If the style ist't fixed maybe you could make a own bibtex style with makebst. It supports making first names into initials.
    – Storm
    Feb 17, 2013 at 11:00
  • I would not abbreviate the name of the authors. If you do abbreviate then somebody else may not be able to find the reference because of lack of information. You should make sure the name matches the exact name in the original reference. Sometimes online BibTeX entries are wrong: don't trust them; only trust the original reference.
    – user10274
    Feb 17, 2013 at 12:28
  • 1
    So you think it is not consistent to to have mixed abbreviated and unabbreviated names in the bibliography? I never thought about that, but it does not sound implausible. Can I read that somewhere?
    – mcandril
    Feb 17, 2013 at 14:17
  • 1
    If your question is for me, I do think it may look inconsistent but that's not relevant. What is important is that the information is consistent with the references. That's what the bibliography is for. Read Mary-Claire Van Leunen's A Handbook for Scholars if you want to learn more about preparing a bibliography. For example, Page 159: "It is an elementary courtesy to an author to give her name as it appears on her work."
    – user10274
    Feb 17, 2013 at 16:59
  • 1
    @MarcvanDongen, while I'm inclined to agree that it's courteous to give names in the style the author does, as journals rarely do this, (for example the Applied Physics Letters RevTeX style always abbreviates to first initials in the references section) I'm not going to worry about it.
    – Chris H
    Dec 31, 2013 at 11:33

5 Answers 5

11

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).

4
  • Ok, thanks so far! I think I will go in the order 1, 3, 2. I assume I will run into the same problems as before when switching to biblatex, i.e. \cite is reported to be undefined. Is that a known and easy to solve issue, by chance? Also, can you give some hint what lines to look at and were, so I don't have to go through the whole manual?
    – mcandril
    Feb 17, 2013 at 12:15
  • 3
    It should be enough to load the package in the preamble \usepackage[sorting=none,url=true]{biblatex}, then replace the \bibliography{somefile} line with \addbibresource{somefile}, remove \bibliographystyle, and finally add a \printbibliography where you want the bibliography to appear. This assuming that you do not need any additional customization. Feb 17, 2013 at 12:21
  • 11
    Oh - and of course I forgot the most important thing: in addition to sorting and url, you also need the option firstinits=true when you load the package, which should abbreviate authors' names. Feb 17, 2013 at 12:27
  • 2
    To complement the excellent answer by @FedericoPoloni, bear in mind that, unlike the \bibliography command, the \addbibresource command should be in the preamble, and that you should include the file extension .bib
    – Ataxias
    Jun 4, 2021 at 5:25
28

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.

16

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.

4
  • Welcome to TeX.SX! Does your proposed setup automatically incorporate all features of the unsrtdin bibliography style, including (a) providing German-language adaptations (such as "und" instead of "and" as the conjunction) and (b) not sorting the bibliographic entries?
    – Mico
    Feb 10, 2015 at 6:48
  • As long as you set your babel package correctly, it should be able to cope with German as well. If you want to add a sorting style do this: \usepackage[backend=bibtex,style=unsrt,sorting=none,firstinits=true]{biblatex} I currently use this line: \usepackage[backend=bibtex,defernumbers=true,style=numeric-comp,sorting=none,minbibnames=5,maxbibnames=5,firstinits=true]{biblatex} This allows for multiple bibliographies, and limits the amount of reference names to 5.
    – Caspar
    Feb 12, 2015 at 23:30
  • This information belongs in the body of the answer, not a follow-up comment.
    – Mico
    Feb 13, 2015 at 3:53
  • 1
    Added to main answer.
    – Caspar
    Feb 18, 2015 at 4:07
2

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.)" * }
0
# 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

3
  • 2
    As this is a TeX centric Q&A site, not everybody is familiar with Python. Could you maybe enhance your answer by explaining what the code does, maybe introduce one or the other comment and thereby allow non-experiences Python users to use your code, too?
    – TobiBS
    Jul 27, 2020 at 7:46
  • Can this method handle name fields of the form Bach, Johann Sebastian as well as Johann Sebastian Bach?
    – Mico
    Jul 27, 2020 at 13:24
  • I have added some explanations. You need two python package pybtex and bibtexparser. This method should be able to hand names mentioned above as pybtex claims Pybtex aims to be 100% compatible with BibTeX
    – mach6
    Jul 28, 2020 at 17:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .