有没有办法生成一个表格,可以根据 bibtex 中的 @article、@proceedings 和其他类别提供计数?
答案1
biblatex
可以使用 的钩子轻松计算每种条目类型的条目数\AtDataInput
。然后从读取文件的那一刻起,数据即可使用.bbl
。如果您只想计算一个特定的条目,\printbibliography
则方法可能与 类似\AtEveryBibitem
。
代码为每个引用部分和类型创建一个计数器,用于计算该引用部分中该类型的条目数。每个类型的通用计数器都是根据当前引用部分的特定于引用部分的计数器定义的。
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear, backend=biber]{biblatex}
\usepackage{booktabs}
\addbibresource{biblatex-examples.bib}
\makeatletter
% generic counters: typecounter@article, ...
% will throw an error if Biber hasn't been run yet, so I'd avoid them
\def\do#1{%
\newcounter{typecounter@#1}%
\csdef{c@typecounter@#1}{%
\csname typecounter@\the\c@refsection @#1\endcsname}%
}
\abx@doentrytypes
% initialise refsection-specific counters
\def\init@typecounters#1{%
\def\do##1{%
\ifltxcounter{typecounter@#1@##1}
{}
{\newcounter{typecounter@#1@##1}}}%
\abx@doentrytypes}
% count entries of each type for this refsection
% \AtDataInput is executed once for every refsection
\AtDataInput{%
\ifcsundef{@processed@typecounters@\the\c@refsection}
{\init@typecounters{\the\c@refsection}%
\global\cslet{@processed@typecounters@\the\c@refsection}\@empty}
{}%
\stepcounter{typecounter@\the\c@refsection @\abx@field@entrytype}}
% produce a table
\newcommand*{\bibtypecounttable}{%
\let\@bibtypecounttable@collector\@empty
\def\do##1{%
\ifltxcounter{typecounter@\the\c@refsection @##1}
{\ifnum\value{typecounter@\the\c@refsection @##1}>0
\appto\@bibtypecounttable@collector{%
\ifcsundef{typecounter@name@##1}
{##1}
{\csuse{typecounter@name@##1}}
& \arabic{typecounter@\the\c@refsection @##1}\\}
\fi}
{}}
\abx@doentrytypes
\ifblank\@bibtypecounttable@collector
{}
{\begin{tabular}{lc}
\toprule
Type & Count \\
\midrule
\@bibtypecounttable@collector
\bottomrule
\end{tabular}}%
}
\makeatother
% custom names for the table can be defined with
% typecounter@name@<entrytype>
\csdef{typecounter@name@article}{Journal articles}
\begin{document}
\cite{sigfridsson,worman,geer,baez/article,companion}
\printbibliography
\begin{center}
\bibtypecounttable
\end{center}
\end{document}