识别 BibLaTeX 地图源中的键

识别 BibLaTeX 地图源中的键

在对问题的评论中使用 Biber 和 BibLaTeX 对参考书目条目进行注释Marco Daniel 建议使用\DeclareSourcemap为特定条目添加注释。

最直接的解决方案是有一个源映射的定义,例如,我们根据 BibTeX 搜索条目key,因此使用类似的东西:

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=entrykey, match={key1},
            fieldset=note, fieldvalue={This is a note}]
    }
  }
}

但是,它不起作用:该note字段未插入到相应的条目中。但是,如果使用不同的字段,例如,author

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=author, match={Author},
            fieldset=note, fieldvalue={This is a note}]
    }
  }
}

然后,注释就被插入了。

我认为在这种情况下不需要 MWE,但是既然有人会要求,那么这里就是:

\documentclass{article}
\usepackage{filecontents}
\usepackage[style=numeric]{biblatex}
\addbibresource{\jobname.bib}
\begin{filecontents}{\jobname.bib}
@article{key1,
author = {Author, John},
title  = {Title},
journal =  {A Journal},
year = 2012,
}
@article{key2,
author = {Author2, John},
title  = {Title},
journal =  {A Journal},
year = 2012,
}
\end{filecontents}
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=entrykey, match={key1},
            fieldset=note, fieldvalue={This is a note}]
    }
    \map{
      \step[fieldsource=author, match={Author2},
            fieldset=note, fieldvalue={This is a note}]
      }
  }
}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

因此,问题是是否可以entrykey在 biber mapsource 规范中使用 BibTeX 键(),或者field可以使用什么并唯一地标识 bibentry?

答案1

我认为您无法匹配 entrykey 字段(但这可能值得提出功能请求)。但实际上您可能不需要它。您可以改为执行如下操作:

\documentclass{article}
\usepackage{filecontents}

\usepackage[style=numeric]{biblatex}
\addbibresource{\jobname.bib}
\begin{filecontents}{\jobname.bib}
@article{key1,
author = {Author, John},
title  = {Title},
journal =  {A Journal},
year = 2012,
}
@article{key2,
author = {Author2, John},
title  = {Title},
journal =  {A Journal},
year = 2012,
}
@article{key3,
author = {Author3, John},
title  = {Title},
journal =  {A Journal},
year = 2012,
}
\end{filecontents}

\makeatletter
\@namedef{key1note}{This is note 1}
\@namedef{key2note}{This is note 2}
% key3 has no note 
\makeatother

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldset=note, 
            fieldvalue=\unexpanded{\csname\thefield{entrykey}note\endcsname}
            ]
      }
  }
}



\begin{document}
\nocite{*}
\printbibliography
\end{document}

相关内容