BibLaTeX - 自动用“无日期”、“无出版商”替换空字段“日期”、“出版商”、“位置”

BibLaTeX - 自动用“无日期”、“无出版商”替换空字段“日期”、“出版商”、“位置”

我尝试更改{publisher+location+date}命令,以便如果三个字段中的一个(或多个)publisherlocationdate空,则可以将其替换为名义无限制正弦正弦或其等价物。

为此,我使用命令\iffieldundef{}\ifflistundef{}。我的问题是\iffieldundef{date}没有预期的行为,并且没有检测date字段是否定义明确。

\newunit尽管位于宏的末尾,但我也遇到最后的标点符号问题......

你知道怎么做吗?我被困在这里:

\documentclass{article}
\usepackage[backend=biber, style=verbose-trad1]{biblatex}

\begin{filecontents}{biblio.bib}
@book{example,
    author      = {The Author},
    title       = {A title},
    publisher   = {Hachette},
    location    = {London},
    date        = {1980},
}
\end{filecontents}
\addbibresource{biblio.bib}
\renewcommand{\newunitpunct}{,\space}

\renewbibmacro*{publisher+location+date}{%
\newunit\printtext{%
\iflistundef{publisher}%
    {\iflistundef{location}%
        {\iffieldundef{date}%
            {(s\adddot\addnbspace n\adddot\addcomma s\adddot\addnbspace l\adddot\addnbspace n\adddot\addnbspace d\adddot)}%
            {(s\adddot\addnbspace n\adddot\addnbspace n\adddot\addnbspace l\adddot)\addcomma\addspace\printfield{date} }%
        }%
        {\iffieldundef{date}%
            {(s\adddot\addnbspace n\adddot\addnbspace n\adddot\addnbspace d\adddot)\addcomma\addspace\printlist{location} }%
            {(s\adddot\addnbspace n\adddot)\addcomma\addspace\printlist{location}\addcomma\addspace\printfield{date}}%
        }%
    }%
    {\iflistundef{location}%
        {\iffieldundef{date}%
            {éd\adddot\addspace \printlist{publisher}\addcomma\addspace(s\adddot\addnbspace l\adddot\addnbspace n\adddot\addnbspace d\adddot)}%
            {éd\adddot\addspace \printlist{publisher}\addcomma\addspace(s\adddot\addnbspace l\adddot)\addcomma\addspace\printfield{date} }%
        }%
        {\iffieldundef{date}%
            {éd\adddot\addspace \printlist{publisher}\addcomma\addspace\printlist{location}\addcomma\addspace(s\adddot\addnbspace d\adddot)}%
            {éd\adddot\addspace \printlist{publisher}\addcomma\addspace\printlist{location}\addcomma\addspace\printfield{date}}%
        }%
    }%
}%
\newunit}

\begin{document}
\cite{example}
\printbibliography
\end{document}

答案1

日期的处理方式与 中的其他字段略有不同biblatex。它们在内部由多个 (datepart) 字段组成。测试是否根本没有日期的最佳方法可能是检查是否存在yearendyear。这就是我在下面使用 实现的\ifnodate{<datetype>}(其中为<datetype>,为, 为为空)。urlurldateeventeventdatedate

我稍微重写了你的代码,让它利用 bibstring 来避免使用裸文本和标点符号,这是强烈不建议的。我也可以通过利用标点符号跟踪器来减少一些重复,尽管正确使用括号是有趣的(我可能遗漏了一些东西)。

\documentclass{article}
\usepackage[backend=biber, style=verbose-trad1]{biblatex}

\renewcommand{\newunitpunct}{\addcomma\space}

\NewBibliographyString{nopublisher,nolocation,intropublisher}
\DefineBibliographyStrings{english}{
  nopublisher    = {s\adddot\addnbspace n},
  nolocation     = {s\adddot\addnbspace l},
  intropublisher = {éd\adddot},
}

\newtoggle{bbx:pld:paren}

\DeclareListWrapperFormat{publisher}{%
  \bibstring{intropublisher}\addspace
  #1}

\makeatletter
\newcommand*{\ifnodate}[1]{%
  \iffieldundef{#1year}
    {\iffieldundef{#1endyear}}
    {\@secondoftwo}}
    
\newcommand*{\dischargepunctuation}{%
  \blx@begunit
  \blx@endunit}    
\makeatother

\renewbibmacro*{publisher+location+date}{%
  \global\togglefalse{bbx:pld:paren}%
  \iflistundef{publisher}%
    {\setunit{\addspace\bibopenparen
              \global\toggletrue{bbx:pld:paren}}%
     \bibstring{nopublisher}}
    {\printlist{publisher}}%
  \iflistundef{location}%
    {\setunit{%
       \addcomma\space
       \iftoggle{bbx:pld:paren}
         {}
         {\bibopenparen
          \global\toggletrue{bbx:pld:paren}}}%
     \bibstring{nolocation}}
    {\setunit{%
       \iftoggle{bbx:pld:paren}
         {\bibcloseparen
          \global\togglefalse{bbx:pld:paren}}
         {}%
       \addcomma\addspace}%
     \printlist{location}}%
  \ifnodate{}
    {\setunit{%
        \addcomma\space
        \iftoggle{bbx:pld:paren}
          {}
          {\bibopenparen
           \global\toggletrue{bbx:pld:paren}}}%
     \bibstring{nodate}}
    {\setunit{%
       \iftoggle{bbx:pld:paren}
         {\bibcloseparen
          \global\togglefalse{bbx:pld:paren}}
         {}%
       \addcomma\addspace}%
     \printdate}%
  \iftoggle{bbx:pld:paren}
    {\setunit{%
       \bibcloseparen
       \global\togglefalse{bbx:pld:paren}}%
     \dischargepunctuation}
    {}}

\begin{filecontents}{\jobname.bib}
@book{example:pld,
    author      = {The Author},
    title       = {A title},
    publisher   = {Hachette},
    location    = {London},
    date        = {1980},
}
@book{example:pln,
    author      = {The Author},
    title       = {B title},
    publisher   = {Hachette},
    location    = {London},
    date        = {1980},
}
@book{example:pnd,
    author      = {The Author},
    title       = {C title},
    publisher   = {Hachette},
    date        = {1980},
}
@book{example:pnn,
    author      = {The Author},
    title       = {D title},
    publisher   = {Hachette},
}
@book{example:nld,
    author      = {The Author},
    title       = {E title},
    location    = {London},
    date        = {1980},
}
@book{example:nln,
    author      = {The Author},
    title       = {F title},
    location    = {London},
}
@book{example:nnd,
    author      = {The Author},
    title       = {G title},
    date        = {1980},
}
@book{example:nnn,
    author      = {The Author},
    title       = {H title},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\cite{example:pld}
\nocite{*}
\printbibliography
\end{document}

作者,《A 标题》,阿歇特出版社,伦敦,1980 年。

相关内容