1

I need to create a bibliography where journal articles within a volume and issue are sorted by the first page number. I can use \mkfirstpage{pages} to print the first page of the page range but cannot sort the list by first page. Here is a MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}

\begin{filecontents}{library.bib}
@article{articleB,
    author  = {AuthorBLast, AuthorBFirst},
    title   = {TitleB},
    journal = {Journal},
    volume  = {1},
    issue   = {1},
    pages   = {1-6}
}
@article{articleA,
    author  = {AuthorAlast, AuthorAFirst},
    title   = {TitleA},
    journal = {Journal},
    volume  = {1},
    issue   = {1},
    pages   = {13-25}
}
@article{articleC,
    author  = {AuthorCLast, AuthorCFirst},
    title   = {TitleC},
    journal = {Journal},
    volume  = {1},
    issue   = {1},
    pages   = {7-12}
}
\end{filecontents}

\usepackage[%
    backend=biber,
    sorting=nty,
]{biblatex}
\addbibresource{library.bib}

\begin{document}
\nocite{*}

\printbibliography[title=Bibliography]
\end{document}

This produces the following:

What I get

I would like to get

What I need

I have spent a lot of time with \DeclareSortingTemplate with no success. Thanks for help, guidance and pointers in advance.

0

\mkfirstpage is a biblatex-side command, but sorting happens at the Biber side of things where this command is not available. This means we need to recreate what \mkfirstpage does within Biber.

In the source map we extract only the first page from the range and write it into a temporary field for sorting. The example uses usera, but one could also define a dedicated field in a new data model.

The sorting template then uses usera and pads its value so the number sorts as expected.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[%
  backend=biber,
]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=pages, final]
      \step[fieldset=usera, origfieldval]
      \step[fieldsource=usera,
        match=\regexp{\A\s*(\p{Nd}+)\s*(\p{Pd}+)\s*(\p{Nd}+)\s*\z},
        replace=\regexp{$1}]
    }
  }
}

\DeclareSortingTemplate{jyvnp}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{journaltitle}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{volume}
    \literal{0}
  }
  \sort{
    \field{number}
    \literal{0}
  }
  \sort{
    \field[padwidth=9]{usera}
    \literal{0}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
}

\ExecuteBibliographyOptions{sorting=jyvnp}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{articleB,
  author  = {AuthorBLast, AuthorBFirst},
  title   = {TitleB},
  journal = {Journal},
  year    = {2001},
  volume  = {1},
  number  = {1},
  pages   = {1-6},
}
@article{articleA,
  author  = {AuthorAlast, AuthorAFirst},
  title   = {TitleA},
  journal = {Journal},
  year    = {2001},
  volume  = {1},
  number  = {1},
  pages   = {13-25},
}
@article{articleC,
  author  = {AuthorCLast, AuthorCFirst},
  title   = {TitleC},
  journal = {Journal},
  year    = {2001},
  volume  = {1},
  number  = {1},
  pages   = {7-12},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}

\printbibliography[title=\bibname]
\end{document}

AuthorBFirst AuthorBLast. “TitleB”. In: Journal 1.1 (2001), pp. 1–6.

AuthorCFirst AuthorCLast. “TitleC”. In: Journal 1.1 (2001), pp. 7–12.

AuthorAFirst AuthorAlast. “TitleA”. In: Journal 1.1 (2001), pp. 13–25.

  • Beautiful. I had tried DeclareSourcemap but had no idea how to accomplish what you did with match and replace. I implemented your solution on my production mode file and it works well. Thank you! I am still learning about posting comments. Thanks to everyone for bearing with a novice. I also need to learn how to award badges. – Ravi Apr 21 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.