Biblatex:引用书籍时抑制年份字段

Biblatex:引用书籍时抑制年份字段

year我在引用时 尝试抑制该字段\ifentrytype{book}。我以为可以使用\AtEveryCitekey{\ifentrytype{book}{\clearfield{year}}{}},但由于某种原因,它没有达到预期的效果。有什么办法可以解决这个问题吗?提前谢谢!

我已提供一个工作样本:

编辑:现在我正在使用authoryear.cbx

\documentclass{scrartcl}
%
\usepackage[%
backend=biber,%
citestyle=authoryear,%
bibstyle=authortitle,%
]{biblatex}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{filecontents}
\usepackage{verbatim}
\usepackage{csquotes}
%
\addbibresource{\jobname.bib} 
% ===
%
\newbibmacro*{cite:extrainfo:shorttitle}{%
\newunit
\printfield{shorttitle}
}
%
\makeatletter
\newbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}}
       {\printnames{labelname}%
       \ifentrytype{book}%
        {\usebibmacro{cite:extrainfo:shorttitle}}{}% shorttitle in footnote
        \setunit{\printdelim{nameyeardelim}}}%
     \usebibmacro{cite:labeldate+extradate}}
    {\usebibmacro{cite:shorthand}}}
% ===
\makeatletter
\AtEveryCitekey{%
  \ifentrytype{book}{%
    \clearfield{year}%
  }{%
  }%
}
\makeatother
% ===
% === BIB
\begin{filecontents}{\jobname.bib}
@book{test2,
    author      = {Max Mustermann},
    shortauthor = {M-M},
    title       = {Musterbuch},
    shorttitle  = {MB},
    year        = {2018},
}
\end{filecontents}
%
\begin{document}
% ===
\printbibliography[title=Bibliography]
I want to achieve a that if I'm citing a book it won't cite the year. I thought I could achieve that with \verb|\AtEveryCitekey{\ifentrytype{book}{\clearfield{year}}{}}|. But it seems like the year is still being printed. Do I have to replace \verb|{year}| with another argument? \\\footcite[p. 85]{test2}
    How can I make it work?
\end{document}

答案1

您几乎已经完成了。您需要做的就是将cite:labeldate+extradate宏从条件语句之后移到条件语句的“else”分支中。

\renewbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}}
       {\printnames{labelname}%
        \setunit{\printdelim{nameyeardelim}}}%   
     \ifentrytype{book}
       {\setunit{\printdelim{nametitledelim}}%
        \usebibmacro{cite:extrainfo:shorttitle}}
       {\usebibmacro{cite:labeldate+extradate}}}
    {\usebibmacro{cite:shorthand}}}

删除year没有帮助,因为 cite 命令适用于labelyear。虽然labelyear可能是 的副本year(取决于配置\DeclareLabeldate),但它的定义方式是删除year(在biblatex级别)不会影响labelyear。因此,您必须删除labelyear以防止在引文中打印日期。但随后\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}条件启动并打印替换标签而不是labelname。这是不受欢迎的。总而言之,最安全、最简单的方法是使用代码不删除任何字段,如果我们不想要年份,我们只是不调用在引文中打印年份的宏。

对于你cite:extrainfo:shorttitle我更愿意

\newbibmacro*{cite:extrainfo:shorttitle}{%
  \printfield[citetitle]{labeltitle}}

这样做的好处是,如果您不提供字段,它就会打印一些内容shorttitle

在此处输入图片描述

相关内容