0

This issue is related to this other issue.

In my custom entrytype I use two alternate fields: author (names of persons) and usera (names of institutions).

In any pre-existing sorting template (e.g. nty, anyvt, etc.), the usera field must be handled as if it were an author/editor field.

So, without having/wanting to create a custom sorting template, I thought of using the sortname field, through sourcemapping.

% !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}

The sourcemapping code should be equivalent to the following .bib file:

@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},
}

but the ordering is not as expected.

1 Answers1

0

Escaping the curly braces in a way that retains them for the sourcemap operation can be a bit painful. I found that the following works as expected.

\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}

A Z. Title. 1000.
Doe, Jane. Title. 4000.
M M. Title. 3000.
Smith, John. Title. 2000.

moewe
  • 175,683