С последней версией biblatex (и biber 2.0)

С последней версией biblatex (и biber 2.0)

Мне нужно создать в документе две библиографии (легко), которые должны быть пронумерованы (легко), которые заполняются различными \cite-командами (что можно сделать, например, с категориями). Проблема в том, что некоторые записи bib могут быть в обеих библиографиях, и здесь начинаются проблемы, как можно увидеть в этом примере:

\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}

введите описание изображения здесь

Запись Шпигельберга должна иметь номер 3 в первой библиографии (и когда цитируется \cite, и 2 во второй и когда цитируется \citer. Я сейчас просматриваю refsection(было бы неплохо, если бы можно было «прервать и возобновить» ее), \DeclareSourceMap(скопировать запись) и другие вещи, но ничего не выглядит действительно хорошим. Есть ли у кого-нибудь идеи, как это сделать?

решение1

Я нашел два решения вопроса

С последней версией biblatex (и biber 2.0)

Там можно «клонировать» записи: (см. также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}

введите описание изображения здесь

Использование «разделенных рефсекций»

Это помещает различные команды cite в различные refsections. Здесь задача состояла в том, чтобы найти способ приостановить и перезапустить refsection. Поскольку refsection не может быть вложенной, это решение нельзя использовать в документах с «настоящими» refsections! Обсуждение этого решения здесьhttps://github.com/plk/biblatex/issues/307. Если найду время, возможно, сделаю из него пакет.

обновлено в 2018 году для адаптации к некоторым внутренним изменениям в \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}    

введите описание изображения здесь

Связанный контент