如何在 biblatex 中抑制 .bbl 檔案中的註解字段

如何在 biblatex 中抑制 .bbl 檔案中的註解字段

我想使用 biblatex 抑制 .bbl 檔案中的註解欄位。我經常使用註釋欄位來寫下有關給定論文的註釋,如果我碰巧在註釋欄位中使用 LaTeX 命令(例如 %),這可能會出現問題。在註釋欄位中包含類似 % 的內容不會在 .bib 檔案中導致任何問題,但在 .bbl 檔案中包含它會導致編譯失敗。我嘗試遵循中的建議是否可以在 biblatex 中抑制 bibtex .bbl 中的特定場?,但這些對我來說不起作用。

這是我的最小工作範例:

\documentclass[12pt]{article}

\usepackage{biblatex}

\begin{filecontents*}{mwe.bib}
@article{Doe.J-1979a,
    Annote = {10 % strain},
    Author = {John Doe},
    Date-Added = {2020-08-27 10:54:17 -0600},
    Date-Modified = {2020-08-27 12:03:22 -0600},
    Journal = {Journal of LaTeX Issues},
    Title = {Problematic Reference Title},
    Year = {1979}}
\end{filecontents*}

\addbibresource{mwe.bib}

\AtEveryBibitem{\clearfield{annotation}}

\DeclareSourcemap{
  \maps[datatype=bibtex, overwrite]{
    \map{
      \step[fieldset=annotation, null]
    }
  }
}

\begin{document}
\textcite{Doe.J-1979a}
\printbibliography
\end{document}

這將創建以下 .bbl 文件

\begingroup
\makeatletter
\@ifundefined{[email protected]}
  {\@latex@error
     {Missing 'biblatex' package}
     {The bibliography requires the 'biblatex' package.}
      \aftergroup\endinput}
  {}
\endgroup


\refsection{0}
  \datalist[entry]{nty/global//global/global}
    \entry{Doe.J-1979a}{article}{}
      \name{author}{1}{}{%
        {{hash=bd051a2f7a5f377e3a62581b0e0f8577}{%
           family={Doe},
           familyi={D\bibinitperiod},
           given={John},
           giveni={J\bibinitperiod}}}%
      }
      \strng{namehash}{bd051a2f7a5f377e3a62581b0e0f8577}
      \strng{fullhash}{bd051a2f7a5f377e3a62581b0e0f8577}
      \strng{bibnamehash}{bd051a2f7a5f377e3a62581b0e0f8577}
      \strng{authorbibnamehash}{bd051a2f7a5f377e3a62581b0e0f8577}
      \strng{authornamehash}{bd051a2f7a5f377e3a62581b0e0f8577}
      \strng{authorfullhash}{bd051a2f7a5f377e3a62581b0e0f8577}
      \field{sortinit}{D}
      \field{sortinithash}{2ef1bd9a78cc71eb74d7231c635177b8}
      \field{labelnamesource}{author}
      \field{labeltitlesource}{title}
      \field{annotation}{10 % strain}
      \field{journaltitle}{Journal of LaTeX Issues}
      \field{title}{Problematic Reference Title}
      \field{year}{1979}
    \endentry
  \enddatalist
\endrefsection
\endinput

正如您所看到的,%中的右括號弄亂了\field{annotation}{10 % strain}

答案1

在MWE中,.bib檔案包含字段annote,但在來源對應中,步驟指定annotation為字段。因此,如果在來源映射中我們替換annotationannote包含的字段,%則該字段將無效,並且不會出現在bbl文件中。因此,\DeclareSourcemap指令應如下所示:

\DeclareSourcemap{
  \maps[datatype=bibtex, overwrite]{
    \map{
      \step[fieldset=annote, null]
    }
  }
} 

答案2

吉多已經給出了回答:您需要刪除annote來源對應中的欄位。但了解其中的原因可能會很有趣。

biblatex設定了一些欄位和類型別名,以向後相容一些流行的 BibTeX 樣式。一種這樣的別名關係將annote字段轉換為annotation.對於 Biber,這種別名關係是透過特殊的實現的驅動程式來源圖定義在biblatex.def(二。 v3.15a 中的 1305-1337

\DeclareDriverSourcemap[datatype=bibtex]{
  <...>
  \map{
    \step[fieldsource=hyphenation,   fieldtarget=langid]
    \step[fieldsource=address,       fieldtarget=location]
    \step[fieldsource=school,        fieldtarget=institution]
    \step[fieldsource=annote,        fieldtarget=annotation]
    \step[fieldsource=archiveprefix, fieldtarget=eprinttype]
    \step[fieldsource=journal,       fieldtarget=journaltitle]
    \step[fieldsource=primaryclass,  fieldtarget=eprintclass]
    \step[fieldsource=key,           fieldtarget=sortkey]
    \step[fieldsource=pdf,           fieldtarget=file]
  }
}

這只是說將annoteBiber 發現的每一個都變成annotation.事實上,你可以說,內部biblatex只有場annotation,沒有annote場。所以很自然地寫出所有提及 onlyannotation和 not 的程式碼annote

您遇到的問題是計時:此驅動程式來源映射已執行你的用戶級別簡單\DeclareSourcemap。特別是,當執行來源對應時,尚未重命名任何欄位名稱,並且該欄位仍稱為annote.

Guido 的回答顯示了解決該問題的一種方法:刪除該annote字段,因為執行來源對應時仍然會呼叫該字段。您可能annotation也可能不想刪除

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldset=annote,     null]
      \step[fieldset=annotation, null]
    }
  }
}

解決該問題的另一種方法是執行來源映射中已有的annote->映射:因此,您首先將所有映射到,然後刪除.annotationannoteannotationannotation

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=annote,  fieldtarget=annotation]
      \step[fieldset=annotation, null]
    }
  }
}

請注意,在任何情況下都\AtEveryBibitem{\clearfield{annotation}}無濟於事,因為從文件%中讀取條目資料時已經發生了錯誤.bbl,而不是在參考書目中列印該欄位時。更重要的是,標準biblatex樣式(除了reading)無論如何都不會顯示annotation,因此\clearfield在 MWE 中不會做任何有用的事情。

答案3

新增annotation=false到設定中,例如:\usepackage[style=apa,annotation=false]{biblatex}

相關內容