计算 biblatex 中每个引用部分内的条目数

计算 biblatex 中每个引用部分内的条目数

我正在用 LaTeX 格式化我的出版物。以下是主文件的内容:

\documentclass{article}
\usepackage[style=alphabetic]{biblatex}
\addbibresource{publications.bib}

\begin{document}
\section{Publications}
\subsection{Journal Articles (1)}
\begin{refsection}
  \nocite{journal1}
  \printbibliography[heading=none]
\end{refsection}

\subsection{Conference Articles (3)}
\begin{refsection}
  \nocite{conference1}
  \nocite{conference2}
  \nocite{conference3}
  \printbibliography[heading=none]
\end{refsection}
\end{document}

以下是参考书目的样本:

@article{journal1,
  author  = {Author 1},
  title   = {Title 1},
  journal = {Journal 1},
  year    = 1993,
  number  = 2,
  pages   = {201-213},
  month   = 7,
  volume  = 4
}
@inproceedings{conference1,
  title        = {Title 1},
  year         = 1993,
  author       = {Author 1},
  volume       = 4,
  series       = 5,
  address      = {Address 1},
  month        = 7,
  organization = {Organization 1},
  publisher    = {Publisher 1},
}
@inproceedings{conference2,
  title        = {Title 2},
  year         = 1993,
  author       = {Author 2},
  volume       = 4,
  series       = 5,
  address      = {Address 2},
  month        = 7,
  organization = {Organization 2},
  publisher    = {Publisher 2},
}
@inproceedings{conference3,
  title        = {Title 3},
  year         = 1993,
  author       = {Author 3},
  volume       = 4,
  series       = 5,
  address      = {Address 3},
  month        = 7,
  organization = {Organization 3},
  publisher    = {Publisher 3},
}

此代码生成以下 PDF:

在此处输入图片描述

请注意,我已经手动提到了\subsection{Journal Articles (1)}\subsection{Conference Articles (3)}

计算每个条目数量的好方法是什么refsection

答案1

refsection您可以通过挂接到 来计算每个条目的数量\AtDataInput。在此解决方案中,我们为每个部分创建一个计数器。\refsectionbibcount只是一个方便的钩子,用于检索当前 的计数器refsection。请注意,此解决方案要求对标题进行排版里面相关的refsection,但这在这里没有问题。

\documentclass{article}
\usepackage[style=alphabetic]{biblatex}

\makeatletter
\AtDataInput{%
  \ifltxcounter{datacount@\the\c@refsection}
    {}
    {\newcounter{datacount@\the\c@refsection}}%
  \stepcounter{datacount@\the\c@refsection}}

\newcommand*{\refsectionbibcount}{\arabic{datacount@\the\c@refsection}}
\makeatother

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{journal1,
  author  = {Author 1},
  title   = {Title 1},
  journal = {Journal 1},
  year    = 1993,
  number  = 2,
  pages   = {201-213},
  month   = 7,
  volume  = 4
}
@inproceedings{conference1,
  title        = {Title 1},
  year         = 1993,
  author       = {Author 1},
  volume       = 4,
  series       = 5,
  address      = {Address 1},
  month        = 7,
  organization = {Organization 1},
  publisher    = {Publisher 1},
}
@inproceedings{conference2,
  title        = {Title 2},
  year         = 1993,
  author       = {Author 2},
  volume       = 4,
  series       = 5,
  address      = {Address 2},
  month        = 7,
  organization = {Organization 2},
  publisher    = {Publisher 2},
}
@inproceedings{conference3,
  title        = {Title 3},
  year         = 1993,
  author       = {Author 3},
  volume       = 4,
  series       = 5,
  address      = {Address 3},
  month        = 7,
  organization = {Organization 3},
  publisher    = {Publisher 3},
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
\printbibheading[heading=bibnumbered, title=Publications]
\begin{refsection}
  \nocite{journal1}
  \printbibliography[heading=subbibnumbered, title={Journal Articles (\refsectionbibcount)}]
\end{refsection}
\begin{refsection}
  \nocite{conference1}
  \nocite{conference2}
  \nocite{conference3}
  \printbibliography[heading=subbibnumbered, title={Conference Articles (\refsectionbibcount)}]
\end{refsection}
\end{document}

按标题中的条目数拆分参考书目(按类型)


您的用例看起来好像您试图按条目类型而不是按 进行计数refsection,这也是可能的。由于您可以按类型拆分参考书目而不必诉诸于 ,因此refsections这里的情况稍微简单一些。

\documentclass{article}
\usepackage[style=alphabetic]{biblatex}

\makeatletter
\AtDataInput{%
  \ifltxcounter{entrycount@\thefield{entrytype}}
    {}
    {\newcounter{entrycount@\thefield{entrytype}}}%
  \stepcounter{entrycount@\thefield{entrytype}}}

\newcommand*{\entrycount}[1]{\arabic{entrycount@#1}}

\newcommand*{\printtypebib}[2]{%
  \printbibliography[type=#1, title={#2 (\entrycount{#1})},
    heading=subbibnumbered]
}
\makeatother

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{journal1,
  author  = {Author 1},
  title   = {Title 1},
  journal = {Journal 1},
  year    = 1993,
  number  = 2,
  pages   = {201-213},
  month   = 7,
  volume  = 4
}
@inproceedings{conference1,
  title        = {Title 1},
  year         = 1993,
  author       = {Author 1},
  volume       = 4,
  series       = 5,
  address      = {Address 1},
  month        = 7,
  organization = {Organization 1},
  publisher    = {Publisher 1},
}
@inproceedings{conference2,
  title        = {Title 2},
  year         = 1993,
  author       = {Author 2},
  volume       = 4,
  series       = 5,
  address      = {Address 2},
  month        = 7,
  organization = {Organization 2},
  publisher    = {Publisher 2},
}
@inproceedings{conference3,
  title        = {Title 3},
  year         = 1993,
  author       = {Author 3},
  volume       = 4,
  series       = 5,
  address      = {Address 3},
  month        = 7,
  organization = {Organization 3},
  publisher    = {Publisher 3},
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibheading[heading=bibnumbered, title=Publications]
\printtypebib{article}{Journal Articles}
\printtypebib{inproceedings}{Conference Articles}
\end{document}

按标题中的条目数拆分参考书目(按类型)


请注意,由于我们\AtDataInput在两种解决方案中都使用了,因此如果参考书目通过其他标准进行过滤,或者其中某些条目.bbl被排除在参考书目之外,则计数可能会出错。应该可以防范这些情况,但需要发生什么可能取决于当前的情况。

答案2

有一个可爱的xcntperchap软件包可以做到这一点:

\documentclass{article}
\usepackage[style=alphabetic]{biblatex}
\addbibresource{publications.bib}

\usepackage{filecontents}
\begin{filecontents*}{publications.bib}
@article{journal1,
  author  = {Author 1},
  title   = {Title 1},
  journal = {Journal 1},
  year    = 1993,
  number  = 2,
  pages   = {201-213},
  month   = 7,
  volume  = 4
}
@inproceedings{conference1,
  title        = {Title 1},
  year         = 1993,
  author       = {Author 1},
  volume       = 4,
  series       = 5,
  address      = {Address 1},
  month        = 7,
  organization = {Organization 1},
  publisher    = {Publisher 1},
}
@inproceedings{conference2,
  title        = {Title 2},
  year         = 1993,
  author       = {Author 2},
  volume       = 4,
  series       = 5,
  address      = {Address 2},
  month        = 7,
  organization = {Organization 2},
  publisher    = {Publisher 2},
}
@inproceedings{conference3,
  title        = {Title 3},
  year         = 1993,
  author       = {Author 3},
  volume       = 4,
  series       = 5,
  address      = {Address 3},
  month        = 7,
  organization = {Organization 3},
  publisher    = {Publisher 3},
}
\end{filecontents*}

\newcounter{foo}
\renewbibmacro*{finentry}{\stepcounter{foo}\finentry}
\usepackage{xcntperchap}
\RegisterTrackCounter{subsection}{foo}

\begin{document}
\section{Publications}
\subsection{Journal Articles (\ObtainTrackedValueExp{subsection}{foo})}
\begin{refsection}
    \setcounter{foo}{0}
  \nocite{journal1}
  \printbibliography[heading=none]
\end{refsection}

\subsection{Conference Articles (\ObtainTrackedValueExp{subsection}{foo})}
\begin{refsection}
    \setcounter{foo}{0}
  \nocite{conference1}
  \nocite{conference2}
  \nocite{conference3}
  \printbibliography[heading=none]
\end{refsection}
\end{document}

在此处输入图片描述

相关内容