plk / biblatex

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

Feature request: Implement `blx@entrytracker` #902

Open dcpurton opened 5 years ago

dcpurton commented 5 years ago

biblatex has \ifciteseen and \ifentryseen{<entrykey>}, but it only has \blx@citetracker for adding the current entry to the list of cited entries.

I am playing around with an entry type in biblatex-sbl where being able to explicitly add an entry to the list of cited entries would be useful.

Would there be a willingness to add a \blx@entrytracker{<entrykey>} feature?

\blx@citetracker could call this with the current entry as the argument in much the same way as \ifciteseen and \ifentryseen ultimately end up in the same place.

Here's a possible implementation:

\documentclass{article}
\usepackage[style=verbose]{biblatex}
\addbibresource{biblatex-examples.bib}

% Implement \blx@entrytracker

\makeatletter

% Handle options

\pretocmd{\blx@opt@citetracker@true}
  {\def\blx@entrytracker{\blx@xsanitizeafter\blx@entrytracker@global}}{}{}
\pretocmd{\blx@opt@citetracker@false}
  {\let\blx@entrytracker\relax}{}{}
\pretocmd{\blx@opt@citetracker@context}
  {\def\blx@entrytracker{\blx@xsanitizeafter\blx@entrytracker@context}}{}{}
\pretocmd{\blx@opt@citetracker@strict}
  {\def\blx@entrytracker{%
     \blx@ifcitesingle{\blx@xsanitizeafter\blx@entrytracker@global}{}}}{}{}
\pretocmd{\blx@opt@citetracker@constrict}
  {\def\blx@entrytracker{%
     \blx@ifcitesingle{\blx@xsanitizeafter\blx@citetracker@context}{}}}{}{}

% Macros

\def\blx@entrytracker@global#1{%
  \ifbool{citetracker}
    {\edef\blx@tempa{#1}%
     \xifinlistcs\blx@tempa{blx@bsee@\the\c@refsection}
       {}
       {\listcsxadd{blx@bsee@\the\c@refsection}\blx@tempa}}
    {}}

\def\blx@entrytracker@context#1{%
  \ifbool{citetracker}
    {\edef\blx@tempa{#1}%
     \iftoggle{blx@footnote}
       {\xifinlistcs\blx@tempa{blx@fsee@\the\c@refsection}
          {}
          {\listcsxadd{blx@fsee@\the\c@refsection}\blx@tempa}}
       {\xifinlistcs\abx@temp@entrykey{blx@bsee@\the\c@refsection}
          {}
          {\listcsxadd{blx@bsee@\the\c@refsection}\blx@tempa}}}
    {}}

\def\blx@citetracker@global{%
  \blx@xsanitizeafter\blx@entrytracker@global{\abx@field@entrykey}}

\def\blx@citetracker@context{%
  \blx@xsanitizeafter\blx@entrytracker@context{\abx@field@entrykey}}

\makeatother

% Execute options

\ExecuteBibliographyOptions{citetracker=true}

\begin{document}

\makeatletter
\blx@entrytracker{augustine}
\makeatother
\cite{augustine}

\end{document}
plk commented 5 years ago

I'm generally fine with adding internals to allow more tracking of just about anything as they tend to be useful. @moewew - what do you think?

moewew commented 5 years ago

This sounds like a niche feature, but a useful one nonetheless. I'm all for implementing it and would even want to go a bit further and add a similar function for all cite trackers. I'll see if that is possible without too many disturbances to the internals.

moewew commented 5 years ago

I looked at making all trackers available as ...entry versions yesterday and hit a few issues.

  1. The context version of the trackers uses \blx@ifcitesingle, which might not be available or might not apply to the correct/useful entry in the context we call the ...entry tracker macro.
  2. Some trackers like the idemtracker don't rely on the entry key, they need other field info, which might be harder to come by (we need \entrydata or similar ...).
  3. The loccit tracker might also take into account postnote data, so this would need to be dealt with as well (probably by having the user supply the postnote as an additional argument).