plk / biblatex

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

Sublists within bibenvironment #844

Open gusbrs opened 5 years ago

gusbrs commented 5 years ago

biblatex uses list structures as the base of its bibliography environments, being bibliography entries rendered as list items. However, contrary to regular lists, it can be very tricky to add a sublist, or nest a list, within the bibliography environment.

I believe there are some use cases for such a feature which, as far as I can see, share the characteristic that some sort of (hierarchical) grouping between entries is attempted to be conveyed. I present three examples below which somehow attempt to convey some such grouping and which would benefit, in terms of better output, if a sublist within the bibenvironment was viable so that we could have proper indentation and so on for these entries groups.

I'm aware this may well be tricky to implement, but I make here the case for the possible use, in the hope that some technical solution can be achieved.

@moewew inquired at TeX.SX about how this could be integrated in the standard styles. Going beyond the argument of the use case above, I might suggest having a multivolume subitems inside a sublist, so as to have a proper hanging indent, would be nice. As for sets, probably the default should be the current compact form, but an eventual (entry?) option would be welcome. But, in general, I believe the possibility to use sublists within the bibenvironment would be quite useful even when this is not immediately integrated in the standard styles.

So, here are some examples in which such a feature might improve output. A first one would be the multivolume related type.

\documentclass{article}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{knuth:ct:a,
  author       = {Knuth, Donald E.},
  title        = {The {\TeX book}},
  subtitle     = {Let's have here also a subtitle, which may be long enough to
    send us to a second line},
  date         = 1984,
  maintitle    = {Computers \& Typesetting},
  volume       = {A},
  publisher    = {Addison-Wesley},
  location     = {Reading, Mass.},
  langid       = {english},
  langidopts   = {variant=american},
  sorttitle    = {Computers & Typesetting A},
  indexsorttitle= {The TeXbook},
  indextitle   = {\protect\TeX book, The},
  shorttitle   = {\TeX book},
}

@book{knuth:ct:b,
  author       = {Knuth, Donald E.},
  title        = {{\TeX}: The Program Oh! What if Knuth was not so concise in
    his titles? How nice would this multivolume look? Would the individual
    entries be easily spotted?},
  date         = 1986,
  maintitle    = {Computers \& Typesetting},
  volume       = {B},
  publisher    = {Addison-Wesley},
  location     = {Reading, Mass.},
  langid       = {english},
  langidopts   = {variant=american},
  sorttitle    = {Computers & Typesetting B},
  indexsorttitle= {TeX: The Program},
  shorttitle   = {\TeX},
}

@book{knuth:ct:c,
  author       = {Knuth, Donald E.},
  title        = {The {METAFONTbook}},
  subtitle     = {It is easy to see where this goes Lorem ipsum Hocus pocus},
  date         = 1986,
  maintitle    = {Computers \& Typesetting},
  volume       = {C},
  publisher    = {Addison-Wesley},
  location     = {Reading, Mass.},
  langid       = {english},
  langidopts   = {variant=american},
  sorttitle    = {Computers & Typesetting C},
  indextitle   = {METAFONTbook, The},
  shorttitle   = {METAFONTbook},
}

@book{knuth:ct:d,
  author       = {Knuth, Donald E.},
  title        = {{METAFONT}: The Program},
  date         = 1986,
  maintitle    = {Computers \& Typesetting},
  volume       = {D},
  publisher    = {Addison-Wesley},
  location     = {Reading, Mass.},
  langid       = {english},
  langidopts   = {variant=american},
  sorttitle    = {Computers & Typesetting D},
  shorttitle   = {METAFONT},
}

@book{knuth:ct:e,
  author       = {Knuth, Donald E.},
  title        = {{Computer Modern} Typefaces},
  date         = 1986,
  maintitle    = {Computers \& Typesetting},
  volume       = {E},
  publisher    = {Addison-Wesley},
  location     = {Reading, Mass.},
  langid       = {english},
  langidopts   = {variant=american},
  sorttitle    = {Computers & Typesetting E},
}

@mvbook{knuth:ct:related,
  author       = {Knuth, Donald E.},
  title        = {Computers \& Typesetting},
  date         = {1984/1986},
  volumes      = 5,
  publisher    = {Addison-Wesley},
  location     = {Reading, Mass.},
  langid       = {english},
  langidopts   = {variant=american},
  sorttitle    = {Computers & Typesetting},
  indexsorttitle= {Computers & Typesetting},
  related      = {knuth:ct:a,knuth:ct:b,knuth:ct:c,knuth:ct:d,knuth:ct:e},
  relatedtype  = {multivolume},
}

\end{filecontents}

\usepackage[style=authoryear]{biblatex}
\usepackage{csquotes}

\addbibresource{\jobname.bib}

\begin{document}

\nocite{knuth:ct:related}
\printbibliography

\end{document}

Which results in:

multivolume

A second example would be sets (taken from https://tex.stackexchange.com/q/463318/105447):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage[subentry]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@Book{fish:drugs,
  mainsubtitle = {Drugs and Society},
  year         = {2006},
  editor       = {Fish, Jefferson M.},
  maintitle    = {U.S.~public policy},
  publisher    = {Rowman \& Littlefield Publishers, Inc},
  location     = {Lanham, Maryland},
}
@Set{set:fish:drugs,
  entryset     = {fish:drugs:gable:alt,fish:drugs:cleveland:use},
}
@Inbook{fish:drugs:cleveland:use,
  crossref  = {fish:drugs},
  author    = {Mary M. Cleveland},
  title     = {Use, 'Abuse', Adverse Health Effects, and Addiction},
  sorttitle = {09 Use, Abuse, Adverse Health Effects, and Addiction},
}
@Inbook{fish:drugs:gable:alt,
  crossref  = {fish:drugs},
  author    = {Robert S. Gable},
  title     = {Acute Toxicity of Drugs vs.~Regulatory Status},
  sorttitle = {07 Acute Toxicity of Drugs versus Regulatory Status},
}
\end{filecontents}

\renewcommand{\entrysetpunct}{\finentrypunct\par}

\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}
\printbibliography

\end{document}

Resulting in:

set

A third, an attempt to have a biblist like subgrouping (taken from https://tex.stackexchange.com/q/409844/105447). Here a conditional is used inside \defbibenvironment to try to emulate a sublist, but it falls definitely short:

\documentclass{article}

\usepackage[style=authortitle,minxrefs=1]{biblatex}

\usepackage{calc}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@customa{natarch,
    title = {National Archives. But with a title long enough to span two lines. Yet a little longer.},
    sortshorthand = {NatArch},
}

@customb{natarch:presabc,
    title = {President ABC Papers. A subtitle to let it reach a second line.},
    shorthand = {NatArch -- ABC},
    sortshorthand = {NatArch -- ABC},
    xref = {natarch},
}

@customb{natarch:mintru,
    title = {Ministry of Truth Papers. Fully and continuously updated.},
    shorthand = {NatArch -- MT},
    sortshorthand = {NatArch -- MT},
    xref = {natarch},
}

@customa{libcong,
    title = {Library of Congress},
    sortshorthand = {LibCon},
}

@customb{libcong:digcoll,
    title = {Digital Collections of the Library of Congress. But with a title long enough to span two lines.},
    shorthand = {LibCon -- DC},
    sortshorthand = {LibCon -- DC},
    xref = {libcong},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\DeclareBiblistFilter{primary}{
    \filteror{
        \filter[type=type,filter=customa]
        \filter[type=type,filter=customb]
    }
}

\DeclareBibliographyDriver{primary}{%
    \usebibmacro{bibindex}%
    \usebibmacro{begentry}%
    \printfield{title}%
    \usebibmacro{finentry}}

\DeclareBiblistFilter{primary}{
    \filteror{
        \filter[type=type,filter=customa]
        \filter[type=type,filter=customb]
    }
}

\DeclareSortingTemplate{primary}{
  \sort{
    \field{sortshorthand}
  }
  \sort{
    \field{shorthand}
  }
}

\defbibenvironment{primary}
  {\list
       {}
       {\setlength{\leftmargin}{\bibhang+\biblabelsep}%
        \setlength{\itemindent}{-\leftmargin}%
        \setlength{\itemsep}{\bibitemsep}%
        \setlength{\parsep}{\bibparsep}%
        \renewcommand*{\makelabel}[1]{##1\hss}}}
  {\endlist}
  {\ifentrytype{customa}
      {\item}{}%
   \ifentrytype{customb}
      {\setlength{\labelwidth}{\shorthandwidth}%
            \setlength{\labelsep}{\biblabelsep}%
            \setlength{\itemindent}{\shorthandwidth-.5\biblabelsep}%
       \item[\printfield{shorthand}]}{}%
   }

\begin{document}

\nocite{libcong:digcoll,natarch:mintru,natarch:presabc}
\printbiblist[title={Primary sources}]{primary}

\end{document}

Resulting in:

primary

moewew commented 5 years ago

I probably won't have time to look into this any time soon, but in case someone else or future me is interested in looking at this I should probably mention that while answering https://tex.stackexchange.com/q/463318/ there were two main obstacles to overcome:

  1. The general workings of the punctuation tracker. The punctuation tracker usually assumes that all text flows in the same paragraph. If list environments start introducing line/paragraph breaks, it might be a bit more tricky to make sure the punctuation ends up in the right place.
  2. The \leavevmodes sprinkled throughout the biblatex code (the code is mainly concerned with the punctuation tracker) can throw off \items.