plk / biblatex

biblatex is a sophisticated bibliography system for LaTeX users. It has considerably more features than traditional bibtex and supports UTF-8
512 stars 118 forks source link

Advice on extending biblatex for "subcitation" feature #1081

Closed AJamesPhillips closed 3 years ago

AJamesPhillips commented 3 years ago

Hi all,

Thank you for the amazing work with this package. I was hoping someone might point me in the right direction for extending the package / leveraging it to accommodate this "subcitation" feature. Specifically I was hoping to write something like:

Lorem \cite{Nolte2020} ipsum dolor sit
amet \cite{Nolte2020,anotherPaper}{h1n1} something else \cite{Nolte2020}{crowd}.

Have it rendered like:

Lorem [1] ipsum dolor sit amet [1a,2] something else [1b].

Based off a biblatex file with something like:

@article{Nolte2020,
    doi = {10.1016/j.jmoldx.2020.06.003},
    url = {https://doi.org/10.1016/j.jmoldx.2020.06.003},
    % ... other fields ...
    subreferences = {
        h1n1 = {https://hyp.is/94iqCB9_EeuQCNcJXiV1IA/www.jmdjournal.org/article/S1525-1578(20)30360-3/fulltext},
        crowd = {https://hyp.is/gTHBhB6_EeudDw8HxXC_sg/www.jmdjournal.org/article/S1525-1578(20)30360-3/fulltext}
    }
}

@article{anotherPaper, ... }

Thank you for any points on where to do get started, thoughts on architecture, and or if I could leverage all the amazing work everyone's put into the biblatex package (I hope so :) ) or if would need to start a new.

My first step has been this:

\newcommand{\subcite}[2]{\cite{#1}}
moewew commented 3 years ago

biblatex has entry sets to bundle several entries in one 'container'. Some styles support a subentry option to refer to each contained source separately.

Sets can be created statically in the .bib file as @set entries

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}

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

\begin{filecontents}{\jobname.bib}
@set{set,
  entryset     = {herrmann,aksin,yoon},
  annotation   = {A \texttt{set} with three members.},
}
@article{herrmann,
  author       = {Herrmann, Wolfgang A. and Öfele, Karl and Schneider,
                  Sabine K.  and Herdtweck, Eberhardt and Hoffmann, Stephan D.},
  title        = {A carbocyclic carbene as an efficient catalyst ligand for {C--C}
                  coupling reactions},
  journaltitle = {Angew.~Chem. Int.~Ed.},
  date         = 2006,
  volume       = 45,
  number       = 23,
  pages        = {3859-3862},
}
@article{aksin,
  author       = {Aksın, Özge and Türkmen, Hayati and Artok, Levent
                  and Çetinkaya, Bekir and Ni, Chaoying and
                  Büyükgüngör, Orhan and Özkal, Erhan},
  title        = {Effect of immobilization on catalytic characteristics of
                  saturated {Pd-N}-heterocyclic carbenes in {Mizoroki-Heck}
                  reactions},
  journaltitle = {J.~Organomet. Chem.},
  date         = 2006,
  volume       = 691,
  number       = 13,
  pages        = {3027-3036},
}
@article{yoon,
  author       = {Yoon, Myeong S. and Ryu, Dowook and Kim, Jeongryul and Ahn,
                  Kyo Han},
  title        = {Palladium pincer complexes with reduced bond angle strain:
                  efficient catalysts for the {Heck} reaction},
  journaltitle = {Organometallics},
  date         = 2006,
  volume       = 25,
  number       = 10,
  pages        = {2409-2411},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
Lorem \autocite{set}
Lorem \autocite{aksin}

\printbibliography
\end{document}

or dynamically from the document preamble

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}

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

\begin{filecontents}{\jobname.bib}
@article{sigfridsson,
  author       = {Sigfridsson, Emma and Ryde, Ulf},
  title        = {Comparison of methods for deriving atomic charges from the
                  electrostatic potential and moments},
  journaltitle = {Journal of Computational Chemistry},
  date         = 1998,
  volume       = 19,
  number       = 4,
  pages        = {377-395},
  doi          = {10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P},
}
@book{worman,
  author       = {Worman, Nancy},
  title        = {The Cast of Character},
  date         = 2002,
  publisher    = {University of Texas Press},
  location     = {Austin},
}
@thesis{geer,
  author       = {de Geer, Ingrid},
  title        = {Earl, Saint, Bishop, Skald~-- and Music},
  type         = {phdthesis},
  institution  = {Uppsala Universitet},
  date         = 1985,
  subtitle     = {The {Orkney Earldom} of the Twelfth Century. {A} Musicological
                  Study},
  location     = {Uppsala},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\defbibentryset{dynamicset}{sigfridsson,worman,geer}

Lorem \autocite{dynamicset}
ipsum \autocite{geer}

\printbibliography
\end{document}

You can read a little more about this in the documentation. §3.13.5 Entry Sets is probably the most relevant. If you are familiar with mcite and its interface, you may be interested in biblatex's emulation of that package, which is discussed in §3.8.10 mcite-like Citation Commands

AJamesPhillips commented 3 years ago

This is fantastic. Thank you so much @moewew .

Under #3.13.5.1 it says

If the @set entry is cited, the set members are grouped automatically. If not, they
will work like any regular entry.

Do you know of any way around this? i.e. to force the inclusion of the parent set into the bibliography?

Apologies I know this is partially moving the goal posts. It's not a big deal to have to use \autocite{Nolte2020,Nolte2020h1n1} which gives [1,1a]

I'd prefer to avoid it if possible and use \autocite{Nolte2020h1n1} which gives [1a] (with a bibtex like this:)

@set{Nolte2020,
    entryset = {Nolte2020main,Nolte2020h1n1,Nolte2020crowd},
}

@article{Nolte2020main,
    doi = {10.1016/j.jmoldx.2020.06.003},
    url = {https://doi.org/10.1016/j.jmoldx.2020.06.003},
    % ... other fields ...
}

@misc{Nolte2020h1n1,
    url={https://hyp.is/94iqCB9_EeuQCNcJXiV1IA/www.jmdjournal.org/article/S1525-1578(20)30360-3/fulltext}
}

@misc{Nolte2020crowd,
    url={https://hyp.is/gTHBhB6_EeudDw8HxXC_sg/www.jmdjournal.org/article/S1525-1578(20)30360-3/fulltext}
}
moewew commented 3 years ago

No, off the top of my head I can't think of a way around this. Since set children can be entries that can stand for themselves without their parent, biblatex (or Biber) really needs to know whether or not you want to add the parent @set to the bibliography. You can avoid an explicit cite with \nocite{set}, but some citation request needs to be there.

If you use dynamic entry sets, the \nocite for the set parent is already implied by \defbibentryset, so need not be given explicitly.

AJamesPhillips commented 3 years ago

Thank you @moewew . This is definitely far more progress than I had expected to get so quickly. I will close for now and perhaps in the future I or someone else might reopen to develop / refine it further. Thanks again!

AJamesPhillips commented 3 years ago

There's a prototype package here.