4

I'm trying to use biblatex to produce two different bibliographies. The first one should contains only my papers, sorted in order of appearance in the text, and with some special prefix. The second bibliography should contain the general references, sorted in some different order (say, name-title-year), and with no special prefix.

Notice that the two bibliographies DO NOT INTERSECT (i.e. they do not have common entries).

I use this MTW:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{ref.bib}
@ARTICLE{Pub1,
  author = {A. R},
  title = {My best paper},
  year = {2013},
  journal = C,
  keywords = {publication}
}

@ARTICLE{Pub2,
  author = {A. R},
  title = {My second best paper},
  year = {2013},
  journal = C,
  keywords = {publication}
}

@ARTICLE{Nopub1,
  author = {A. R},
  title = {Not my paper 1},
  year = {2012},
  journal = I,
  keywords = {general}
}

@ARTICLE{Nopub2,
  author = {A. R},
  title = {Not my paper 2},
  year = {2012},
  journal = I,
  keywords = {general}
}

\end{filecontents}

\usepackage[style=numeric, sorting=none, defernumbers=true, backend=biber]{biblatex}


\addbibresource{ref.bib}

\pagestyle{empty}

\begin{document}

This is my first publication : \cite{Pub1}

These are not my publications: \cite{Nopub1,Nopub2}

This is my second publication: \cite{Pub2}


\printbibliography[keyword=publication, prefixnumbers=R, title=My papers]

\begin{refcontext}[sorting=nty]
\printbibliography[notkeyword=publication, prefixnumbers=, title=Not my papers]
\end{refcontext}

\end{document}

OUTPUT (after pdflatex + biber + pdflatex + pdflatex):

enter image description here

Both bibliographies are printed correctly and well ordered, but text citations referring to the second bibliography are wrong (they are all [0]). I tried to check other related posts, but no one mentioned this specific problem.

Thanks!

2

I don't think that currently there is a good solution. But I will try to explain some background. In your example the wanted output looks obvious as your two bibliographies don't overlap. But this doesn't need to be the case. In different refcontexts entries can be repeated. So lets look what happens if you remove the filters:

\documentclass{article}

\usepackage[style=numeric, sorting=none,   backend=biber]{biblatex}

\addbibresource{ref.bib}

\pagestyle{empty}

\begin{document}

This is my first publication : \cite{Pub1}

These are not my publications: \cite{Nopub1,Nopub2}

This is my second publication: \cite{Pub2}

\printbibliography[title=Not my papers]

\newrefcontext[sorting=nty]
This is my first publication: \cite{Pub1}

These are not my publications: \cite{Nopub1,Nopub2}

This is my second publication: \cite{Pub2}

\printbibliography[prefixnumbers=R,title=My papers]

\end{document}

enter image description here

As you can see every bibentry has two labels and biblatex has to choose which one to use. Sensibly it uses for the first block of cites the labels from the first (default) refcontext, and for the second block the labels from the second block.

This explains why you get zeros: In the first block the cites don't have a label and biblatex has no chance to guess that you want a label from another refcontext as fallback -- after all there could be more than one suitable label.

The label biblatex will use for a cite depends on the current value of \blx@refcontext@sorting. So you can locally force biblatex to use labels from another refcontext by doing

{
 \makeatletter\def\blx@refcontext@sorting{nty}
 These are not my publications: \cite{Nopub1,Nopub2}
} 

Then you can get something like this:

enter image description here

But this solution wouldn't work for mixed cites like \cite{Nopub1,pub1}. And the "logical" solution

 \AtEveryCitekey{\ifkeyword{puplication}{}{\def\blx@refcontext@sorting{nty}}}

doesn't work either as the code for refcontext is executed before \AtEveryCitekey can kick in. So probably you will have to make a feature request ...

Edit

You could try this. But be warned: It is a hack, and it is quite possible that it confuse biblatex. So test and check carefully with more data.

\documentclass{article}

\usepackage[style=numeric, sorting=none, defernumbers,  backend=biber]{biblatex}

\addbibresource{ref.bib}

\pagestyle{empty}

\makeatletter
\AtEveryCitekey{\ifkeyword{publication}{}{\def\blx@refcontext@sorting{nty}%
   \csname blx@data@\the \c@refsection @\blx@refcontext@sorting @\abx@field@entrykey\endcsname}}
\makeatother
\begin{document}

This is my first publication : \cite{Pub1}

These are not my publications: \cite{Nopub1,Nopub2}

This is my second publication: \cite{Pub2}


\printbibliography[keyword=publication, prefixnumbers=R, title=My papers]

\begin{refcontext}[sorting=nty]
\printbibliography[notkeyword=publication, prefixnumbers=, title=Not my papers]
\end{refcontext}

\end{document}
  • So, even if the two bibliographies DO NOT intersect (which is my case) there is no solution? The problem of "[0]" occurs only if I specify a different sorting scheme for the two bibliographies, otherwise it works perfectly... – Raziel Feb 8 '16 at 12:12
  • That the bibliographies don't intersect is not really relevant. It only means that you get "0" instead of a faulty "1" when you are in the "wrong" refcontext. And yes, it will work if you are using the same sorting scheme for both as now labels are known for all entries. I added a suggestion for a workaround. – Ulrike Fischer Feb 8 '16 at 14:24
2

refcontexts were introduced for this sort of thing - citation commands within refcontexts share the context so put the "These are not my publications:" citation inside the same refcontext.

\assignrefcontextentries[sorting=nty]{Nopub1,Nopub2}
\begin{document}

This is my first publication: \cite{Pub1}
These are not my publications: \cite{Nopub1,Nopub2}
This is my second publication: \cite{Pub2}

\printbibliography[keyword=publication, prefixnumbers=R, title=My papers]

\begin{refcontext}[sorting=nty]
\printbibliography[notkeyword=publication, title=Not my papers]
\end{refcontext}

\end{document}

This requires biblatex 3.3

  • With a nocite command, or what (I don't think I understood your answer)? I stress that the two bibliographies appear both at the end of the document. Can you provide a MWE? – Raziel Feb 9 '16 at 19:27
  • See updated answer. – PLK Feb 12 '16 at 16:00
  • I haven't tested it yet, but I do find the syntax a bit confusing. What would happen if someone would use nty twice but with different prefixnumbers? Wouldn't something like \begin{refcontext}[sorting=nty, name=mypub]\printbibliography ... and \userefcontext[name=mypub]{\cite{...}} be clearer? – Ulrike Fischer Mar 1 '16 at 14:46
  • Hmm, well, that's an argument for making prefixnumbers part of a refcontext rather than as an argument to \printbibliography since in such a case, the citations also need to be in the same context. This seems to be a general trend now - the more complex things are allowed, the more there is a case for refcontexts which can enclose citations and bibliographies. The other point is reasonable too as the refcontexts become more complex - having named refcontexts is probably a good idea. – PLK Mar 1 '16 at 17:50
  • 1
    @PLK: Sorry I didn't got notified about your comments. I personally think one shouldn't split bibs to much, one get a lot of problems (unrelated to the technical capabilities of biblatex) and only makes it for the reader more difficult to find an entry. So I don't have really a use case. But I do find it a bit dangerous to use nty for two different functions: One to describe a sorting and the other to identify a refcontext. Someone can find an example where it leads to troubles. – Ulrike Fischer Mar 3 '16 at 18:18
0

The problem comes from using a different refcontext. If you remove the refcontext environment around the second printbibliography, you get the desired output.

  • The refcontext environment is there because I want the second bibliography to be sorted with a different scheme w.r.t. the first (which uses the global sorting scheme defined when the biblatex package is declared in the preamble). Is there another way to specify a different scheme without the refcontext environment? – Raziel Feb 8 '16 at 12:50
  • Then I believe what you need is a custom sorting scheme. I was misled by the first response you got and didn't reread your intro. Will try to update. – Joce Feb 8 '16 at 12:56
  • Not really a custom sorting scheme, just two different (albeit standard) ones. E.g. "none" sorting scheme for the first biblio and "nty" for the second. I'm looking forward to your updated answer! – Raziel Feb 8 '16 at 13:00

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.