biblatex: How to remove the parentheses around the year in authoryear style?
Thanks to egreg's great answer to biblatex: Is it possible to patch macros created with \newbibmacro?, the solution to the present question is easy: Use the new \patchbibmacro
command to selectively change the definition of the date+extrayear
bibmacro however this definition looks like in the first place (provided some common patterns are present).
\documentclass{article}
\usepackage[style=authoryear]{biblatex}
% By courtesy of Enrico Gregorio (egreg)
\makeatletter
\def\act@on@bibmacro#1#2{%
\expandafter#1\csname abx@macro@\detokenize{#2}\endcsname
}
\def\patchbibmacro{\act@on@bibmacro\patchcmd}
\def\pretobibmacro{\act@on@bibmacro\pretocmd}
\def\apptobibmacro{\act@on@bibmacro\apptocmd}
\def\showbibmacro{\act@on@bibmacro\show}
\makeatother
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\nocite{*}
\begin{document}
\printbibliography
\patchbibmacro{date+extradate}{%
\printtext[parens]%
}{%
\setunit{\addperiod\space}%
\printtext%
}{}{}
\printbibliography
\end{document}
EDIT: Things are even easier with egreg's xpatch
package:
\documentclass{article}
\usepackage[style=authoryear]{biblatex}
\usepackage{xpatch}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\nocite{*}
\begin{document}
\printbibliography
\xpatchbibmacro{date+extradate}{%
\printtext[parens]%
}{%
\setunit{\addperiod\space}%
\printtext%
}{}{}
\printbibliography
\end{document}
UPDATE: A better solution for the bibliography may be found here.
In-text-citations: Replace \cite
with \textcite
.
Bibliography: From my personal biblatex.cfg
(plus \makeatletter
/\makeatother
):
\makeatletter
\ifcsundef{abx@macro@\detokenize{date+extrayear}}{%
}{%
\renewbibmacro*{date+extrayear}{%
\iffieldundef{year}{%
}{%
\addperiod\space
\printtext{\printdateextra}%
}%
}%
}
\makeatother
(One could also simply redefine the date+extrayear
bibmacro, but this would cause an error in case one switches to a style that doesn't feature this particular macro.)
EDIT: Alan Munn has brought my attention to the fact that my redefinition is based on an outdated version of authoryear.bbx
which is by mistake still included in the biblatex version coming with MiKTeX. With a correctly installed biblatex version, my "solution" may or may not work for you.
EDIT 2: MiKTeX isn't the culprit. My preferred editor (TeXworks) somehow displays the contents of a former (!) version of authoryear.bbx
.
EDIT 3: It seems that my redefinition will work with the default setting of the authoryear style, but is likely to break things if you tinker with the mergedate
option (which was improved in biblatex v1.1b).
The following answer to the second part of my question is based on discussions with lockstep in chat where we discovered that there have been significant changes to how dates are formatted in bibtex
v1.1b which make his original answer potentially problematic. I thank him for his help.
For the first part of the question, his answer stands: to get parentheses around in-text citation years, use the \textcite
family of commands.
To remove the parentheses from the bibliography years requires significant modification to the .bbx
file. (I describe the modifications schematically here.) The actual modification should ideally be part of a separate .bbx
file.
The biblatex authoryear.bbx
file contains the following code to format various date fields. (This is just one of 5 such blocks of code: \bbx@opt@mergedate@maximum
, compact
, basic
, minimum
and false
.)
\def\bbx@opt@mergedate@basic{%
\renewbibmacro*{date+extrayear}{%
\iffieldundef{year}
{}
{\printtext[parens]{%
\printfield{labelyear}%
\printfield{extrayear}}}}%
\renewbibmacro*{date}{%
\iffieldundef{month}
{}
{\printdate}}%
\renewbibmacro*{issue+date}{%
\ifboolexpr{
test {\iffieldundef{issue}}
and
test {\iffieldundef{month}}
}
{}
{\printtext[parens]{%
\printfield{issue}%
\setunit*{\addspace}%
\printdate}}%
\newunit}%
}
The relevant part of the code that formats the year field is:
\renewbibmacro*{date+extrayear}{%
\iffieldundef{year}
{}
{\printtext[parens]{%
\printfield{labelyear}%
\printfield{extrayear}}}}
Notice that the two \printfield
commands are enclosed in a \printtext[parens]
command. This is the command that needs to be changed. So we redefine it without the [parens]
format, and additionally we add punctuation and a space (which will appear right after the author name). This is needed because in styles that don't parenthesize the year, both author and year need to be punctuated.
So the redefined code is:
\renewbibmacro*{date+extrayear}{%
\iffieldundef{year}
{}
{\printtext{%
\addperiod\space\printfield{labelyear}%
\printfield{extrayear}}}}
The same change needs to be made in each of the \bbx@opt@mergedate@...
commands.
To make these changes take effect, the .bbx
file must also have the line:
\ExecuteBibliographyOptions{labelyear,sorting=nyt,pagetracker,mergedate}
Additionally, the following needs to be added to the .bbx
file to correctly format the extra year field when the year is non-numeric. (Based on lockstep's answer to this question: How to format the extrayear field in biblatex.
\DeclareFieldFormat{extrayear}{%
\iffieldnums{labelyear}{%
\mknumalph{#1}%
}{%
\mkbibparens{\mknumalph{#1}}%
}%
}
It would be nice if this sort of change would not take such low-level programming, but could be a user option. But for now this seems to be the best way to achieve it.