[Tex/LaTex] Multiple bibliographies (reference lists) using embedded bibliography database

biblatexbibliographiesmultibibsubdividing

I would like to have multiple bibliographies (reference lists) as described in Airminded · Multiple bibliographies in LaTeX (TeX Frequently Asked Questions — question label "multbib").

However, I'd like to use with a single .tex file, which would contain the bibliography database embedded, as in LaTeX/Bibliography Management: #1 Embedded system

Now, I want to use letter documentclass, for which the bibliography needs to be defined (Re: Environment thebibliography undefined when using letter)

So what I end up is with this example (code below, compiled with just pdflatex, no bibtex(which I'd like to avoid in this case)):

multibib-embedded.png

… obviously, something works (multibib recognized primary and secondary cites, assigning them number "1" as start) — however I don't get two, separate primary and secondary list of references; would that be possible in this context? (doesn't have to be with multibib, but I'd like to avoid a separate .bib file and a bibtex call)

EDIT: I'd also like separate cite keys (i.e. rendered as [a1] and [b1]; not yet sure if multibib can do that; edit: no it cant, multibib.pdf says "You can also edit the .bbl files created by BibTEX and add 'a', 'b',. . . to the labels, but your changes will be overwritten by subsequent BibTEX runs." and recommends \cite[a]{key}) – how possible would that be?

 

The code is this:

\documentclass{letter}

% Environment thebibliography undefined when using letter: http://www.latex-community.org/forum/viewtopic.php?f=4&t=3359
\makeatletter
\setlength \labelsep {.5em}
\newcommand\newblock{\hskip
  .11em\@plus.33em\@minus.07em} \let\@openbib@code\@empty
\newcommand\refname{References}
\newcommand\section{\@startsection
  {section}{1}{\z@}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {2.3ex \@plus.2ex}%
  {\normalfont\Large\bfseries}}
\newenvironment{thebibliography}[1]
{\section*{\refname}%
  \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
  \list{\@biblabel{\@arabic\c@enumiv}}%
  {\settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth \advance\leftmargin\labelsep \@openbib@code
    \usecounter{enumiv}%
    \let\p@enumiv\@empty \renewcommand\theenumiv{\@arabic\c@enumiv}}%
  \sloppy \clubpenalty4000 \@clubpenalty \clubpenalty
  \widowpenalty4000%
  \sfcode`\.\@m} {\def\@noitemerr {\@latex@warning{Empty
      `thebibliography' environment}}%
      \endlist}
\makeatother

\usepackage{multibib}
\newcites{pri}{Primary sources}
\newcites{sec}{Secondary sources}

\begin{document}


\begin{letter}{Addressee}
Blah, blah - content...

Primary cite: \citepri{lamport94} ...

Secondary cite: \citesec{lamport94} ...


\begin{thebibliography}{9}

\bibitem{lamport94}
  Leslie Lamport,
  \emph{\LaTeX: A Document Preparation System}.
  Addison Wesley, Massachusetts,
  2nd Edition,
  1994.

\bibitem{lamport95}
  Leslie Lamport,
  \emph{\LaTeX: A Document Preparation System}.
  Addison Wesley, Massachusetts,
  2nd Edition,
  1995.

\end{thebibliography}

\end{letter}


\end{document}

Best Answer

Under your keyword filter approach with biblatex, superficial adjustments to the labelnumber field (such as adding the suffix a or b and resetting the secondary entry count) can be made by redefining the labelnumber format. Here's an example.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[colorlinks=true,citecolor=red]{hyperref}
\usepackage[defernumbers=true]{biblatex}

\newcounter{bbx:primcount}
\setcounter{bbx:primcount}{0}

% Count number of  primary entries; expand labelnumberwidth
% to accommodate suffixes (NB: this might need tweaking when there
% are relatively many more secondary entries)
\makeatletter
\AtDataInput{%
  \ifkeyword{secondary}
    {}
    {\addtocounter{bbx:primcount}{1}%
     \blx@setlabwidth{\labelnumberwidth}{%
       \csuse{abx@ffd@*@labelnumberwidth}{\thefield{labelnumber}a}}}}
\makeatother

% Print labelnumbers with suffixes, adjust secondary labelnumber
\DeclareFieldFormat{labelnumber}{%
  \ifkeyword{secondary}
    {{\number\numexpr#1-\value{bbx:primcount}}b}
    {#1a}}

\addbibresource{biblatex-examples.bib}

\begin{document}
Filler text \cites[10--15]{aristotle:anima}{aristotle:physics}.
Filler text \cite[23--25]{nussbaum}. Filler text \cite{hyman}.
\printbibheading
\printbibliography[keyword=primary,heading=subbibliography,title={Primary Sources (a)}]
\printbibliography[keyword=secondary,heading=subbibliography,title={Secondary Sources (b)}]
\end{document}

enter image description here

This solution assumes that all entries are assigned one of the keywords primary or secondary, but entries without the latter keyword can be treated as primary by replacing the filter keyword=primary with notkeyword=secondary.

The same problem but with prefixes to the labelnumber is relatively easy using the prefixnumbers option.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[colorlinks=true,citecolor=red]{hyperref}
\usepackage[defernumbers=true]{biblatex}

\addbibresource{biblatex-examples.bib}

\begin{document}
Filler text \cites[10--15]{aristotle:anima}{aristotle:physics}.
Filler text \cite[23--25]{nussbaum}. Filler text \cite{hyman}.
\printbibheading
\printbibliography[keyword=primary,heading=subbibliography,title={Primary Sources},prefixnumbers={A}]
\printbibliography[keyword=secondary,heading=subbibliography,title={Secondary Sources},prefixnumbers={B}]
\end{document}