1

I need to switch a project to Overleaf. I'm using biblatex and Biber, and I use \DeclareSortingTemplate to create a separate bibliography environment that's sorted by shorthand instead of author.

Is there a special package I need or....?

Minimal example that works in my regular setup but not on Overleaf:

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

\usepackage{filecontents}
\begin{filecontents}{example.bib}
@book{test,
  title      = {A Title},
  year       = {2420},
  author     = {Famous, Person},
  location      = {Big City},
  publisher  = {Fancy Academic Press},
  shorthand  = {b2420},
}
\end{filecontents}

\usepackage[backend=biber,style=authoryear]{biblatex}
\addbibresource{example.bib}

% special sort style
\DeclareSortingTemplate{byShorthand}{
  \sort{\field{shorthand}}
  \sort{\field{name}}
  \sort{\field{year}}
  \sort{\field{title}}
}

\begin{document}
I want to cite \cite{test}

\newrefcontext[sorting=byShorthand]
\printbibliography[title={Bibliography sorted by shorthand}]

\newrefcontext[sorting=nyt]
\printbibliography[title={Bibliography sorted by author}]
\end{document}
  • 2
    (I'm on support staff at Overleaf.) New projects on Overleaf are currently created using TeX Live 2017, which includes an older version of biblatex than you're likely using. On TL2017, you should use \DeclareSortingScheme instead of \DeclareSortingTemplate. The syntax is the same, this macro was simply renamed in more recent versions of biblatex. – Paul Gessler Apr 18 at 20:03
  • 1
    There is a predefined sorting template/scheme called shorthand that sorts only by shorthand and not by name, title and year. So you could just use \newrefcontext[sorting=shorthand] and no \DeclareSortingTemplate at all. The difference should be negligible unless you use the same shorthand twice (which you probably shouldn't). Note that \field{name} is not a valid sorting rule anyway, since there is no field called name. – moewe Apr 19 at 5:16
  • Actually \field{name} is sort of valid in the current version of Biber (see github.com/plk/biber/issues/262), it just does not do something extremely useful. Unless there is a field called name it will behave like \literal{name}. But since it is in a \sort{...} of its own that means it could be omitted since all entries will have the "name" string in their sort specification. – moewe Apr 29 at 15:31
1

Based on Paul's comment above, I was able to fix this issue by using the (now deprecated) \DeclareSortingScheme (biblatex version <3.8) instead of \DeclareSortingTemplate (biblatex >= 3.8). As of this post, Overleaf uses TeX Live 2017 with biblatex 3.7 (2016/12/05) for new projects.

Working example:

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

\usepackage{filecontents}
\begin{filecontents}{example.bib}
@book{test,
  title      = {A Title},
  year       = {2420},
  author     = {Famous, Person},
  location      = {Big City},
  publisher  = {Fancy Academic Press},
  shorthand  = {b2420},
}
@book2{test2,
  title      = {A Title},
  year       = {2420},
  author     = {Author, Person},
  location      = {Big City},
  publisher  = {Fancy Academic Press},
  shorthand  = {c2420},
}
\end{filecontents}

\usepackage[backend=biber,style=authoryear]{biblatex}
\addbibresource{example.bib}

% special sort style
\DeclareSortingScheme{byShorthand}{
  \sort{\field{shorthand}}
  \sort{\field{name}}
  \sort{\field{year}}
  \sort{\field{title}}
}

\begin{document}
I want to cite \cite{test} and \cite{test2}

\newrefcontext[sorting=byShorthand]
\printbibliography[title={Bibliography sorted by shorthand}]

\newrefcontext[sorting=nyt]
\printbibliography[title={Bibliography sorted by author}]
\end{document}

Edit: Furthermore, as pointed out by moewe above, I can use the pre-defined "sorting=shorthand" option. A much sleeker approach!

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.