4

I'm writing a biblatex style that extends another third-party style. What I need is to \DeclareCiteCommand that \justcites an entry such a way its reference is not considered when printing the bibliography, but only when the author doesn't cite it again using any other citation command, e.g. \cite. The solution shouldn't require setting options in the \printbibliography command nor special attributes in the .bib entries, which means that all the implementation should be in my style files.

I found this and this answers and followed the category strategy, which somehow helped me:

\DeclareBibliographyCategory{refcite}

\AtEveryCitekey{%
  \ifcsstring{blx@delimcontext}{justcite}{}{%
    \addtocategory{refcite}{\thefield{entrykey}}}}

\newbibmacro*{justcite}{%
  \DeclareFieldAlias{bibhyperref}{noformat}%
  \usebibmacro{cite}}

\DeclareCiteCommand{\justcite}
 {\usebibmacro{prenote}}
 {\usebibmacro{citeindex}%
  \usebibmacro{justcite}}
 {}
 {\usebibmacro{postnote}}

\DeclareMultiCiteCommand{\justcites}
 {\justcite}
 {\setunit{\multicitedelim}}

But this way the author would need to explicitly set the category option in the \printbibliography command:

\printbibliography[category=refcite]

I also found something about refsections, but I'm not sure how I should implement this and how this could help me.

Perhaps I could set default options for the \printbibliography command directly in my style files, but I didn't find any documentation or implementation about this approach.

How could I achieve this?


The following code is a MWE of what I currently have:

\documentclass{article}
\usepackage[style=abnt]{biblatex}
\usepackage[citecolor=red, colorlinks]{hyperref}

\DeclareBibliographyCategory{refcite}

\AtEveryCitekey{%
  \ifcsstring{blx@delimcontext}{justcite}{}{%
    \addtocategory{refcite}{\thefield{entrykey}}}}

\newbibmacro*{justcite}{%
  \DeclareFieldAlias{bibhyperref}{noformat}%
  \usebibmacro{cite}}

\DeclareCiteCommand{\justcite}[\mkbibparens]
 {\usebibmacro{cite:init}%
  \usebibmacro{prenote}}
 {\usebibmacro{citeindex}%
  \usebibmacro{justcite}}
 {}
 {\usebibmacro{postnote}}

\DeclareMultiCiteCommand{\justcites}[\mkbibparens]
 {\justcite}
 {\setunit{\multicitedelim}}

\addbibresource{biblatex-examples.bib}

\begin{document}
This sentence wants to list the reference of its citation because it is important \cite{aksin}.

But not this sentence \justcite{aksin,glashow}. However, once \verb|aksin| was cited above with \verb|\cite|, it appears in the references below.

\printbibliography[category=refcite]
\end{document}

It produces the following document, which is the expected result:

produced-document

Note that the glashow reference is not listed because it was only cited by the \justcite command.

Once again, the problem is that the author must explicitly set the category option in the \printbibliography command. However, the way citations are treated when their entries are listed in references should be implicit to the author, i.e., this filtering should be implemented directly in my style files.

Based on the MWE, this means the author should have something like the following:

\documentclass{article}
\usepackage[style=my-style]{biblatex}
\usepackage[citecolor=red, colorlinks]{hyperref}

\addbibresource{biblatex-examples.bib}

\begin{document}
This sentence wants to list the reference of its citation because it is important \cite{aksin}.

But not this sentence \justcite{aksin,glashow}. However, once \verb|aksin| was cited above with \verb|\cite|, it appears in the references below.

\printbibliography
\end{document}

And this code should produce the same document.

I also believe that there must be a more generic way to solve this without the following snippet being necessary:

\AtEveryCitekey{%
  \ifcsstring{blx@delimcontext}{justcite}{}{%
    \addtocategory{refcite}{\thefield{entrykey}}}}

This also seems like a workaround to me.

By the way, the MWE uses the biblatex style I want to extend, which package is named biblatex-abnt.

7
  • 1
    Welcome to tex.sx. Apr 8 at 21:34
  • @barbarabeeton thanks!
    – Marlon
    Apr 8 at 22:56
  • Can you provide a complete example we can compile? You can use biblatex-examples.bib to save writing a sample bib file.
    – cfr
    Apr 9 at 1:02
  • @cfr of course, as soon as I can. Thanks for the tip.
    – Marlon
    Apr 9 at 1:34
  • @cfr added a MWE. I hope it helps!
    – Marlon
    Apr 9 at 15:59

1 Answer 1

3
+250

Perhaps I could set default options for the \printbibliography command directly in my style files, but I didn't find any documentation or implementation about this approach.

\DeclarePrintbibliographyDefaults is the command that you're looking for. It doesn't take a category key, but it does take a filter key, so we just need to define a filter that only matches the refcite category.

\documentclass{article}

\usepackage[style=abnt]{biblatex}
\usepackage[citecolor=red, colorlinks]{hyperref}

\DeclareBibliographyCategory{refcite}

\AtEveryCitekey{%
  \ifcsstring{blx@delimcontext}{justcite}{}{%
    \addtocategory{refcite}{\thefield{entrykey}}}}

\newbibmacro*{justcite}{%
  \DeclareFieldAlias{bibhyperref}{noformat}%
  \usebibmacro{cite}}

\DeclareCiteCommand{\justcite}[\mkbibparens]
 {\usebibmacro{cite:init}%
  \usebibmacro{prenote}}
 {\usebibmacro{citeindex}%
  \usebibmacro{justcite}}
 {}
 {\usebibmacro{postnote}}

\DeclareMultiCiteCommand{\justcites}[\mkbibparens]
 {\justcite}
 {\setunit{\multicitedelim}}

%%% BEGIN ADDED %%%
\defbibfilter{refcite}{category=refcite}
\DeclarePrintbibliographyDefaults{filter=refcite}
%%% END ADDED %%%

\addbibresource{biblatex-examples.bib}

\begin{document}
This sentence wants to list the reference of its citation because it is important \cite{aksin}.

But not this sentence \justcite{aksin,glashow}. However, once \verb|aksin| was cited above with \verb|\cite|, it appears in the references below.

\printbibliography % No [category=refcite] needed
\end{document}

output

I also believe that there must be a more generic way to solve this without the following snippet being necessary:

\AtEveryCitekey{%
  \ifcsstring{blx@delimcontext}{justcite}{}{%
    \addtocategory{refcite}{\thefield{entrykey}}}}

This also seems like a workaround to me.

Instead of defining a new bibliography category, we could use \AtEveryCitekey and a bibliography check to determine if the entry should be included in the bibliography. But we can't set a check with \DeclarePrintbibliographyDefaults, so we need to hack into private BibLaTeX macros to do this.

\documentclass{article}
\pagestyle{empty}

\usepackage[style=abnt]{biblatex}
\usepackage[citecolor=red, colorlinks]{hyperref}

\makeatletter

\def\bbx@printentry@yes{%
    \global\cslet{bbx@printentry@key@\abx@field@entrykey}\@empty%
}

\def\bbx@printentry@no{%
    \ifcsdef{bbx@printentry@key@\abx@field@entrykey}{}{%
        \global\cslet{bbx@printentry@key@\abx@field@entrykey}\bbx@printentry@no@aux%
    }%
}

\let\bbx@printentry@this=\bbx@printentry@yes

\AtEveryCitekey{%
    \bbx@printentry@this%
}

\newrobustcmd{\justcite}[2][cite]{%
    \let\bbx@printentry@this=\bbx@printentry@no
    \csname#1\endcsname{#2}%
    \let\bbx@printentry@this=\bbx@printentry@yes
}

%%% The proper way:
%
% \def\bbx@printentry@no@aux{%
%     \skipentry%
% }
%
% \defbibcheck{nojustcite}{%
%     \csname bbx@printentry@key@\abx@field@entrykey\endcsname%
% }
%
%%% [...]
%
% \printbibliography[check=nojustcite]


%%% The hacky way:
\def\bbx@printentry@no@aux{%
    \toggletrue{blx@skipentry}%
}

\def\blx@bibcheck{%
    \csname bbx@printentry@key@\abx@field@entrykey\endcsname%
}

\makeatother

\addbibresource{biblatex-examples.bib}

\begin{document}
This sentence wants to list the reference of its citation because it is
important \cite{aksin}.

But not this sentence \justcite{aksin,glashow}. However, once
\verb|aksin| was cited above with \verb|\cite|, it appears in the
references below.

We can also use other citation commands like
\justcite[citetitle]{glashow} or \justcite[Citeauthor]{aksin}.

\printbibliography
\end{document}

output

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .