初始情况

初始情况

这个问题与这些问题相关,但范围有所扩大:

此外,我提交了一份BibLaTeX GitHub 存储库上的问题,我的问题已被重定向至此处。


正如上面提到的问题,我有一份使用 BibLaTeX 和 Biber 的拆分参考书目的文档。各个参考书目部分按名称、年份、标题 ( nyt) 排序,数字标签与引用样式一起使用numeric-comp。我还想实现按压缩数字升序对多个引用进行排序,例如[1, 3, 8--10]而不是[3, 9, 1, 10, 8]。从上述问题的解决方案中,我了解到这可以通过使用指令对 Biber 的参考书目条目进行预排序来实现\DeclareSourcemap

然而,这意味着必须定义两次拆分标准:一次在选项中\printbibliography,另一次在\DeclareSourcemap映射定义中。当使用单个关键字拆分书目时,这可能很容易。

与上述问题相反,我使用 指令定义的复杂过滤器来分离参考书目部分\defbibfilter。因此,我必须将这些过滤器转换为 的映射指令\DeclareSourcemap。这也许并非不可能,但需要付出很多努力,而且并非易事。

初始情况

请考虑以下 MWE(示例书目文件可在本文末尾找到):

\documentclass{article}
\usepackage[
    defernumbers=true,          % continuous numbering across bibliography sections
    sortcites=true,             % sort citations if multiple entry keys are passed
                                %   to a citation command, e.g. \cite{a,b,c}
    citestyle=numeric-comp      % compact variant of numeric, which prints a list
                                %   of more than two consecutive numbers as a range
]{biblatex}
\addbibresource{example.bib}

% to show the corresponding entry keys after the individual
% entries within the bibliography
\renewbibmacro{finentry}{\finentry\space\textbf{(\thefield{entrykey})}}

% eliminate paragraph indentation
\setlength{\parindent}{0em}

\begin{document}

    \textbf{Examples:}
    \begin{itemize}
        \item Multiple citations \cite{c,d,f,a,i,h} not sorted numerically ascending;
              should be \verb|[2--4, 8--10]|.
        \item Multiple citations \cite{d,f,a,i,h} not sorted numerically ascending;
              should be \verb|[2--4, 8, 10]|.
    \end{itemize}

    \section*{References}
    \nocite{*}

    \textbf{References with Keyword A}
    \printbibliography[heading=none, keyword={A}]

    \textbf{References with Keyword B}
    \printbibliography[heading=none, keyword={B}]

\end{document}

MWE #1 的编译输出

如您所见,引用标签未排序。

使用 `\DeclareSourcemap` 的解决方案

可以使用\DeclareSourcemap指令对 Biber 中的参考书目条目进行预排序,如上文中引用的问题答案中所述。这种预排序还可对多个引文中的引文标签进行所需的数字升序排序,如下所示:

\documentclass{article}
\usepackage[
    defernumbers=true,          % continuous numbering across bibliography sections
    sortcites=true,             % sort citations if multiple entry keys are passed
                                %   to a citation command, e.g. \cite{a,b,c}
    citestyle=numeric-comp      % compact variant of numeric, which prints a list
                                %   of more than two consecutive numbers as a range
]{biblatex}
\addbibresource{example.bib}

% to show the corresponding entry keys after the individual
% entries within the bibliography
\renewbibmacro{finentry}{\finentry\space\textbf{(\thefield{entrykey})}}

% eliminate paragraph indentation
\setlength{\parindent}{0em}

% presorting of the bibliography entries with Biber
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=keywords, match={A}, final]
      \step[fieldset=presort, fieldvalue = {A}]
    }
    \map{
      \step[fieldset=presort, fieldvalue = {B}]
    }
  }
}

\begin{document}

    \textbf{Examples:}
    \begin{itemize}
        \item Multiple citations \cite{c,d,f,a,i,h} sorted numerically ascending and
          compressed; expectation \verb|[2--4, 8--10]| met.
        \item Multiple citations \cite{d,f,a,i,h} sorted numerically ascending and
          compressed; expectation \verb|[2--4, 8, 10]| met.
    \end{itemize}

    \section*{References}
    \nocite{*}

    \textbf{References with Keyword A}
    \printbibliography[heading=none, keyword={A}]

    \textbf{References with Keyword B}
    \printbibliography[heading=none, keyword={B}]

\end{document}

MWE #2 的编译输出

参考书目过滤器的情况

如上例所示,一种解决方法是使用\DeclareSourcemap。但是,这意味着要再次实施过滤标准。当使用 的复杂书目过滤器时,情况会变得更糟\defbibfilter。以下 MWE 中的过滤器故意保持简单 --- 我知道这也可以通过 的标准选项实现\printbibliography;它只是为了说明。

\documentclass{article}
\usepackage[
    defernumbers=true,          % continuous numbering across bibliography sections
    sortcites=true,             % sort citations if multiple entry keys are passed
                                %   to a citation command, e.g. \cite{a,b,c}
    citestyle=numeric-comp      % compact variant of numeric, which prints a list
                                %   of more than two consecutive numbers as a range
]{biblatex}
\addbibresource{example.bib}

% to show the corresponding entry keys after the individual
% entries within the bibliography
\renewbibmacro{finentry}{\finentry\space\textbf{(\thefield{entrykey})}}

% eliminate paragraph indentation
\setlength{\parindent}{0em}

% definition of filters for splitting bibliographies
\defbibfilter{only-A}{ keyword={A} and not ( keyword={B} or keyword={C} ) }
\defbibfilter{A-and-C}{ keyword={A} and keyword={C} }

\begin{document}

    \textbf{Examples:}
    \begin{itemize}
        \item Multiple citations \cite{c,d,f,a,i,h} not sorted numerically ascending;
              should be \verb|[2--4, 8--10]|.
        \item Multiple citations \cite{d,f,a,i,h} not sorted numerically ascending;
              should be \verb|[2--4, 8, 10]|.
    \end{itemize}

    \section*{References}
    \nocite{*}

    \textbf{References only with Keyword A}
    \printbibliography[heading=none, filter={only-A}]

    \textbf{References with Keyword B}
    \printbibliography[heading=none, keyword={B}]

    \textbf{References with Keyword A and C}
    \printbibliography[heading=none, filter={A-and-C}]

\end{document}

MWE #3 的编译输出

同样,要使引文标签按数字排序,必须在\DeclareSourcemap指令中再次实现书目过滤器。这将加倍努力,并且是错误和不一致的潜在来源。对于复杂的过滤器,这也是一件不简单的事情。我现在的问题是:在这种情况下,是否存在其他方法可以按数字升序对引用标签进行排序,而无需在\DeclareSourcemap过滤器指令中重新实现参考书目过滤器?


BibTeX 数据库示例

@INPROCEEDINGS{a,
    author = {Kishore Papineni and Salim Roukos and Todd Ward and Wei-Jing Zhu},
    title = {BLEU: A method for automatic evaluation of machine translation},
    booktitle = {In Proceedings of the 40th Annual Meeting on Association for Computational Linguistics},
    year = {2002},
    pages = {311--318},
    keywords = {A, C}
}

@INPROCEEDINGS{b,
    author = {D D Clark},
    title = {The design philosophy of the DARPA internet protocols},
    booktitle = {in ACM SIGCOMM},
    year = {1988},
    pages = {106--114},
    keywords = {B}
}

@INPROCEEDINGS{c,
    author = {Muthu Muthukrishnan},
    title = {Data Streams: Algorithms and Applications},
    booktitle = {of Foundations and Trends in Theoretical Computer Science. Now Publishers Inc},
    year = {2005},
    keywords = {B}
}

@ARTICLE{d,
    author = {R Koenker and G Basset},
    title = {Regression Quantiles},
    journal = {Eco- nometrica},
    year = {1978},
    number = {46},
    pages = {33--50},
    keywords = {A}
}

@MISC{e,
    author = {Michael Wilkinson Institute and Michael H. F. Wilkinson},
    title = {FIRST PUBLISHED IN ANNALS OF IMPROBABLE RESEARCH, VOL. 8, NO. 4, PP. 6-7 1 Zero-Tolerance Math: A Defense of "No Math"},
    year = {},
    keywords = {B}
}

@ARTICLE{f,
    author = {R M Neal},
    title = {Markov chain sampling methods for dirichlet process mixture models},
    journal = {Journal of Computational and Graphical Statistics},
    year = {2000},
    number = {9},
    pages = {249--265},
    keywords = {A, C}
}

@ARTICLE{g,
    author = {K P Birman},
    title = {The process group approach to reliable distributed computing},
    journal = {Communications of the ACM},
    year = {1993},
    number = {36},
    pages = {37--53},
    keywords = {A}
}

@ARTICLE{h,
    author = {Joxan Jaffar and Michael J Maher},
    title = {Constraint logic programming: A survey},
    journal = {Journal of Logic Programming},
    year = {1994},
    number = {19},
    pages = {581},
    keywords = {B}
}

@INPROCEEDINGS{i,
    author = {M J Wainwright and M I Jordan},
    title = {Graphical models, exponential families, and variational inference},
    booktitle = {Foundations and Trends R© in Machine Learning},
    year = {2008},
    keywords = {B}
}

@MISC{j,
    author = {K Train},
    title = {Discrete choice methods with simulation},
    year = {2003},
    keywords = {A}
}

答案1

通过您的示例,可以在没有源映射的情况下获得想要的结果(请确保在尝试之前删除旧的辅助文件,并在 biber 之后至少编译两次):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[
    defernumbers=true,          % continuous numbering across bibliography sections
    sortcites=true,             % sort citations if multiple entry keys are passed
                                %   to a citation command, e.g. \cite{a,b,c}
    citestyle=numeric-comp      % compact variant of numeric, which prints a list
                                %   of more than two consecutive numbers as a range
]{biblatex}
\addbibresource{example.bib}

% to show the corresponding entry keys after the individual
% entries within the bibliography
\renewbibmacro{finentry}{\finentry\space\textbf{(\thefield{entrykey})}}

\makeatletter
\AtEveryBibitem{\immediate\write\@mainaux{\string\listxadd\string\mynewsortbiblist{\string\detokenize{\thefield{entrykey}}}}}
\AtBeginDocument{\ifundef\mynewsortbiblist{}{\cslet{blx@slist@centry@\the\c@refsection @\blx@refcontext@context}\mynewsortbiblist}}
\makeatother

\begin{document}
    \textbf{Examples:}
    \begin{itemize}
        \item Multiple citations \cite{c,d,f,a,i,h}  not sorted numerically ascending;
              should be \verb|[2--4, 8--10]|.
        \item Multiple citations \cite{d,f,a,i,h} not sorted numerically ascending;
              should be \verb|[2--4, 8, 10]|.
    \end{itemize}

    \section*{References}
    \nocite{*}

    \textbf{References with Keyword A}
    \printbibliography[heading=none, keyword={A}]

    \textbf{References with Keyword B}
    \printbibliography[heading=none, keyword={B}]


\end{document}

在此处输入图片描述

注意力!

还有一些悬而未决的问题

  • 它目前只适用于一个 refsection 和 refcontext(因为我实际上不知道多个 refsection 和 refcontext 的结果会是什么)。
  • 我没有尝试如果一个 bib 条目出现在多个参考书目中会发生什么(我现在尝试过,结果毫无意义,因此需要添加一些代码以避免重复)。

在此处输入图片描述

  • 我没有尝试如果印刷书目中缺少 bib 条目会发生什么

相关内容