5

I have to create in a document two bibliographies (easy), which should be numbered (easy) which are filled by distinct \cite-commands (which can be done e.g. with categories). The problem is that it is possible that some bib-entries should be in both bibliographies and here the problems start as can be seen by this example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[style=numeric,defernumbers,sortcites]{biblatex}
\DeclareBibliographyCategory{related}
\DeclareBibliographyCategory{main}

\DeclareCiteCommand{\cite}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\addtocategory{main}{\thefield{entrykey}}%
   \usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citer}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\addtocategory{related}{\thefield{entrykey}}%
   \usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\addbibresource{biblatex-examples.bib}  

\begin{document}
\cite{shore,sarfraz,spiegelberg}

\citer{spiegelberg}

\cite{weinberg}

\citer{sigfridsson}


\printbibliography[category=main,title=Main List,resetnumbers]

\DeclareFieldFormat{labelnumberwidth}{\mkbibparens{#1}}
\printbibliography[category=related,resetnumbers,title=Related Documents]

\end{document}

enter image description here

The Spiegelberg entry should have number 3 in the first bibliography (and when cited by \cite, and 2 in the second and when cited by \citer. I have now been looking at refsection (would work, if one could "interrupt and resume" it), \DeclareSourceMap (to copy the entry) and other things but nothing looks really good. Has someone an idea how to do it?

lockstep
  • 250,273
Ulrike Fischer
  • 327,261
  • Could be complete nonsense (have no manual available), but have you tried leaving the defernumbers option? – Daniel Feb 15 '15 at 23:03
  • There's another question either about this or very closely related somewhere. But you need to undefine the labelnumber for the repeated entry because otherwise it won't be assigned a new label since it already has one. resetnumbers just sets the next number assigned if a new label is needed to a particular value (1 by default). – cfr Feb 16 '15 at 03:13
  • @Daniel: Removing the defernumbers or resetnumbers don't solve the core problem that one entry (Spiegelberg) must have to distinct labels. – Ulrike Fischer Feb 16 '15 at 12:04
  • @cfr: The search key labelnumber helped. I found this: http://tex.stackexchange.com/a/205094/2388. I can use a normal enumerate list for the second bibliography and label the items and use \ref in the \citer-command to access the labels. It already works I only have to polish it up a bit. – Ulrike Fischer Feb 16 '15 at 12:09
  • @UlrikeFischer It would be nice if biblatex could handle multiple bibliographies a little more flexibly without the need for these kinds of workarounds, but I it seems to pull against the entire setup. Glad you found a way... – cfr Feb 16 '15 at 18:42
  • 1
    @cfr: And now I realized I will run into problems with the sorting (my actual case should use sorting=none). So I made a feature request https://github.com/plk/biblatex/issues/297. – Ulrike Fischer Feb 17 '15 at 12:29
  • I have implemented a sourcemapping feature in biber which can "clone" an entry by adding a prefix to the entry key. See the Github issue you raised - it seems to solve your problem but I would welcome feedback. – PLK Feb 21 '15 at 10:49
  • I wanted to comment on github but the access is somehow broken from this pc, the comments disappear. I will test the sourcemap solution asap - it sounds very sensible. My other solution works too, but I'm still investigating how to best reference the entries of a refsection "from the outside". – Ulrike Fischer Feb 21 '15 at 11:20
  • Since the bug report seems to have been dealt with satisfactorily, is there any chance this question here can be answered (or closed)? – moewe Apr 04 '15 at 11:46
  • @moewe: I added an answer. – Ulrike Fischer Apr 04 '15 at 12:55

1 Answers1

3

I found two solutions to the question

With a recent version of biblatex (and biber 2.0)

There one can "clone" entries: (see also https://github.com/plk/biblatex/issues/297)

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[style=numeric,defernumbers,sortcites]{biblatex}
\DeclareBibliographyCategory{related}
\DeclareBibliographyCategory{main}

\DeclareCiteCommand{\cite}[\mkbibbrackets] {\usebibmacro{prenote}} {\addtocategory{main}{\thefield{entrykey}}% \usebibmacro{citeindex}% \usebibmacro{cite}} {\multicitedelim} {\usebibmacro{postnote}}

\DeclareCiteCommand{\citer}[\mkbibparens] {\usebibmacro{prenote}} {\addtocategory{related}{\thefield{entrykey}}% \usebibmacro{citeindex}% \usebibmacro{cite}} {\multicitedelim} {\usebibmacro{postnote}}

\addbibresource{biblatex-examples.bib}

\DeclareSourcemap{ \maps[datatype=bibtex]{ \map{ \perdatasource{biblatex-examples.bib} \step[fieldsource=entrykey, match=\regexp{(.*)}, final] \step[entryclone={rel-$1}] } } }

\begin{document}\nocite{*} \cite{shore,sarfraz,spiegelberg}

\citer{rel-spiegelberg,rel-springer}

\printbibliography[category=main,title=Main List,resetnumbers]

\DeclareFieldFormat{labelnumberwidth}{\mkbibparens{#1}} \printbibliography[category=related,resetnumbers,title=Related Documents]

\end{document}

enter image description here

Using "splitted refsections"

This puts the different cite commands in different refsections. The challenge here was to find a way to pause and restart a refsection. As refsection can't be nested one can't use this solution in documents with "real" refsections! A discussion about this solution is here https://github.com/plk/biblatex/issues/307. If I find some time I will perhaps convert it in a package.

updated 2018 to adapt to some internal changes in \blx@refsection@i.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[sortcites]{biblatex}
\usepackage{xparse,zref}
\addbibresource{biblatex-examples.bib}

\makeatletter

% Commands to label and reference the refsections % by name. As a refsection can be behind % \printbibliography a fallback label in the aux is used too \newcommand\UFblx@labelrefsection[1]{% \csxdef{refsection@label@#1@num}{\the\c@refsection}% \zref@setcurrent{default}{\the\c@refsection}% \zref@labelbyprops{refsection@auxlabel@#1}{default}}

\newcommand\getrefsection[1]{% \ifcsname refsection@label@#1@num\endcsname \csname refsection@label@#1@num\endcsname \else \zref@extractdefault{refsection@auxlabel@#1}{default}{0}% \fi}

% a hook at the begin can be useful \newcommand\splitrefinit[2]{% \csdef{UFblx@splitrefsection@#1@inithook}{#2}}

\newcommand\UFblx@refsectioncont@i{} \newcommand\UF@refsectioncont@name{}

\def\UFblx@refsectioncont@i[#1]{%an adapted version of \blx@refsection@i \endgroup \ifcsdef{refsection@label@\csuse{UF@refsectioncont@name}@num}% {\blx@maxsection=\numexpr\csname refsection@label@\csuse{UF@refsectioncont@name}@num\endcsname\relax}% {\PackageWarning{test}{refsection \UF@refsectioncont@name\space unknown, using refsection 0}{}% \blx@maxsection=0 }% \xifinlist{\the\c@refsection}\blx@allrefsections {} {\listxadd\blx@allrefsections{\the\c@refsection}}% \ifcsdef{blx@defaultrefcontexts@\the\c@refsection} {} {\global\cslet{blx@defaultrefcontexts@\the\c@refsection}@empty}% \ifcsdef{blx@maxsegment@\the\c@refsection}{}% {\expandafter\newcount\csname blx@maxsegment@\the\c@refsection\endcsname}% \ifcsdef{blx@sectionciteorder@\the\c@refsection}{}% {\expandafter\newcount\csname blx@sectionciteorder@\the\c@refsection\endcsname}% \global\c@refsection\blx@maxsection \blx@inf@refsec \blx@secinit \if@filesw \blx@auxwrite@mainaux{}{% \string\abx@aux@refsection{\the\c@refsection}{\the\c@page}}% \ifblank{#1} {} {\let\blx@bibfiles@empty % globals should be first as it might contain macros needed for others \forlistloop{\listadd\blx@bibfiles}\blx@bibfiles@global}% \blx@xsanitizeafter{\forcsvlist\blx@refsection@addfile}{#1}% \blx@refsection@ii \fi \endgroup}%

\ExplSyntaxOn \tl_new:N\l_UFbbx_tmp_biblist_tl

\keys_define:nn {UFbbx} { name .tl_set:N = {\UF@refsectioncont@name}, }

\newenvironment{splitrefsection}[1][]%[2][] {\keys_set_known:nnN {UFbbx} {#1} \l_UFbbx_tmp_biblist_tl %a hook \csname UFblx@splitrefsection@\csuse{UF@refsectioncont@name}@inithook\endcsname %test if new name \ifcsdef{refsection@label@\csuse{UF@refsectioncont@name}@num} {%continue known refsection \let\blx@refsection@i\UFblx@refsectioncont@i \expandafter\refsection\expandafter[\l_UFbbx_tmp_biblist_tl] } {%new labeled refsection: \expandafter\refsection\expandafter[\l_UFbbx_tmp_biblist_tl] \UFblx@labelrefsection{\UF@refsectioncont@name} } } {\endrefsection}

\ExplSyntaxOff

\NewDocumentCommand\splitrefcite {r<> o o m} {\begin{splitrefsection}[name=#1]% \let\mkbibbrackets\mkbibparens \IfNoValueTF{#3} {\IfNoValueTF{#2} {\cite{#4}} {\cite[#2]{#4}}} {\cite[#2][#3]{#4}}% \end{splitrefsection}}

\DeclareMultiCiteCommand{@splitrefcites}[@splitrefwrapper]{\cite}{\multicitedelim} \newcommand@splitrefwrapper{}

\NewDocumentCommand\splitrefcites {r<>} {\renewcommand@splitrefwrapper[1]{\begin{splitrefsection}[name=#1]\mkbibparens{##1}\end{splitrefsection}}% @splitrefcites}

%for the example cites are in parens in splitref. \splitrefinit{myrefsec}{\let\mkbibbrackets\mkbibparens} \makeatother

\begin{document} \cite{shore,sarfraz,spiegelberg}

\splitrefcite<related>{spiegelberg,springer}

\printbibliography[title=Main List]

\DeclareFieldFormat{labelnumberwidth}{\mkbibparens{#1}} \printbibliography[section=\getrefsection{related},title=Related Documents] \end{document}

enter image description here

Martin
  • 114
Ulrike Fischer
  • 327,261