2

I replicated the Journal of Finance reference standard and when I have an article title with a question mark, I also get a comma after it in the references. However, I try to remove the comma if there is a question mark.

Here I created a simple example:

@article{examplesource,
  title={Title of article with question mark?},
  author={LastName1, FirstName1 and LastName2, FirstName2 and LastName3, FirstName3},
  journal={Journal of Finance},
  volume={40},
  number={1},
  pages={3--73},
  year={2005}}
\documentclass{article}

\usepackage[style=ext-authoryear, backend=biber, giveninits=true, uniquelist = false, uniquename=init, isbn=false, maxcitenames=3, dashed=false, maxbibnames=999, doi=false, url=false,giveninits=false]{biblatex}

%Bibliography file with sources
\addbibresource{biblatex-examples.bib}

%Indent of following references rows
\setlength{\bibhang}{15pt}

\renewcommand*{\labelnamepunct}{\addspace}

\DeclareFieldFormat
  [article,inbook,incollection,inproceedings,patent,thesis,unpublished]
  {title}{#1}

\DeclareFieldFormat{titlecase}{\MakeSentenceCase*{#1}}

%Article definition
\renewbibmacro*{in:}{%
  \ifentrytype{article}
    {\setunit{\addcomma\space}}
    {\printtext{\bibstring{in}\intitlepunct}}}

%Title of Journal    
\DeclareFieldFormat{journaltitlecase}{#1}
\renewbibmacro*{journal}{%
  \ifboolexpr{
    test {\iffieldundef{journaltitle}}and
    test {\iffieldundef{journalsubtitle}}}{}
    {\printtext[journaltitle]{%
       \printfield[journaltitlecase]{journaltitle}%
       \setunit{\subtitlepunct}%
       \printfield[journaltitlecase]{journalsubtitle}}}}

%Article number, volume & page
\renewbibmacro*{volume+number+eid}{%
  \printfield{volume}%
  \setunit{\addcomma\space}%
  \printfield{eid}}
\DeclareFieldFormat[article,periodical]{volume}{{#1}}
\DeclareFieldFormat{pages}{#1}

%Parentheses instead of commas in text 
\UndeclareInnerCiteDelims{parencite}
\DeclareInnerCiteDelims{parencite}{(}{)}

%Commas instead of parentheses for years in references
\DeclareFieldFormat{biblabeldate}{#1}
\DeclareDelimFormat[bib]{nameyeardelim}{\addcomma\space}

\ExecuteBibliographyOptions{innamebeforetitle=true} \DeclareDelimFormat[bib]{nametitledelim}{\addcomma\space}

\begin{document}
\textcite{examplesource} lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\\

\printbibliography
\end{document}

I get a comma after the question mark, but I want to only remove the comma in case the title includes a question mark.

Thanks a lot for the suggestions!

1
  • 1
    Try out my answer below, I hope it helps! – A hint: you are loading biblatex with both options giveninits=true and giveninits=false. There's no real conflict, but be aware that later options overwrite earlier ones, so giveninits=true is redundant.
    – marquinho
    Feb 22 at 0:11

1 Answer 1

6
+50

tl;dr

You need to (1) use \addcomma in the macro in: – as you are already doing – and to (2) teach \addcomma not to print a comma following ?, which can be done via \DeclarePunctuationPairs{comma}{*!}.


Here are two approaches, one global and one local. Both are based on the feature \DeclarePunctuationPairs (§4.7.5 of the biblatex documentation). This is intended to customize the behavior of \addcomma and of the \add- commands in general.

\addcomma is designed to print a comma, unless it follows certain punctuation marks. There are exceptions, though:

commas after abbreviation dots, exclamation marks, and question marks are permitted.

The way to specify such a list of exceptions for an \add- command is via \DeclarePunctuationPairs, with the default setting for \addcomma in biblatex.def being:

\DeclarePunctuationPairs{comma}{*!?}

where * stands for the abbreviation dot. (In the US localization, this is the only symbol on the list, meaning no comma after question or exclamation marks.)

Global approach

If we remove the question mark from the list, we are effectively barring biblatex from ever adding a comma after a question mark. This is much broader than what you are asking for, since it affects all entry types (you are looking for article) and potentially all field delimiters (not just between title and journal).

\AtBeginBibliography{\DeclarePunctuationPairs{comma}{*!}}

Note that I chose to activate this setting at the beginning of the bibliography, so as not to affect the main document. (F.i., both commas around “however” in The essay \citetitle{my-article}, however, appeared... are important, regardless of question marks. Something like “The essay “Was ist Aufklärung?” however, appeared” is incorrect.)

Pro: Clear-cut implementation.

Con: This is broader than what you have asked for – though it might be in the spirit of what you are trying to achieve, which is why I chose to demonstrate it.

Local approach

We can edit the bibmacro in: to include a redefinition of the behavior of \addcomma – locally, within the scope of the single entry – so as to affect only the title of journal articles.

\renewbibmacro*{in:}{%
  \ifentrytype{article}
    {\DeclarePunctuationPairs{comma}{*!}        % if article, no comma after "?"
    \setunit{\addcomma\space}}
    {\printtext{\bibstring{in}\intitlepunct}}}

This answers your specific request, it affects only the relevant entry types and fields and doesn't spill over to the main document. And you can always extend the approach to other entry types ("incollection"?) and punctuation (exclamation mark?).

Pro: Answers your specific question.

Con: A bit hacky and inelegant. I don't see any technical problems lurking in this solution, but more expert users might find fault with it.

The result:

original-posting-example

And here's a simple MWE:

\documentclass{article}

\begin{filecontents}{questionable-articles.bib}
@article{kant-kopf,
  title={Versuch über die Krankheiten des Kopfes},
  author={Kant, Immanuel},
  journal={Königsbergsche Gelehrte und Politische Zeitungen},
  pages={13-27},
  year={1764}}
@article{kant-aufklaerung,
  title={Beantwortung der Frage: Was ist Aufklärung?},
  author={Kant, Immanuel},
  journal={Berlinische Monatsschrift},
  pages={481-494},
  year={1784}}
\end{filecontents}

\usepackage{biblatex}

\addbibresource{questionable-articles.bib}

\renewbibmacro*{in:}{%
  \ifentrytype{article}
    {\DeclarePunctuationPairs{comma}{*!}        % if article, no comma after "?"
    \setunit{\addcomma\space}}
    {\printtext{\bibstring{in}\intitlepunct}}}
    
\begin{document}
\nocite{*}
\printbibliography
\end{document}

references-kant

3
  • Hi @marquinho, thank you very much for your clear explanation and for including both solutions. You just helped me massively and this answer would deserve even more reputation :) Many thanks and cheers!
    – fjurt
    Feb 22 at 9:04
  • 1
    You are very welcome! :)
    – marquinho
    Feb 22 at 11:42
  • 2
    +1: I am also impressed that the command DeclarePunctuationPairs exists in the first place. Feb 24 at 5:17

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.