2

I want to remove the comma between the "school" field and the date (year) in an @thesis bibliography entry:

Here is my minimal example code:

\documentclass{minimal}

\usepackage{ngerman}
\usepackage[backend = biber, style = numeric]{biblatex}

%%%%%%%% https://tex.stackexchange.com/a/492917

\newtoggle{bbx:datemissing}

\renewbibmacro*{date}{\toggletrue{bbx:datemissing}%}

\renewbibmacro{volume+number+eid}{%
  \printfield{volume}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\renewbibmacro*{issue+date}{%
  \toggletrue{bbx:datemissing}%
  \iffieldundef{issue}{}{
    \printtext[parens]{%
    \printfield{issue}}}%
  \newunit}

\newbibmacro*{date:print}{%
  \togglefalse{bbx:datemissing}%
  \printdate}

\renewbibmacro*{chapter+pages}{%
  \printfield{chapter}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}

\renewbibmacro*{note+pages}{%
  \printfield{note}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}

%%%%%%%%

%%% This is what I came up with
\renewbibmacro{institution+location+date}{%
  \printlist{location}%
  \iflistundef{institution}{%
    \setunit*{\space}%
  }{%
    \setunit*{\addcolon\space}%
  }%
  \printlist{institution}%
  \setunit*{\space}%
  \usebibmacro{date}%
  \newunit%
}

\usepackage{filecontents}
\begin{filecontents*}{lit.bib}
  @thesis {mythesis,
    author = {Me, I.},
    school = {University},
    title = {Sometitle},
    type = {Phd thesis},
    year = {123}
  }  
\end{filecontents*}

\addbibresource{lit.bib}

\begin{document}
\printbibliography
\end{document}
\nocite{*}

I already tried \renewbibmacro{institution+location+date}{...}, but that did not work. I am quite new to BibLaTeX.

My thought was that the numeric style uses the entry types from standard, which is from where I copied the macro and removed all commas. However, that clearly did not work. How can I remove this comma?

7
  • 1
    Did you delete your aux files and recompile? The code here produces no comma.
    – Alan Munn
    Aug 15, 2020 at 22:11
  • @AlanMunn That's odd, I must have missed something when creating the minimal example because it clearly does not work in my full code. Aug 15, 2020 at 22:17
  • @AlanMunn I have added some code I copied from a different question. Aug 15, 2020 at 22:25
  • (That only adds a dot, not a comma...) Aug 15, 2020 at 22:29
  • The code from tex.stackexchange.com/q/491895/35864 you are using explicitly shifts the date printing away from \usebibmacro{date} to \usebibmacro{date:print}. That is done in a very unsophisticated fashion and for all entry types alike. The date is now printed after the pages field. Since the punctuation before a field is always the last punctuation command the style issued before the field is printed, it is not enough to modify institution+location+date as the punctuation commands that are relevant come in later. ...
    – moewe
    Aug 16, 2020 at 9:53

2 Answers 2

3

You can add \nopunct just before the \newunit of your redefined institution+location+date macro. I've changed the document class of your example to article. Despite its name, the minimal document class should not be used for MWEs since it is in fact too minimal. I've also removed the filecontents package, which is now part of the LaTeX kernel.

\documentclass{article}

\usepackage{ngerman}
\usepackage[backend = biber, style = numeric]{biblatex}

\newtoggle{bbx:datemissing}

\renewbibmacro*{date}{\toggletrue{bbx:datemissing}}

\renewbibmacro{volume+number+eid}{%
  \printfield{volume}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\renewbibmacro*{issue+date}{%
  \toggletrue{bbx:datemissing}%
  \iffieldundef{issue}{}{
    \printtext[parens]{%
    \printfield{issue}}}%
  \newunit}

\newbibmacro*{date:print}{%
  \togglefalse{bbx:datemissing}%
  \printdate}

\renewbibmacro*{chapter+pages}{%
  \printfield{chapter}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}

\renewbibmacro*{note+pages}{%
  \printfield{note}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}
%%% This is what I came up with
\renewbibmacro{institution+location+date}{%
  \printlist{location}%
  \iflistundef{institution}{%
    \setunit*{\space}%
  }{%
    \setunit*{\space}%
  }%
  \printlist{institution}%
  \setunit*{\space}%
  \usebibmacro{date}%
  \nopunct\newunit%
}

\begin{filecontents*}[overwrite]{\jobname.bib}
  @thesis {mythesis,
    author = {Me, I.},
    school = {University of Somewhere},
    title = {Sometitle},
    type = {Phd thesis},
    year = {1980}
  }  
\end{filecontents*}

\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

output of code

2
  • That works. But why do I have to put \nopuct after \usebibmacro{date}? I would have expected it to go before... Am I misunderstanding something? Aug 15, 2020 at 22:41
  • 1
    @HerpDerpington The way punctuation is added in biblatex is quite complex, and it happens asynchronously. So (roughly) the punctuation isn't produced where it's called. See §4.11.7 of the biblatex manual for a detailed explanation of how it works.
    – Alan Munn
    Aug 15, 2020 at 22:45
2

The answer to Change the order of the pages and year in Biblatex, whose code you are using, uses quite blunt instruments to move the date printing after pages. This may not be exactly what you want or need in all situations.

Here is a slightly more complex setup that moves the date only if there are pages (or a chapter), which may result in an output that works slightly better for you in some situations.

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[backend=biber, style=numeric]{biblatex}

\newtoggle{bbx:datesuppressed}

\renewbibmacro*{date}{%
  \ifboolexpr{
        test {\iffieldundef{pages}}
    and test {\iffieldundef{chapter}}}
    {\printdate}
    {\toggletrue{bbx:datesuppressed}}}

\renewbibmacro{volume+number+eid}{%
  \printfield{volume}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\renewbibmacro*{issue+date}{%
  \toggletrue{bbx:datesuppressed}%
  \iffieldundef{issue}
    {}
    {\printtext[parens]{%
       \printfield{issue}}}%
  \newunit}

\newbibmacro*{date:print}{%
  \iftoggle{bbx:datesuppressed}
    {\togglefalse{bbx:datesuppressed}%
     \printdate}
    {}}

\renewbibmacro*{chapter+pages}{%
  \printfield{chapter}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}

\renewbibmacro*{note+pages}{%
  \printfield{note}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \usebibmacro{date:print}%
  \newunit}

\renewbibmacro{institution+location+date}{%
  \printlist{location}%
  \iflistundef{institution}
    {\setunit*{\space}}
    {\setunit*{\addcolon\space}}%
  \printlist{institution}%
  \setunit*{\space}%
  \usebibmacro{date}%
  \newunit
}

\begin{filecontents*}{\jobname.bib}
@phdthesis{mythesis,
  author = {Me, I.},
  school = {University},
  title  = {Sometitle},
  year   = {123},
}  
\end{filecontents*}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
\nocite{mythesis,sigfridsson,westfahl:space}
\printbibliography
\end{document}

I. Me. “Sometitle”. Phd thesis. University 123.

As Alan explained in the comments under his answer, biblatex's punctuation handling is asynchronous: Punctuation is stored in a buffer and only printed once it is needed (i.e. when the next \print... command actually prints something). Since in the code in the question the \usebibmacro{date} in institution+location+date doesn't actually print the date, the \setunit before it does not ultimately control the punctuation before the date. The date is only printed by date:print in chapter+pages, at which point other \setunit commands will have added different punctuation into the buffer.

\nopunct sets a permanent marker not to print any punctuation until new content/text is printed by a \print... command. In this case it helps to suppress the undesired period. Since \nopunct can be used inside and outside the punctuation tracker it is a handy tool to tweak punctuation, but I generally try to avoid it and prefer solutions not using it, as it can have effects that go beyond what is desired.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .