moewew / biblatex-ext

Extensions for the biblatex standard styles
LaTeX Project Public License v1.3c
24 stars 3 forks source link

Make introcite settabel on per-entry basis #13

Closed denismaier closed 5 years ago

denismaier commented 5 years ago

Sometimes I want to have the shorthand in the bibliography. In biblatex-dw I can use the option shorthandinbib that prints shorthands at the beginning of the respective entry. I thought I could use introcite for this, but it seems that this option is not usable for single entries. Would it be an option to make introcite settable on a per-entry basis?

moewew commented 5 years ago

Thank you for that suggestion.

introcite=label must apply to a bibliography in its entirety, so that value does not really lend itself to entry- or type-specific options. introcite=plain on the other hand has no such issue, so that could be implemented. I'll see what I can come up with.

For what it's worth, it is not too complicated to steal the code for shorthandinbib from biblatex-dw, so it might turn out that you don't have any need for introcite at all.

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

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

\addbibresource{biblatex-examples.bib}

\DeclareFieldFormat{shorthandinbib}{\mkbibbrackets{#1}}
\newcommand*{\shorthandinbibpunct}{\addspace}
\renewbibmacro*{begentry}{%
  \ifboolexpr{test {\ifcsstring{blx@delimcontext}{bib}}
              and not test {\ifcitation}}
    {\iffieldundef{shorthand}
      {}
      {\printfield[shorthandinbib]{shorthand}%
       \printunit*{\shorthandinbibpunct}}}
    {}}

\begin{document}
\cite{sigfridsson,kant:kpv}
\printbibliography
\end{document}

In this case I would say that the shorthandinbib is nicer than introcite, because it does what you want: You want the shorthand displayed in the bibliography, you do not want the citation label shown for some entries.

biblatex offers \printbiblist{shorthand} to resolve shorthands.

denismaier commented 5 years ago

Absolutely, shorthandinbib is much nicer. Would it be an option to add this to the extended standard styles? I know that I could use the code from biblatex-dw in my preamble, but I would prefer a cleaner preamble, and I also think that this might be a very useful extension.

(I guess you are aware of that, but I want to add that the code in biblatex-dw is actually a bit more complete. The code in your example will output all shorthands in the bibliography. In biblatex-dw it is possible to enableshorthandinbib for individual entries only or for all entries with shorthands. Also biblatex-dw checks whether we are in the bibliography or in the list of shorthands. Obviously, we wouldn't want the shorthand printed twice in the list of shorthands.)

moewew commented 5 years ago

https://github.com/moewew/biblatex-ext/commit/2b0a7df6237cecd54e953ba185d32431bf43e7bc enables introcite on a per-entry and per-type level. As mentioned above only introcite=plain can be guaranteed to work in those situations, so introcite=label issues a warning when used at those levels.

I'm a bit on the fence whether or not I should implement something like biblatex-dw's shorthandinbib. Despite the details you rightfully pointed out I still believe that for the most part it is easy to recreate what that option does with a few lines of code, so I don't think that it warrants inclusion in biblatex-ext. On the other hand I don't quite like the solution biblatex-dw took for dealing with the 'detail' of not printing the shorthand twice in the list of shorthands, but I have nothing better to offer myself.

moewew commented 5 years ago

v0.6 allows you to set introcite on a per-entry basis. As mentioned before, only introcite=plain makes sense on a per-entry basis, since introcite=label needs support of the bibliography environment.

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

\usepackage[style=ext-authoryear, backend=biber]{biblatex}

\DeclareFieldFormat{bbx@introcite}{\mkbibbold{#1}}

\usepackage{filecontents}
\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},
  journal = {Journal of Computational Chemistry},
  year    = 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},
}
@misc{elk,
  author   = {Anne Elk},
  title    = {A Theory on Brontosauruses},
  url      = {http://www.example.edu/~elk/bronto.pdf},
  year     = {2016},
  options  = {introcite=plain},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\cite{sigfridsson,elk}
\printbibliography
\end{document}

If there still is interest in something similar to shorthandinbib I suggest you open a new issue about that, so we can discuss this in more detail. I'm still not sure how much I like the idea of implementing it, but at least we then have a place for discussions.