Repository: texworld/betterbib (language: python)

Issue:
Space between initials
In case of multiple first names, `betterbib` puts no space, see e.g.

```shell
$ betterbib doi-to-bibtex 10.1103/physrevb.4.2412
%comment{This file was created with betterbib v4.0.1.}


@article{blackman1971,
 author = {Blackman, J.A. and Esterling, D.M. and Berk, N.F.},
 doi = {10.1103/physrevb.4.2412},
 number = {8},
 pages = {2412-2428},
 source = {Crossref},
 url = {http://dx.doi.org/10.1103/physrevb.4.2412},
 volume = {4},
 journal = {Phys. Rev. B},
 publisher = {American Physical Society (APS)},
 title = {Generalized Locator---Coherent-Potential Approach to Binary Alloys},
 issn = {0556-2805},
 year = {1971},
 month = oct,
}
```

`bibtex`, however, needs a space, that is, `author = {Blackman, J. A. and Esterling, D. M. and Berk, N. F.},`.


Discussion / hints:
Reference?

_Edit:_ No space seems to be more correct. See Robert Bringhurst, The Elements of Typographic Style, rule 2.1.5:
> Add little or no space within strings of initials.

Also see https://tex.stackexchange.com/q/10203/13262.
Sorry, I cannot provide a reference. And please correct me if I am wrong. But typography doesn't matter in your bibtex file. Latex has to typeset it correctly, but this depends on your bitex/latex style.

The problem is that bibtex understands `Blackman, J.A.` as a person with first name `J.A.` rendering the name as `J. Blackman`,
not a person with two first names:
```
J. Blackman, D. Esterling, and N. Berk, Phys. Rev. B 4, 2412 (1971).
```

While if the Name contains correct spaces `author = {Blackman, J. A. and Esterling, D. M. and Berk, N. F.}` we get the correct entry:
```
J. A. Blackman, D. M. Esterling, and N. F. Berk, Phys. Rev. B 4, 2412 (1971).
```
(Of course the space between `J.` and `A.` might be incorrect here as I paste only the text, not the PDF, just like bold font is missing.)

So the question here is not about the correct space, but the correct Name!
Like I said, correct me if I am wrong as I have hardly any knowledge of bibtex, but to my understanding the current behavior of `betterbib` yields **incorrect bibliographies**.

Please also compare with the reference name given by the site http://dx.doi.org/10.1103/physrevb.4.2412 itself, and the bibtex file they provide https://journals.aps.org/prb/export/10.1103/PhysRevB.4.2412
> The problem is that bibtex understands Blackman, J.A. as a person with first name J.A. rendering the name as J. Blackman, not a person with two first names:

I cannot reproduce this. MWE:

```latex
\documentclass{article}
\usepackage{biblatex}

\begin{filecontents}{\jobname.bib}
@article{einstein,
  author = {Einstein, A.X.},
  title = {Some title},
  journaltitle = {Annalen der Physik}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
  \nocite{einstein}
  \printbibliography
\end{document}
```
Output:

![screenshot](https://user-images.githubusercontent.com/181628/136190505-a1f81f39-1d6c-45f6-bb6a-f395b2e0d0a5.png)
That's because you choose to spell out the full first name, use `giveninits=True` to see the difference.
See:
```text
\documentclass{article}
\usepackage[giveninits=true]{biblatex}

\begin{filecontents}{\jobname.bib}
@article{einstein,
  author = {Einstein, A.X.},
  title = {Some title},
  journaltitle = {Annalen der Physik}
}
@article{fulleinstein,
  author = {Einstein, Albert Xylophon},
  title = {Some title},
  journaltitle = {Annalen der Physik}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
  \nocite{einstein,fulleinstein}
  \printbibliography
\end{document}
```

![Screenshot from 2021-10-06 13-50-11](https://user-images.githubusercontent.com/22542812/136196997-25bb4cf9-7cf3-4291-8728-4507d4a34b84.png)

Whereas printing the full name, as you did:

```tex
\documentclass{article}
\usepackage[giveninits=false]{biblatex}

\begin{filecontents}{\jobname.bib}
@article{einstein,
  author = {Einstein, A.X.},
  title = {Some title},
  journaltitle = {Annalen der Physik}
}
@article{fulleinstein,
  author = {Einstein, Albert Xylophon},
  title = {Some title},
  journaltitle = {Annalen der Physik}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
  \nocite{einstein,fulleinstein}
  \printbibliography
\end{document}
```
![Screenshot from 2021-10-06 13-52-06](https://user-images.githubusercontent.com/22542812/136197158-63d8322d-4500-4f93-9787-64d94e334b9d.png)

----
In principle, the bibtex file should optimally contain all information available, and the bibtex style or the biblatex configuration decides how it should be presented, e.g. abbreviating names are giving using et al. after a certain number of names.
This is especially important, if you submit the manuscript to Journals, which use their on personal configurations.

> That's because you choose to spell out the full first name

I don't understand. I only give the initials, how do I "spell out the full first name"?
Ah, you mean that by not providing `giveninits`, I tell biblatex to use to the "full" first name, and it understands "A.X." as full first name.

I think I understand the problem now. Given that [this blog entry](https://clauswilke.com/blog/2015/10/02/bibtex/) from 2015 recommends the same,

> Therefore, always abbreviate names in your Bibtex file, and leave a space between initials, [...]

I'll see about changing this in betterbib.
Exactly, was just typing a response. A clarifying example is maybe the empty parenthesis `()` you see in the references.
Your style says print the year in parentheses, but your `.bib` file is incomplete, as the year is missing.

This is the strength of LaTeX we should keep in mind, in `.bib` we give all the information we have, the LaTeX style decides what to print. It might e.g. decide to print 3 authors and abbreviate the rest with et al. This doesn't mean we should only give 3 authors in the `.bib` file.

Fix patch:
diff --git a/setup.cfg b/setup.cfg
index 6ca39f2..dadfeb2 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
 [metadata]
 name = betterbib
-version = 4.0.1
+version = 4.0.2
 author = Nico Schlömer
 author_email = nico.schloemer@gmail.com
 description = Better BibTeX data
diff --git a/src/betterbib/tools.py b/src/betterbib/tools.py
index 7b64d9b..17117b3 100644
--- a/src/betterbib/tools.py
+++ b/src/betterbib/tools.py
@@ -290,26 +290,6 @@ def get_short_doi(doi):
     return data["ShortDOI"]
 
 
-def _join_abbreviated_names(lst):
-    """Joins a list of name strings like ["J.", "Frank"] such that it adds a space if
-    one of the two names is not abbreviated. See
-    <https://english.stackexchange.com/a/105529/23644>.
-    """
-    if len(lst) == 0:
-        return ""
-
-    out = lst[0]
-    last_ends_in_dot = lst[0][-1] == "."
-    for item in lst[1:]:
-        ends_in_dot = item[-1] == "."
-        if last_ends_in_dot and ends_in_dot:
-            out += item
-        else:
-            out += " " + item
-        last_ends_in_dot = ends_in_dot
-    return out
-
-
 def _get_person_str(p):
     out = ", ".join(
         filter(
@@ -317,7 +297,15 @@ def _get_person_str(p):
             [
                 " ".join(p.prelast_names + p.last_names),
                 " ".join(p.lineage_names),
-                _join_abbreviated_names(p.first_names + p.middle_names),
+                # In plain English, you wouldn't put a full space between abbreviated
+                # initials, see, e.g.,
+                # <https://english.stackexchange.com/a/105529/23644>. In bib files,
+                # though, it's useful, see
+                # <https://github.com/nschloe/betterbib/issues/212> and
+                # <https://clauswilke.com/blog/2015/10/02/bibtex/>.
+                # See <https://tex.stackexchange.com/a/11083/13262> on how to configure
+                # biber/biblatex to use thin spaces.
+                " ".join(p.first_names + p.middle_names),
             ],
         )
     )
@@ -415,7 +403,7 @@ def heuristic_unique_result(results, d):
 
 # This used to be a write() function, but beware of exceptions! Files would get
 # unintentionally overridden, see <https://github.com/nschloe/betterbib/issues/184>
-def to_string(od, delimiter_type: str, tab_indent: bool, preamble: list = []):
+def to_string(od: dict, delimiter_type: str, tab_indent: bool, preamble: list = []):
     """
     Creates a string representing the bib entries
 


Test patch:
diff --git a/tests/test_tools.py b/tests/test_tools.py
index 9c21eed..cd5a886 100644
--- a/tests/test_tools.py
+++ b/tests/test_tools.py
@@ -130,7 +130,7 @@ def test_first_name_space():
     }
     out = betterbib.pybtex_to_bibtex_string(d["doe"], "doe")
     ref = """@misc{doe,
- author = {Doe, J.J.},
+ author = {Doe, J. J.},
 }"""
 
     assert out == ref