biblatex:如果参考书目中的位置字段为空,则删除该字段

biblatex:如果参考书目中的位置字段为空,则删除该字段

在 biblatex 中,我想删除参考书目中@manual缺少位置(地址)的条目的位置(又名地址)字段。否则,结果会出现一对难看的空括号。MWE:

\documentclass[11pt, oneside]{article}


\usepackage[
backend=biber, 
defernumbers=true, 
style=numeric, 
bibstyle=authoryear,
autocite = superscript,
date=year, 
giveninits=true, 
sorting=none,
]
{biblatex}

% Changes for Book
\csletcs{abx@macro@publisher+location+date@orig}{abx@macro@publisher+location+date}
\renewbibmacro*{publisher+location+date}{%
    \printtext[parens]{\usebibmacro{publisher+location+date@orig}}
}
\DeclareFieldFormat[book]{title}{#1\printunit{\addspace}}


\begin{filecontents}[force]{\jobname.bib}

@manual{Wilke:2020aa,
    author = {Claus O. Wilke},
    date-added = {2023-11-26 13:10:50 -0800},
    date-modified = {2023-11-26 15:12:25 -0800},
    note = {R package version 1.1.1},
    title = {cowplot: Streamlined Plot Theme and Plot Annotations for 'ggplot2'},
    url = {https://CRAN.R-project.org/package=cowplot},
    year = {2020},
    bdsk-url-1 = {https://CRAN.R-project.org/package=cowplot},
    }
    
@manual{R-Core-Team:2023aa,
    address = {Vienna, Austria},
    author = {{R Core Team}},
    date-added = {2023-11-18 21:11:58 -0800},
    date-modified = {2023-11-18 21:16:30 -0800},
    organization = {R Foundation for Statistical Computing},
    title = {\textsf{R}: A language and environment for statistical computing},
    url = {https://www.R-project.org/},
    year = {2023},
    bdsk-url-1 = {https://www.R-project.org/},
    }
    
\end{filecontents}


\addbibresource{\jobname.bib}

\begin{document}


I would like to remove the empty address field for the Wilke citation, but not the R Core Team citation \autocite{Wilke:2020aa, R-Core-Team:2023aa}.

\printbibliography

\end{document}  

输出如下:

输出

答案1

尝试这个:

\documentclass[11pt, oneside]{article}

\usepackage[
backend=biber, 
defernumbers=true, 
style=numeric, 
bibstyle=authoryear,
autocite=superscript,
date=year, 
giveninits=true, 
sorting=none,
]{biblatex}

% Default global settings for publisher+location+date
\csletcs{abx@macro@publisher+location+date@orig}{abx@macro@publisher+location+date}
\renewbibmacro*{publisher+location+date}{%
    \printtext[parens]{\usebibmacro{publisher+location+date@orig}}
}

\DeclareFieldFormat[book]{title}{#1\printunit{\addspace}}

% Customizing @manual bibliography driver
\DeclareBibliographyDriver{manual}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \iflistundef{location}
    {\printlist{}}
    {\printtext[parens]{%
       \printlist{location}%
       \setunit*{\addcomma\space}%
       \printfield{year}}%
    }
  \newunit\newblock
  \usebibmacro{note+pages}%
  \newunit\newblock
  \iftoggle{bbx:url}
    {\usebibmacro{doi+eprint+url}}
    {}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

\begin{filecontents}[force]{\jobname.bib}
@manual{Wilke:2020aa,
    author = {Claus O. Wilke},
    note = {R package version 1.1.1},
    title = {cowplot: Streamlined Plot Theme and Plot Annotations for 'ggplot2'},
    url = {https://CRAN.R-project.org/package=cowplot},
    year = {2020},
}

@manual{R-Core-Team:2023aa,
    address = {Vienna, Austria},
    author = {{R Core Team}},
    organization = {R Foundation for Statistical Computing},
    title = {\textsf{R}: A language and environment for statistical computing},
    url = {https://www.R-project.org/},
    year = {2023},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

I would like to remove the empty address field for the Wilke citation, but not the R Core Team citation \autocite{Wilke:2020aa, R-Core-Team:2023aa}.

\printbibliography

\end{document}

用于\iflistundef{location}检查是否为条目定义了位置列表@manual
如果是,则位置和年份会打印在括号内;否则,不会打印任何内容来代替位置。

输出如下:
在此处输入图片描述

相关内容