1

I'm using biblatex for my citations and references. In some citations I'd like to change the comma for any other symbol that I want. How can I do this?

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[
citestyle=authoryear-comp,
bibstyle=authoryear,
giveninits=true,
maxcitenames=2
]{biblatex}

%References
\begin{filecontents*}{references22.bib}
@Article{Ho_1899,
  author   = {Ho, Lionel and Dreyfus, J. and Boyer, J. and Lowe, T. and Bustamante, H. and Duker, P.},
  title    = {Example article},
  year     = {1899}
}
\end{filecontents*}

\addbibresource{references22.bib}
\begin{document}

\textcite[some words]{Ho_1899}\\
\parencite[some words]{Ho_1899}\par%
%
In the next 2 citations, I'd like to change the comma for ~-~ and "."\par
%
\textcite[~-~some words]{Ho_1899}\\
\parencite[. Some words]{Ho_1899}\par
%
Expected result\par
%
Ho et al. (1899~-~some words)\\
(Ho et al. 1899. Some words)

\end{document}

enter image description here

  • Please Check the edited version, (natbib=true doesn't needed and added a second better option that doesn't break the comma of the original command) – koleygr Mar 7 at 20:50
  • 1
    @DanielalenciaC. Feel free to select the provided answer of mowe that is using the correct (provided by biblatex) method of changing the delim. – koleygr Mar 8 at 9:25
1

This answer is something that many people would imagine as a solution and thus it is here (I will not delete) in order to demonstrate possible problems of such a definition. So, please the last part labeled "moewe's example" in order to understand why this method should be avoided

Section 1:

A hack, but it will break the ability of adding a second optional argument in your \textcite and \parencite comands (if they can "afford" one second argument):

Edit: (both codes) Changed in order to not break (redefine) the original commands' behavior but to use another command name in order to help the discussion with @moewe untill delete the answer.

For @moewe: I also suppose no comma will be added in the second (the mandatory) argument of these two new commands and would like to know what would be the problem in such a definition.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[
citestyle=authoryear-comp,
bibstyle=authoryear,
giveninits=true,
maxcitenames=2,
]{biblatex}

%References
\begin{filecontents*}{references22.bib}
@Article{Ho_1899,
  author   = {Ho, Lionel and Dreyfus, J. and Boyer, J. and Lowe, T. and Bustamante, H. and Duker, P.},
  title    = {Example article},
  year     = {1899}
}
\end{filecontents*}

\newcommand\mytextcite[2][]{\citeauthor{#2}(\citeyear{#2}#1)}
\newcommand\myparencite[2][]{(\cite{#2}#1)}
\addbibresource{references22.bib}
\begin{document}
\mytextcite[some words]{Ho_1899}\\
\myparencite[some words]{Ho_1899}\par%
%
In the next 2 citations, I'd like to change the comma for ~-~ and "."\par
%
\mytextcite[~-~some words]{Ho_1899}\\
\myparencite[. Some words]{Ho_1899}\par
%
Expected result\par
%
Ho et al. (1899~-~some words)\\
(Ho et al. 1899. Some words)

\end{document}

PS: You have to add comma manually in the above code's first two citations.

Section 2:

Code that will work for the two first citations too:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[
citestyle=authoryear-comp,
bibstyle=authoryear,
giveninits=true,
maxcitenames=2,
]{biblatex}

%References
\begin{filecontents*}{references22.bib}
@Article{Ho_1899,
  author   = {Ho, Lionel and Dreyfus, J. and Boyer, J. and Lowe, T. and Bustamante, H. and Duker, P.},
  title    = {Example article},
  year     = {1899}
}
\end{filecontents*}
\def\mydelim{,~}
\newcommand\mytextcite[2][]{\citeauthor{#2}(\citeyear{#2}\mydelim#1)}
\newcommand\myparencite[2][]{(\cite{#2}\mydelim#1)}
\addbibresource{references22.bib}
\begin{document}
\mytextcite[some words]{Ho_1899}\\
\myparencite[some words]{Ho_1899}\par%
%
In the next 2 citations, I'd like to change the comma for ~-~ and "."\par
%

\def\mydelim{~.~}
\mytextcite[some words]{Ho_1899}\\
\def\mydelim{.~}
\myparencite[Some words]{Ho_1899}\par
%
Expected result\par
%
Ho et al. (1899~-~some words)\\
(Ho et al. 1899. Some words)

\end{document}

The given result for these examples are the expected results:

enter image description here

moewe's example: (read his last comment too)

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[style=authoryear-ibid]{biblatex}

\addbibresource{biblatex-examples.bib}

\def\mydelim{,~}
\newcommand\mytextcite[2][]{\citeauthor{#2}(\citeyear{#2}\mydelim#1)}

\begin{document}
\cite{sigfridsson} \cite{sigfridsson}

\mytextcite{nussbaum} \mytextcite{nussbaum} % no "ibid"

\cite{sigfridsson} % incorrect "ibid."

\citereset
\cite{sigfridsson} \cite{sigfridsson}

\textcite{nussbaum} \textcite{nussbaum} % correct "ibid"

\cite{sigfridsson} % no "ibid."
\end{document}
  • 1
    I strongly prefer solutions that do not redefine the cite commands in such a way. Not only does this approach not allow for the second option prenote argument, it also has a hard time dealing with multiple citations: Try \textcite{sigfridsson,worman}. In its current definition the citations will also produce a spurious postnote punctuation if there is no optional argument: Try \textcite{sigfridsson}. Furthermore, the combination of several \cite commands into one \(re)newcommand can mess up citation tracking (which would be important for 'ibid.' or backrefs). – moewe Mar 8 at 7:45
  • -comp features are also disabled: Cite \textcite{knuth:ct:a,knuth:ct:b} (and compare that with \cite{knuth:ct:a,knuth:ct:b}). Oh, I just realised: Try \textcite{knuth:ct:b,knuth:ct:c} and compare it with \cite{knuth:ct:b,knuth:ct:c}. The disambiguation letters are missing! That is a serious issue as it will make the citation impossible to pin down. – moewe Mar 8 at 7:51
  • Thanks , @mowe, I was thinking to not redefine the command but just give a new name. Sure would give less problems and I could fix it to accept more arguments, but I am going to delete the answer. I would like to know what this: "the combination of several \cite commands into one (re)newcommand can mess up citation tracking" supposed to mean. (I mean that I would like to understand why this problem would come up) Sure it would not show the correct -suggested- order for multiple citation in one command and this would change the order of an unsrt-style bibliography etc. For 1 inner argument? – koleygr Mar 8 at 9:22
  • 1
    gist.github.com/moewew/67866c6ddbcc32a3b0c201f99ba9af23 shows an issue that would arise with 'ibid.' styles. – moewe Mar 8 at 9:39
  • 1
    The key here is that full citation commands such as \cite, \textcite, \parencite are tracked by biblatex (i.e. they set the last cited key, author, year for 'ibid.' and the like, biblatex remembers the page number for backref, the citations are indexed, ...). The lower-level \citeauthor, \citetitle etc. usually do no such thing, they are not tracked and exist 'outside' or are transparent for the real cite commands. If you now use the low-level command to recreate a real cite command, this can mess up the tracking expectations. – moewe Mar 8 at 9:51
4

The command that controls the punctuation before the postnote is called \postnotedelim. You can redefine it as you see fit. If you only want to change the punctuation locally for the next cite command, it is best to wrap the redefinition into \AtNextCite. It may come in handy to define a new command for that to avoid having to type that much.

If there is a rule/an algorithm behind the changes to the punctuation, it might be possible to automate the changes. Starting with the next biblatex release postnotedelim will be a context-sensitive delimiter (https://github.com/plk/biblatex/pull/869), which means that it will be very simple to define different delimiters for \parencite and \textcite.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[style=authoryear-comp]{biblatex}

\addbibresource{biblatex-examples.bib}

\newcommand*{\SetNextPostnoteDelim}[1]{%
  \AtNextCite{\renewcommand*{\postnotedelim}{#1}}}

\begin{document}
\textcite[some words 01]{sigfridsson}

\parencite[some words 02]{sigfridsson}

% \AtNextCite applies only to the next citation
\AtNextCite{\renewcommand*{\postnotedelim}{\addspace\textendash\space}}
\textcite[some words 03]{sigfridsson}

\parencite[some words 04]{sigfridsson}

\AtNextCite{\renewcommand*{\postnotedelim}{\addperiod\space}}
\parencite[Some words 05]{sigfridsson}

\textcite[some words 06]{sigfridsson}

% \AtNextCite packed up in a handy command
\SetNextPostnoteDelim{\addspace\textendash\space}
\textcite[some words 03']{sigfridsson}

\parencite[some words 04']{sigfridsson}

\SetNextPostnoteDelim{\addperiod\space}
\parencite[Some words 05']{sigfridsson}

\textcite[some words 06']{sigfridsson}

% a simple \renewcommand applies from now until the next change
\renewcommand*{\postnotedelim}{\addspace\textendash\space}
\textcite[some words 07]{sigfridsson}

\parencite[some words 08]{sigfridsson}

\renewcommand*{\postnotedelim}{\addperiod\space}
\parencite[Some words 09]{sigfridsson}

\textcite[Some words 10]{sigfridsson}

% manual approach: provide the punctuation in the postnote
\renewcommand*{\postnotedelim}{}
\textcite[~-~some words 11]{sigfridsson}

\parencite[. Some words 12]{sigfridsson}
\end{document}

Sigfridsson and Ryde (1998, some words 01)//(Sigfridsson and Ryde 1998, some words 02)//Sigfridsson and Ryde (1998 – some words 03)//(Sigfridsson and Ryde 1998, some words 04)//(Sigfridsson and Ryde 1998. Some words 05)//Sigfridsson and Ryde (1998, some words 06)//Sigfridsson and Ryde (1998 – some words 03’)//(Sigfridsson and Ryde 1998, some words 04’)//(Sigfridsson and Ryde 1998. Some words 05’)//Sigfridsson and Ryde (1998, some words 06’)//Sigfridsson and Ryde (1998 – some words 07)//(Sigfridsson and Ryde 1998 – some words 08)//(Sigfridsson and Ryde 1998. Some words 09)//Sigfridsson and Ryde (1998. Some words 10)//Sigfridsson and Ryde (1998 - some words 11)//(Sigfridsson and Ryde 1998. Some words 12)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.