plk / biblatex-apa

APA style for BibLaTeX
90 stars 48 forks source link

External abstracts and annotations as per biblatex manual 4.11.3 #126

Closed jrmoserbaltimore closed 2 years ago

jrmoserbaltimore commented 4 years ago

Please add external abstracts and annotations as per section 4.11.3 of the biblatex manual.

jrmoserbaltimore commented 4 years ago

I think something like the below would work, but I haven't tested and don't know much about all this.

\renewbibmacro*{annotation}{%
  \ifboolexpr{       test {\iffieldundef{annotation}}
              and not test {\IfFileExists{\bibannotationprefix\thefield{entrykey}.tex}}
    {}
    {
    \ifboolexpr{ togl {bbx:annotation}}
    {
    \begingroup
     \togglefalse{blx@bibliography}%
     \newline
     \setunit{}%
     \iffieldundef{annotation}
     {%
       \printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}%
     }%
     {%
       \printfield{annotation}%
     }%
     \endgroup}%
     {}
     }

Tests if the file exists, then decides which approach to use.

I think it really needs to test if the file exists and loadfiles=true to work properly, else when loadfiles=false it will print out a blank annotation. Also I'm not sure the syntax for if (a and b) or c.

Same approach for abstract.

plk commented 4 years ago

Annotation makes sense but APA doesn't use abstracts and this field isn't used at all in the style currently.

plk commented 4 years ago

Support for external annotations will be in the next version. You can replace this if you want it now:

\renewbibmacro*{annotation}{%
  \ifboolexpr{test {\iffieldundef{annotation}}
              or not togl {bbx:annotation}}
    {\IfFileExists{\bibannotationprefix\thefield{entrykey}.tex}
       {\begingroup
        \togglefalse{blx@bibliography}%
        \newline
        \setunit{}%
        \printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}%
        \endgroup}
      {}}
    {\begingroup
     \togglefalse{blx@bibliography}%
     \newline
     \setunit{}%
     \printfield{annotation}%
     \endgroup}}
jrmoserbaltimore commented 4 years ago

Thanks. Yeah I was just reading out the stuff in bibtex. I though the APA style was used by a number of journals in social and behavioral sciences, but personally I don't care about abstracts in the context of compiling an annotated bibliography and don't know how the abstract field is even useful.

jrmoserbaltimore commented 4 years ago

I've tested this and found an issue: it prints the external bibliography if annotation=false.

It looks like if the annotation field doesn't exist OR annotation=false it prints the external bibliography.

Perhaps something like this?

\renewbibmacro*{annotation}{%
\ifboolexpr{togl {bbx:annotation}}
    {\iffieldundef{annotation}{\IfFileExists{\bibannotationprefix\thefield{entrykey}.tex}
       {\begingroup
        \togglefalse{blx@bibliography}%
        \newline
        \setunit{}%
        \printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}%
        \endgroup}
      {}}
    {\begingroup
     \togglefalse{blx@bibliography}%
     \newline
     \setunit{}%
     \printfield{annotation}%
     \endgroup}}}
     {}

That seems to respect the annotation={true|false} setting.

moewew commented 4 years ago

I think this could all be simplified a bit if there were a way to append to the punctuation buffer. (In fact I've thought for some time that a macro for this might be useful).

What do you think of

\long\def\blxapa@appunit#1{%
  \iftoggle{blx@keepunit}
    {}
    {\gappto\blx@unitpunct{#1}%
     \global\toggletrue{blx@unit}}}

\renewbibmacro*{annotation}{%
  \iftoggle{bbx:annotation}
    {\begingroup
     \togglefalse{blx@bibliography}%
     \blxapa@appunit{\newline}%
     \iffieldundef{annotation}
       {\printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}}
       {\printfield{annotation}}%
     \endgroup}
    {}}

We could make \blxapa@appunit an official core biblatex command once we've given it some thought.

MWE

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

\usepackage[style=apa, backend=biber, loadfiles=true, annotation=true]{biblatex}

\makeatletter
\long\def\blxapa@appunit#1{%
  \iftoggle{blx@keepunit}
    {}
    {\gappto\blx@unitpunct{#1}%
     \global\toggletrue{blx@unit}}}

\renewbibmacro*{annotation}{%
  \iftoggle{bbx:annotation}
    {\begingroup
     \togglefalse{blx@bibliography}%
     \blxapa@appunit{\newline}%
     \iffieldundef{annotation}
       {\printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}}
       {\printfield{annotation}}%
     \endgroup}
    {}}
\makeatother

\begin{filecontents}{\jobname.bib}
@book{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  date    = {1980},
}
\end{filecontents}
\begin{filecontents}{\bibannotationprefix appleby.tex}
Lorem ipsum \[x^2+y^2=z^2\] that was mathy.
Also $a+b=c$ and so forth.
Just a few words to make the next
paragraph stand out properly.

We can even have a new paragraph.
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
\cite{sigfridsson,appleby}
\printbibliography
\end{document}
plk commented 4 years ago

Yes, I like this - the annotation in APA is a bit hacky currently.

jrmoserbaltimore commented 3 years ago

I'm unclear: would this require adding the multi-line latex macro to the document, or would it work as detailed in the Biblatex manual?

jrmoserbaltimore commented 3 years ago

Also, using the version I suggested fixes the thing with using annotated bibliography when it's disabled, but it prints finentry at the end of each annotation. Unsure why.

Does APA define a style for annotations?

jrmoserbaltimore commented 3 years ago

PR #127 fixes this now.

plk commented 3 years ago

APA does have a general annotation "style" but as @moewew mentions, it would be cleaner doing this with enhancements to the punctuation buffer - not sure the status of this more general topic though - @moewew?

moewew commented 3 years ago

I opened https://github.com/plk/biblatex/issues/1048 on the biblatex bugtracker, but I wanted to wait until 3.16 is released before I look at that in more detail.

Since I usually miss something when it comes to conceptual things like this I was thinking of coming up with a proof of concept that could make it into biblatex-apa and see how it goes. If things work fine, we could then think about adding it to the biblatex core.

jrmoserbaltimore commented 3 years ago

Is that an internal consideration or does that change the commands the document itself would use to set up the annotations?

moewew commented 3 years ago

That's mostly a matter of the internal implementation and should be transparent to the user (provided they use matching biblatex and biblatex-apa version in case there is only limited backwards compatibility should we implement the new append-punctuation macro in the biblatex core).

jrmoserbaltimore commented 3 years ago

I assume then that implementing the append-punctuation macro would allow implementation of the annotation stuff in biblatex core rather than biblatex-apa and other styles, thus saving style authors a lot of work.

moewew commented 3 years ago

Just to avoid any confusion, there is already an annotation bibmacro in biblatex.def that deals with annotation fields and external files, see https://github.com/plk/biblatex/blob/7bfa1b768690053bb75e14fad39e2ecad5f05b53/tex/latex/biblatex/biblatex.def#L2928-L2934. (And whatever we do, I don't think we can significantly change the annotation bibmacro, because people may rely on its current behaviour. Though small changes are certainly not impossible if there are good reasons for them.)

biblatex-apa just needs to roll its own version of that bibmacro because it wants slightly non-standard punctuation before the field, namely a line break. That doesn't play nicely with the punctuation tracker/buffer and that's where the new 'append punctuation' comes in and can simplify things.

I like the idea of the append-punctuation macro, but it needs a bit of thought to make sure it plays well with everything that might be thrown at it. Hence my idea to 'trial' it in biblatex-apa, where the situations the macro might find itself in are a bit more restricted. If all goes well, we can move the macro to the biblatex core and change biblatex-apa to use the new core macro. If it turns out that the append-punctuation macro is harder to pull off in general, biblatex-apa could stick to what it has so far. That way we can avoid having to roll back a core biblatex macro or being stuck with a half-working implementation.

jrmoserbaltimore commented 3 years ago

Ah! That helps. I was reading this as a suggestion to implement a completely different system, rather than as a discussion on how to cleanly implement the feature in the backend. I thought you were suggesting adding the ability to stick a macro in the preamble to append things to the bibliography.

That clears things up.

plk commented 2 years ago

@moewew - do you have a sense of where we left this? I am planning a new APA release shortly to fix a few things and perhaps we can address this?

moewew commented 2 years ago

I'll prepare a PR based on my suggestion above. Then we can trial the idea of \appunit (https://github.com/plk/biblatex/issues/1048) in biblatex-apa and hopefully see how the idea plays out in practice (if only in a very controlled environment where I don't expect any issues).

moewew commented 2 years ago

See https://github.com/plk/biblatex-apa/pull/158. If you merge #158 you can close #127.

Test file, if you need something to play around with

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

\usepackage[backend=biber, style=apa, loadfiles=true, annotation=false]{biblatex}

\begin{filecontents}{\jobname.bib}
@book{elk,
  author    = {Anne Elk},
  title     = {A Theory on Brontosauruses},
  year      = {1972},
  publisher = {Monthy \& Co.},
  location  = {London},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{filecontents}{\bibannotationprefix elk.tex}
Ohh, an annotation.
\end{filecontents}

\begin{document}
Lorem \autocite{sigfridsson,elk}

\printbibliography
\end{document}