1

I am trying to achieve citing with squared brackets in natbib, having comma-separated author and year in it, like this:

[Einstein, 1905]

Within the text I am successful with:

\usepackage{natbib}
\bibliographystyle{dinat}
\setcitestyle{authoryear,open={[},close={]}}

But when printing the reference with \bibliography{sample}, there is no comma between author and year. I use XeLaTex and BibTex to compile the document on macOS High Sierra.

The sample.tex:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{natbib}
\bibliographystyle{dinat}
\setcitestyle{authoryear,open={[},close={]}}

\title{Bibliography management: \texttt{natbib} package}
\author{Share\LaTeX}
\date { }

\begin{document}

\maketitle

This document is an example of \texttt{natbib} package using in bibliography
management. Three items are cited: \textit{The \LaTeX\ Companion} book 
\citep{latexcompanion}, the Einstein journal paper \citep{einstein}, and the 
Donald Knuth's website \citep{knuthwebsite}. The \LaTeX\ related items are 
\citep{latexcompanion,knuthwebsite}. 

\medskip

\bibliography{sample}

\end{document}

The sample.bib:

@article{einstein,
    author =       "Albert Einstein",
    title =        "{Zur Elektrodynamik bewegter K{\"o}rper}. ({German})
        [{On} the electrodynamics of moving bodies]",
    journal =      "Annalen der Physik",
    volume =       "322",
    number =       "10",
    pages =        "891--921",
    year =         "1905",
    DOI =          "http://dx.doi.org/10.1002/andp.19053221004"
}

@book{latexcompanion,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The \LaTeX\ Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts"
}

@misc{knuthwebsite,
    author    = "Donald Knuth",
    year = 2019,
    title     = "Knuth: Computers and Typesetting",
    url       = "http://www-cs-faculty.stanford.edu/\~{}uno/abcde.html"
}

What must be done to get a comma between author and year?

EDIT:

The example is taken from Sharelatex.

5
  • Just out of idle curiosity: Why do you care about the presence of a comma (or the lack thereof) in the formatted bibliography? Are you really concerned that somebody might fail to parse the formatted bib items correctly for lack of a comma? Please advise.
    – Mico
    Mar 18, 2018 at 18:21
  • 1
    If I were you, I would be far more concerned about the ouright error in one of the URL strings. url = "http://www-cs-faculty.stanford.edu/\~{}uno/abcde.html" is simply wrong. It should be url = "http://www-cs-faculty.stanford.edu/~uno/abcde.html". (Can you spot the difference?) Readers tend to resent it if they are presented with invalid URL strings. In contrast, nobody could care less over the presence (or absence) of a meaningless comma.
    – Mico
    Mar 18, 2018 at 18:25
  • @Mico Well, it's about getting the document perfect all the way through. If there is a coma within the text, I'd like a comma in the references, too. Hence, the same style. And there is no place for a personal opinion when it is a thesis requirement.
    – Socrates
    Mar 18, 2018 at 18:42
  • @Mico True, the URL looks indeed a bit strange. I put an edit to the posting mentioning the site I got this example from. Interesting point, though not the focus of this posting.
    – Socrates
    Mar 18, 2018 at 18:44
  • natbib is a package that provides tools to manage citation call-outs. It does not control the look of the formatted bibliographic entries -- that's the purview of the bibliography style file (here: dinat.bst). You'll have to hack that file and, in particular, the BibTeX function that controls the contents of the the \dinatlabel directive. Are you absolutely certain that your university has made the presence of the comma in the label an absolute requirement?
    – Mico
    Mar 18, 2018 at 18:55

0

You must log in to answer this question.

Browse other questions tagged .