TeX - LaTeX Asked on May 6, 2021
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{addcommaspace}%
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*{addcolonspace}%
}%
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?
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{addcommaspace}%
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}%
nopunctnewunit%
}
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}
Correct answer by Alan Munn on May 6, 2021
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{addcommaspace}%
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*{addcolonspace}}%
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}
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.
Answered by moewe on May 6, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP