打印两个日期之间的书目条目

打印两个日期之间的书目条目

如何创建 bibcheck,只打印两个日期之间的出版物,比如 2017 年 5 月 1 日至 2018 年 4 月 30 日之间?在 Mac OS X 10.13.4 上使用 biblatex 3.9、biber 2.10,在 TexShop 中使用 XeLatex 进行编译。

Biblatex 手册提供了\defbibcheck。在下面的例子中,\defbibcheck用于打印自 2000 年以来的出版物。但我不知道如何修改它以仅打印两个日期之间的出版物。

\defbibcheck{recent}{%
\iffieldint{year}
{\ifnumless{\thefield{year}}{2000}
{\skipentry}
{}}
{\skipentry}}

以下

\documentclass{article}
\usepackage{biblatex}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @article{greenwade93,
        author  = "A Guy",
        title   = "A document",
        date    = "2016-01-05",
        journal = "Journal of Post-Modern Mysticisms",
        volume  = "14",
        number  = "3",
        pages   = "342--351"
    }

    @book{abook,
        author    = "An Other Auther",
        title     = "Something Really Important",
        date      = "2017-06-01",
        publisher = "Addison-Wesley",
        address   = "Somewhere Town"
    }
    \end{filecontents}



\addbibresource{\jobname.bib}
\begin{document}
Test
\nocite{*}
\printbibliography
\end{document}

答案1

一种直接的方法是添加一个测试,看看你的条目是否是在特定日期(或)之后写的。然后可以像在biblatex,biber,两年之间可以 \printbibliography 吗?。目前的测试非常简单,如果遇到没有月份或日期信息的条目,将会抛出错误 - 当然可以防止这种情况,但不确定写入的内容是否year = {2018}来自 2018-05-08 之后。

\ifdateafter{yyyy}{mm}{dd}检查条目的日期是否在之后yyyy-mm-dd(“>”),\ifdateonorafter{yyyy}{mm}{dd}检查日期是否不在之前yyyy-mm-dd(“>=”)。这些命令有一个可选参数,可用于检查不同的日期,用于\ifdateonorafter[url]检查条目的 URL 日期或\ifdateonorafter[orig]检查origdate字段;默认值为空的可选参数,用于检查date

您现在可以使用\ifdateonorafterin\defbibcheck来仅选择在 2017-05-01 或之后但在 2018-05-01 之前撰写的条目。

\documentclass{article}
\usepackage{biblatex}

% this macro is not used in the check below, but might still be useful
% check if entry's date > {yyyy}{mm}{dd} 
\newcommand*{\ifdateafter}[4][]{%
  \ifboolexpr{test {\ifnumgreater{\thefield{#1year}}{#2}}
              or (test {\ifnumequal{\thefield{#1year}}{#2}}
                  and (test {\ifnumgreater{\thefield{#1month}}{#3}}
                       or (test {\ifnumequal{\thefield{#1month}}{#3}}
                           and test {\ifnumgreater{\thefield{#1day}}{#4}})))}}

% check if entry's date >= {yyyy}{mm}{dd} 
\newcommand*{\ifdateonorafter}[4][]{%
  \ifboolexpr{test {\ifnumgreater{\thefield{#1year}}{#2}}
              or (test {\ifnumequal{\thefield{#1year}}{#2}}
                  and (test {\ifnumgreater{\thefield{#1month}}{#3}}
                       or (test {\ifnumequal{\thefield{#1month}}{#3}}
                           and not test {\ifnumless{\thefield{#1day}}{#4}})))}}

\defbibcheck{thisyear}{%
  \iffieldint{year}
    {\ifdateonorafter{2017}{5}{1}      % date >= 2017-05-01?
       {\ifdateonorafter{2018}{5}{1}   % date >= 2018-05-01
          {\skipentry}                 % too new for us (date >= 2018-05-01)
          {}}                          % just right (2017-05-01 <= date < 2018-05-01)
       {\skipentry}}                   % too old (date <2017-05-01)
    {\skipentry}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{greenwade93,
  author  = "A Guy",
  title   = "A document",
  date    = "2018-05-01",
  journal = "Journal of Post-Modern Mysticisms",
  volume  = "14",
  number  = "3",
  pages   = "342--351"
}

@book{abook,
  author    = "An Other Auther",
  title     = "Something Really Important",
  date      = "2017-06-01",
  publisher = "Addison-Wesley",
  address   = "Somewhere Town"
}
\end{filecontents}

\addbibresource{\jobname.bib}
\begin{document}
Test
\nocite{*}
\printbibliography[check=thisyear]
\end{document}

在此处输入图片描述

答案2

另一种方法是在源映射中的日期上使用正则表达式,为感兴趣的条目添加关键字(这是对 moewe 在评论中提供的链接中 jon 的回答的要求的改编,即:https://tex.stackexchange.com/a/346299/105447)。

对于您的情况,由于您的间隔从一个月的第一天延伸到另一个月的最后一天,我们只需要控制月份。但是,该技术可以扩展到实际需要日期的情况或可能并不总是完整指定日期的情况。

\documentclass{article}
\usepackage{biblatex}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
  @article{greenwade93,
    author  = "A Guy",
    title   = "A document",
    date    = "2016-01-05",
    journal = "Journal of Post-Modern Mysticisms",
    volume  = "14",
    number  = "3",
    pages   = "342--351"
  }

  @book{abook,
    author    = "An Other Auther",
    title     = "Something Really Important",
    date      = "2017-06-01",
    publisher = "Addison-Wesley",
    address   = "Somewhere Town"
  }
\end{filecontents}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=date,  match=\regexp{^(2017-(0[5-9]|1[1-2])|2018-0[1-4])}, final]
      \step[fieldset=keywords, fieldvalue={,daterange}, append]
      \step[fieldsource=keywords, match=\regexp{\A,}, replace={}]
    }
  }
}

\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography[keyword=daterange]
\end{document}

相关内容