此问题与另一个问题。
在我的自定义条目类型中,我使用了两个备用字段:(author
人名)和usera
(机构名称)。
在任何预先存在的排序模板(例如 nty、anyvt 等)中,都usera
必须将该字段视为author
/editor
字段进行处理。
因此,在没有/不想创建自定义排序模板的情况下,我想到sortname
通过源映射使用该字段。
% !TEX encoding = UTF-8 Unicode
% !TEX program = lualatex
% !BIB program = biber
\begin{filecontents}{\jobname.bib}
@customa{a,
author = {Smith, John},
title = {Title},
date = {2000},
}
@customa{b,
usera = {M M},
title = {Title},
date = {3000},
}
@customa{c,
usera = {A Z},
title = {Title},
date = {1000},
}
@customa{d,
author = {Doe, Jane},
title = {Title},
date = {4000},
}
\end{filecontents}
\documentclass{article}
\usepackage[style=authortitle]{biblatex}
\addbibresource{\jobname.bib}
\DeclareSourcemap{
\maps{
\map{
\pertype{customa}
\step[fieldsource=usera, match=\regexp{\A(.*)\Z}, final]
\step[fieldset=sortname, fieldvalue={\{$1\}}]
}
}
}
\DeclareBibliographyDriver{customa}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\printfield{usera}%
\printnames{author}%
\newunit\newblock
\usebibmacro{title}%
\newunit\newblock
\printdate%
\usebibmacro{finentry}}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
源映射代码应等同于以下.bib 文件:
@customa{a,
author = {Smith, John},
title = {Title},
date = {2000},
}
@customa{b,
usera = {M M},
title = {Title},
date = {3000},
sortname = {{M M}},
}
@customa{c,
usera = {A Z},
title = {Title},
date = {1000},
sortname = {{A Z}},
}
@customa{d,
author = {Doe, Jane},
title = {Title},
date = {4000},
}
但排序并不像预期的那样。
答案1
以保留花括号的方式将其转义以进行源映射操作可能会有点麻烦。我发现下面的操作按预期工作。
\documentclass{article}
\usepackage[style=authortitle]{biblatex}
\DeclareSourcemap{
\maps{
\map{
\pertype{customa}
\step[fieldsource=usera, match=\regexp{\A(.*)\Z}, final]
\step[fieldset=sortname, fieldvalue=\regexp{{$1}}]
}
}
}
\DeclareBibliographyDriver{customa}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\printfield{usera}%
\printnames{author}%
\newunit\newblock
\usebibmacro{title}%
\newunit\newblock
\printdate%
\usebibmacro{finentry}}
\begin{filecontents}{\jobname.bib}
@customa{a,
author = {Smith, John},
title = {Title},
date = {2000},
}
@customa{b,
usera = {M M},
title = {Title},
date = {3000},
}
@customa{c,
usera = {A Z},
title = {Title},
date = {1000},
}
@customa{d,
author = {Doe, Jane},
title = {Title},
date = {4000},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}