我有一个主要来源,并分析了它的参考文献(参考文献在哪些页面上被引用,就像手工backref
工作一样)。我为此创建了一个新库(就像几个世纪前作者使用 LaTeX 时所做的那样),并添加了一个自定义字段,citedonpages
其中包含手动发现的页面。
我想打印这些分析的数据(例如,将其显示在表格中)。是否可以使用biblatex/biber
处理其他字段(在本例citedonpages
中如中所述citedonpages.dbx
)来
- 打印每个条目的列表
- 并计算逗号分隔的条目数?
我尝试跟随https://tex.stackexchange.com/a/163396/4419但命令\printfield{citedonpages}
不起作用。
我如何访问(打印)该citedonpages
字段以及如何计算逗号分隔值的条目数?由于实际库有许多条目,因此自动化解决方案将非常有用(最好完全在 LaTeX 中)。
MWE(作为使用 biblatex/biber 根据引用创建表,并以自定义字段作为列):
\documentclass{scrbook}
\begin{filecontents*}{citedonpages.dbx}
\ProvidesFile{citedonpages.dbx}[2021/07/27 add citedonpages field to biblatex data model]
\DeclareDatamodelFields[type=field,datatype=literal]{citedonpages} %comma seperated list of values
\DeclareDatamodelEntryfields{citedonpages}
\end{filecontents*}
\begin{filecontents*}{Analysis.bib}
@Book{Miller1832a,
author = {John Miller},
title = {Elementary book},
year = {1832},
citedonpages = {67,68,97},
}
@InBook{Smith1744a,
author = {Daniel Smith},
booktitle = {Collection of important articles},
location = {Amsterdam},
title = {Noteworthy Article},
year = {1744},
citedonpages = {5, 23, 37, 79, 248, 249, 254},
}
\end{filecontents*}
%\addbibresource{Analysis.bib}
\usepackage{longtable,array}
\usepackage{booktabs,lipsum,tabularx}
\usepackage[backend=biber,datamodel=citedonpages,style=authortitle]{biblatex}
\usepackage{biblatex-ext-tabular}
\DeclareFieldFormat{citedonpages}{\bibstring{citedonpages}\space #1}
\defbibtabular{bibtabular}
{\renewbibmacro*{bbx:dashcheck}[2]{##2}%
\begin{longtable}{@{}llccl@{}}
\toprule
\textbf{Author} & \textbf{Title} & \textbf{Year} & \textbf{\# Citations} & \dots\ on pages\\
\midrule}
{\bottomrule
\end{longtable}}
{\anchorlang{\usebibmacro{author/editor+others}}
& \plainlang{\usebibmacro{title}}
& \plainlang{\printdate}
& 0 % how to display counter
& \printfield{citedonpages}
\\}
\begin{document}
\begin{refsection}[Analysis.bib]
\nocite{*}
\printbibliography[heading=none]
\end{refsection}
\textbf{Ideally, it should output something like:}\\
Miller, John. \textit{Elementary book}. 1832. (cited 3 times on pages 67, 68, 97)\\
Smith, Daniel. “Noteworthy Article”. In: \textit{Collection of important articles}. Amsterdam,
1744. (cited 7 times on pages 5, 23, 37, 79, 248, 249, 254)
\vspace{1cm}\textbf{Version with table} (added manually):
\begin{tabularx}{0.95\textwidth}{llccX}
\toprule
{\bfseries Author} & {\bfseries Title} & {\bfseries Year} & {\bfseries \# Citations} & ... on pages \\\midrule%\otoprule
Miller, John & Elementary book & 1832 & 3 & 67, 68, 97\\
Smith, Daniel & "Noteworthy article" & 1744 & 7 & 5, 23, 37, 79, 248, 249, 254 \\
\bottomrule
\end{tabularx}
\vspace{1cm}\textbf{Version with table} (autogenerated, but entries are missing):
\begin{refsection}[Analysis.bib]
\nocite{*}
\printbibtabular[heading=none]
\end{refsection}
\end{document}
答案1
我们可以使用expl3
代码读取页码列表,删除重复的数字并计算页数。
这可以在 中完成,因此当从文件中读取\DeclareFieldInputHandler
字段时就会发生这种情况。从 开始,包含格式良好的页面列表(没有重复)。citedonpages
.bbl
citedonpages
剩余的代码几乎可以详细地从使用 biblatex/biber 根据引用创建表,并以自定义字段作为列,我们只需要打印我们的citedonpages
字段而不是列表biblatex
pageref
。
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}
\begin{filecontents*}{citedonpages.dbx}
\ProvidesFile{citedonpages.dbx}[2021/07/27 add citedonpages field to biblatex data model]
\DeclareDatamodelFields[type=field, datatype=literal]{citedonpages}
\DeclareDatamodelEntryfields{citedonpages}
\end{filecontents*}
\usepackage[backend=biber, style=authoryear, datamodel=citedonpages]{biblatex}
\usepackage{biblatex-ext-tabular}
\makeatletter
\ExplSyntaxOn
\clist_new:N \l__kromuchiblx_citedonpages_clist
\DeclareFieldInputHandler{citedonpages}
{
\clist_set:Nn \l__kromuchiblx_citedonpages_clist {#1}
% remove duplicates, if you want the duplicates counted,
% move this line *after* the citecount definition
\clist_remove_duplicates:N \l__kromuchiblx_citedonpages_clist
% writing a new field *while* we are processing another
% is a bit risky, ...
\blx@bbl@fieldedef{citecount}{\clist_count:N \l__kromuchiblx_citedonpages_clist}
% ... but works if we make sure *we* write \NewValue
\edef\NewValue{\clist_use:Nn \l__kromuchiblx_citedonpages_clist {,~}}
}
\ExplSyntaxOff
\makeatother
\usepackage{longtable}
\usepackage{array}
\usepackage{booktabs}
\newcolumntype{L}[1]{%
>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{%
>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newbibmacro*{tablepageref}{%
\printfield{citedonpages}}
\renewbibmacro*{pageref}{}
\defbibtabular{bibtabular}
{\renewbibmacro*{bbx:dashcheck}[2]{##2}%
\renewbibmacro*{labeltitle}{}%
\renewbibmacro*{date+extradate}{}%
\setlength{\LTpre}{0pt}%
\setlength{\LTpost}{0pt}%
\renewcommand*{\arraystretch}{2}%
\begin{longtable}{%
@{}
L{\dimexpr0.2\textwidth-1\tabcolsep\relax}
L{\dimexpr0.25\textwidth-2\tabcolsep\relax}
L{\dimexpr0.12\textwidth-2\tabcolsep\relax}
L{\dimexpr0.22\textwidth-2\tabcolsep\relax}
L{\dimexpr0.21\textwidth-1\tabcolsep\relax}
@{}}
\toprule
\textbf{Author} & \textbf{Title} & \textbf{Year} & \textbf{\# Citations} & \dots\ on pages\\
\midrule}
{\bottomrule
\end{longtable}}
{\anchorlang{\usebibmacro{author/editor+others}}
& \plainlang{\usebibmacro{title}}
& \plainlang{\printdate}
& \plainlang{\printfield{citecount}}
& \plainlang{\usebibmacro{tablepageref}} \\}
\begin{filecontents*}{\jobname.bib}
@Book{Miller1832a,
author = {John Miller},
title = {Elementary book},
year = {1832},
citedonpages = {67,67,68,97,67},
}
@inbook{Smith1744a,
author = {Daniel Smith},
booktitle = {Collection of important articles},
location = {Amsterdam},
title = {Noteworthy Article},
year = {1744},
citedonpages = {5, 23, 37, 79, 248, 249, 254},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibtabular[title=Analysis]
\end{document}