3

I'm using Biblatex/Biber with the phys style. I would like to highlight selected references in the text with an asterisk, i.e. the number should be marked. A \cite{key1,highlightedkey,key2} should result in something like [13,78*,99] in the text.

I found this solution to a similar problem: Is it possible to mark designated entries in a bibliography with an asterisk? But there, the entry is highlighted in the bibliography. Is there a way to achieve what I'm looking for?

JSK
  • 51
  • 3

2 Answers2

2

A solution that works quite well for me:

added to preamble:

\renewcommand{\postnotedelim}{}
\DeclareFieldFormat{postnote}{#1}

then use:

\cites{key1}[][$^\ast$]{highlightedkey}{key3}

gives me the output I was looking for.

Please note that this solution may not apply to anyone as the postnote behavior is changed for the entire document. (No problem in my case.)

egreg
  • 1,121,712
JSK
  • 51
  • 3
1

If we use the category approach we can automate this behaviour.

\DeclareBibliographyCategory{asterisk}

We use a macro to avoid having to type too much

\newcommand*{\addcat}{%
  \ifcategory{asterisk}%
    {*}%
    {}%
}

Then we add the asterisk to the bibliography with

\renewbibmacro*{begentry}{\addcat}

Finally, we patch relevant numeric-comp macros to also include the asterisk if need be (you will need the xpatch package for that). Which macros we need to modify heavily depends on the style, phys is based on numeric-comp. A rule of thumb is that every \printfield{labelnumber} needs an additional \addcat.

\xpatchbibmacro{cite:comp:comp}
  {\printfield{labelnumber}}{\printfield{labelnumber}\addcat}
  {}{\typeout{failed to patch cite:comp:comp macro}}

\xpatchbibmacro{cite:comp:end}
  {\printfield{labelnumber}}{\printfield{labelnumber}\addcat}
  {}{\typeout{failed to patch cite:comp:comp macro}}

\xpatchbibmacro{cite:comp:inset}
  {\printfield{labelnumber}}{\printfield{labelnumber}\addcat}
  {}{\typeout{failed to patch cite:comp:comp macro}}

Works to be marked with an asterisk are handed over to \addtocategory{asterisk}{<citekey>} as in

\addtocategory{asterisk}{geer,knuth:ct:b}

MWE

\documentclass[12pt,a4paper]{article}
\usepackage[style=numeric-comp]{biblatex}
\usepackage{xpatch}
\usepackage{hyperref}
\addbibresource{biblatex-examples.bib}

\DeclareBibliographyCategory{asterisk}
\newcommand*{\addcat}{%
  \ifcategory{asterisk}%
    {*}%
    {}%
}
\renewbibmacro*{begentry}{\addcat}


\xpatchbibmacro{cite:comp:comp}
  {\printfield{labelnumber}}{\printfield{labelnumber}\addcat}
  {}{\typeout{failed to patch cite:comp:comp macro}}

\xpatchbibmacro{cite:comp:end}
  {\printfield{labelnumber}}{\printfield{labelnumber}\addcat}
  {}{\typeout{failed to patch cite:comp:comp macro}}

\xpatchbibmacro{cite:comp:inset}
  {\printfield{labelnumber}}{\printfield{labelnumber}\addcat}
  {}{\typeout{failed to patch cite:comp:comp macro}}


\addtocategory{asterisk}{geer,knuth:ct:b}


\begin{document}
This is just filler text \cite{geer}. This is just filler
text \cite{worman}. This is just filler
text \cite{geer}.

Text \cite{knuth:ct:a} an \cite{knuth:ct:b} again \cite{knuth:ct:a,geer,worman}.

\printbibliography
\end{document}

enter image description here


You can also let the asterisk only appear at the first citation if you enable citetracker=true and change \addcat to

\newcommand*{\addcat}{%
  \ifboolexpr{(not test {\ifciteseen} or test {\ifbibliography})
              and test {\ifcategory{asterisk}}}
    {*}%
    {}%
}
moewe
  • 175,683