7

With biblatex and Biber, is it possible to print all the bibliography (\printbibliography) from (let's say) 2003 to 2008 in one section? And then in another section print all the bibliography from 2009 to 2016?

1

4 Answers 4

9

This can be done with Biber's ability to dynamically rewrite bibliographical information using regular expressions. This example prints only the entries in the range 2003--2008 and 2009--2015 even though the document cites all entries, which range from 2001 to 2016.

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}

@Article{a,
  date =     2001,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{b,
  date =     2003,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{c,
  date =     2005,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{d,
  date =     2007,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{e,
  date =     2009,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{f,
  date =     2011,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{g,
  date =     2013,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{h,
  date =     2015,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{i,
  date =     2016,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

\end{filecontents*}

\usepackage[backend=biber]{biblatex}
\addbibresource{\jobname.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=date,  match=\regexp{200([3-8])}, %
            fieldset=keywords, fieldvalue={ONE}, append, ]
      \step[fieldsource=date,  match=\regexp{(2009|201[0-5])}, %
            fieldset=keywords, fieldvalue={TWO}, append, ]
}}}

\begin{document}
\nocite{*}

\printbibliography[keyword=ONE, title={Group One (2003--2008)}]

\printbibliography[keyword=TWO, title={Group Two (2009--2015)}]

\end{document}
0
6

The simplest way is to define two checks with the conditions for the years

\defbibcheck{old}{
  \ifnumless{\thefield{year}}{2003}
    {\skipentry}
    {\ifnumgreater{\thefield{year}}{2008}
      {\skipentry}
      {}
    }
}

\defbibcheck{new}{
  \ifnumless{\thefield{year}}{2009}
    {\skipentry}
    {\ifnumgreater{\thefield{year}}{2016}
      {\skipentry}
      {}
    }
}

and then use the check option of \printbibliography`, namelly:

\printbibliography[check=old, title={2003--2008}]

\printbibliography[check=new, title={2009-2016}]
3
  • Ohhh, you beat me by fourty seconds or so.
    – moewe
    Commented Dec 30, 2016 at 7:23
  • 1
    @moewe not putting \iffieldint{year} saved me the 40 seconds :-)
    – Guido
    Commented Dec 30, 2016 at 7:25
  • 1
    Oh, this is good too. Never noticed the \defbibcheck command before.... (+1 for both)
    – jon
    Commented Dec 30, 2016 at 19:04
5

jon's answer with Biber's regex is brilliant, but you can also use bibchecks from within the document. We just need to compare years with etoolbox's facilities. Unfortunately we have only < and >, so our checks will look like this

\defbibcheck{yrs0308}{%
  \iffieldint{year}
    {\ifboolexpr{test {\ifnumgreater{\thefield{year}}{2002}} and test {\ifnumless{\thefield{year}}{2009}}}
      {}
      {\skipentry}}
    {\skipentry}}

\defbibcheck{yrs1015}{%
  \iffieldint{year}
    {\ifboolexpr{test {\ifnumgreater{\thefield{year}}{2009}} and test {\ifnumless{\thefield{year}}{2016}}}
      {}
      {\skipentry}}
    {\skipentry}}

Full MWE (adapted from jon's)

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}

@Article{a,
  date =     2001,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{b,
  date =     2003,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{c,
  date =     2005,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{d,
  date =     2007,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{e,
  date =     2009,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{f,
  date =     2011,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{g,
  date =     2013,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{h,
  date =     2015,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

@Article{i,
  date =     2016,
  author =   {Author, Amy},
  title =    {Title},
  journaltitle = {Journal},
  volume =   10,
  number =   4,
  pages =    {100-141}}

\end{filecontents*}

\usepackage[backend=biber]{biblatex}
\addbibresource{\jobname.bib}

\defbibcheck{yrs0308}{%
  \iffieldint{year}
    {\ifboolexpr{test {\ifnumgreater{\thefield{year}}{2002}} and test {\ifnumless{\thefield{year}}{2009}}}
      {}
      {\skipentry}}
    {\skipentry}}

\defbibcheck{yrs1015}{%
  \iffieldint{year}
    {\ifboolexpr{test {\ifnumgreater{\thefield{year}}{2009}} and test {\ifnumless{\thefield{year}}{2016}}}
      {}
      {\skipentry}}
    {\skipentry}}


\begin{document}
\nocite{*}

\printbibliography[check=yrs0308, title={Group One (2003--2008)}]
\printbibliography[check=yrs1015, title={Group Two (2009--2015)}]
\end{document}
-1

Thank you very much. It helped me a lot. However, I had to change the code a little bit to make it work. Probably because I had another \map (???) ... I don't understand everything and the doc of biblatex is quite heavy!

\DeclareSourcemap{
 \maps[datatype=bibtex]{
  \map[overwrite=true]{
        \step[fieldsource=author, match=myself, final]
        \step[fieldset=keywords, fieldvalue={,}, append]
        \step[fieldset=keywords, fieldvalue=own, append]
}
     \map[overwrite=true]{
        \step[fieldsource=year,  match=\regexp{200([3-8])},final]
        \step[fieldset=keywords, fieldvalue={,}, append]
    \step[fieldset=keywords, fieldvalue=ONE, append]
}
     \map[overwrite=true]{
        \step[fieldsource=year,  match=\regexp{(2009|201[0-5])},final]
        \step[fieldset=keywords, fieldvalue={,}, append]
        \step[fieldset=keywords, fieldvalue={TWO}, append]
}}}
\printbibliography[keyword=own,type=article,heading=none,resetnumbers=true,keyword=ONE]

Could you please, @jon, clarify what does "final" stand for? Why was the line

\step[fieldset=keywords, fieldvalue={,}, append]

necessary in my case?

5
  • 1
    It is hard to say why these things are necessary in your case because you have not provided any information about your actual .tex file; however, I'm not convinced things are as necessary as it may seem right now. Please provide an MWE. (If you were already using a sourcemap, why didn't you mention this?)
    – jon
    Commented Dec 30, 2016 at 5:05
  • Regarding the final: the point is that this term terminates the processing of the parent map. It must be used with discretion.
    – jon
    Commented Dec 30, 2016 at 5:18
  • @jon What is crucial here is that the code also appends a comma to the field. When you append ONE to a non-empty keyword list, primary,own for example, you get primary,ownONE which doesn't work for obvious reasons. If the field is empty, however, this adds a comma, so that in the end we have ,ONE, which I think gives a warning about an empty keyword, but causes no further trouble.
    – moewe
    Commented Dec 30, 2016 at 7:30
  • @moewe -- Yes, indeed. I figured that might be an issue, but I was trying to promote the idea that this is yet another case where an MWE is actually useful/important. I think (without having tried) that it might simply be easier to append a ,ONE all in one step ... which is why I said it may not be 'necessary' to add that \step in my earlier comment. (And, depending on what is going on, I was going to suggest that append may or may not be the right choice.)
    – jon
    Commented Dec 30, 2016 at 19:01
  • @jon Yes, adding ,ONE should do the same. With a bit of regex foo one might be able to append the comma only when necessary, but I haven't yet found an elegant way of doing that. I see your point about MWEs here, sometimes it is hard to know how far to reduce all the code involved.
    – moewe
    Commented Dec 30, 2016 at 19:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .