5

I have an article in which I want to place symbols before some of my references, indicating their role in the work. For example, some of them might just be ordinary references while others might point to datasets that I've been analysing.

Below is a minimal working example where I've been using the APA style for the references and where the different types are indicated both by Keywords and by Symbol (the latter indicating which symbol I would like to put in front of the reference in question).

\documentclass[man]{apa6}
\usepackage{filecontents,showframe}
\usepackage[american]{babel}
\usepackage{csquotes} 
\usepackage[style=apa]{biblatex}
\DeclareLanguageMapping{american}{american-apa}
\usepackage[T1]{fontenc}
\shorttitle{This is the title of the article}

\begin{filecontents*}{mybib.bib}
@article{ID1,
    Author = {Some Author},
    Journal = {Journal of Non-existence},
    Title = {Being on the top: How it feels},
    Year = {2014},
    Volume = {1},
    Pages = {1-10},
    Keywords = {Reference},
    Symbol = {}}

@article{ID2,
    Author = {Some Dufus},
    Journal = {Scandinavian Journal of Bogus},
    Title = {Second to none (except to one)},
    Year = {2015},
    Volume = {2},
    Pages = {11-20},
    Keywords = {Database},
    Symbol = {*}}

@article{ID3,
    Author = {Some Writer},
    Journal = {Journal of Fake},
    Title = {Number number three: How it feels},
    Year = {2016},
    Volume = {3},
    Pages = {21-30},
    Keywords = {Data received via e-mail},
    Symbol = {**}}

\end{filecontents*}
\addbibresource{mybib.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

The code above gives me the following output:

enter image description here

In this specific case, what I would like to achieve is for the first reference to be as it is, for the second reference to have "* " in front of it and for the third reference to have "** " in front of it.

How can I achieve this? I have total control over my bib-file and can add/remove rows according to certain rules or subset it into different files with different content if necessary.

(Note that this question differs from example this one and this one since I'm trying to to accomplish this using several different symbols rather than just one. It's non-trivial how one could extend the answers given for those questions to the problem I'm having.)

From comment: I've tried to modify the answers given in the linked questions for multiple hours now without success, and I wrote my whole master thesis using LaTeX. Either it's really not that trivial or I'm having a brain haemorrhage. (Here's rooting for the first alternative.)

  • 1
    Have a look at tex.stackexchange.com/a/103862/16895. Given that you specify the symbol in the bibtex file the solution in the link above can be changes as \renewbibmacro{begentry}{\printfield{symbol}} – Guido Jul 4 '16 at 21:22
  • @Guido I tried replacing the \renewbibmacroblock from PLK's code with your code without any success. The file compiles, but the references looks like normal. – Speldosa Jul 5 '16 at 12:43
  • @Guido Same goes for editing your answer given in the link. – Speldosa Jul 5 '16 at 12:53
  • @moewe Thanks! However, that question also only handles how to add a single symbol to some of the references. I'm trying to have several different symbols, and I find it non-trivial how to extend for example the answer you linked to my situation. – Speldosa Jul 5 '16 at 18:31
4

You can define a new entry option extsymb where you can give an arbitrary symbol to be printed before the entry in the bibliography

\makeatletter
\providecommand{\bib@extsym}{}
\DeclareEntryOption[string]{extsym}{\renewcommand{\bib@extsym}{#1}}
\renewbibmacro*{begentry}{\printtext{\bib@extsym}}
\makeatother

this is used as

options       = {extsym={*}},

in the .bib entry.

MWE

\documentclass[american]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber, style=apa]{biblatex}
\DeclareLanguageMapping{american}{american-apa}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{bohec,
  author        = {Le Bohec, Yann},
  title         = {Histoire militaire des guerres puniques},
  date          = {1996},
  location      = {Monaco},
  publisher     = {Rocher},
  isbn          = {2-268-02147-5},
  options       = {extsym={**}},
}
@book{uthor,
  author        = {Uthor, Arnold},
  title         = {A Book},
  date          = {2013},
  location      = {Place},
  publisher     = {P. Ublisher's \& Co.},
  options       = {extsym={*}},
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\makeatletter
\providecommand{\bib@extsym}{}
\DeclareEntryOption[string]{extsym}{\renewcommand{\bib@extsym}{#1}}
\renewbibmacro*{begentry}{\printtext{\bib@extsym}}
\makeatother

\begin{document}
  \cite{wilde,cicero,coleridge,vangennep,bohec,uthor}
  \printbibliography
\end{document}

example output


You can of course also extend the methods from Functionality of apacites \nocitemeta with biblatex-apa: adding asterisks to author lastnames (meta-analysis)

\DeclareBibliographyCategory{asterisk}
\DeclareBibliographyCategory{doubleasterisk}
\renewbibmacro*{begentry}{%
  \ifcategory{asterisk}%
    {*}%
    {}%
  \ifcategory{doubleasterisk}%
    {**}%
    {}%
}

Where you then have

\addtocategory{asterisk}{uthor}
\addtocategory{doubleasterisk}{bohec}

in your .tex file.


Lastly, you can use keywords

\renewbibmacro*{begentry}{%
  \ifcategory{asterisk}%
    {*}%
    {}%
  \ifcategory{doubleasterisk}%
    {**}%
    {}%
}

with

@book{uthor,
  author        = {Uthor, Arnold},
  title         = {A Book},
  date          = {2013},
  location      = {Place},
  publisher     = {P. Ublisher's \& Co.},
  keywords      = {asterisk},
}

in the .bib file.

  • Thanks for the answer! Running the MWE in solution1 gave me the following error: ! LaTeX Error: Missing \begin{document}. ... l.35 \DeclareEntryOption[string]{extsym}{\renewcommand{\bib@extsym}{#1}}. For solution 2, I got the following error: ! Package biblatex Error: Category 'asterisk' not declared. ... l.46 \addtocategory{asterisk}{uthor}(I tried to extend the code and place my code blocks at different places in relation to each other to no avail.) Solution 3 compiled fine, but generated no symbols in the references. The list just looked as usual. – Speldosa Jul 7 '16 at 11:59
  • 1
    @Speldosa For solution 1 I guess your biblatex could be too old. Your problem with solution 2 baffles me, because as you can see in the very first line of my code, we define the category asterisk. Solution 3 should work as well, if you add the keywords to your .bib file. (Do the keywords appear in the .bbl file?) If still have problems, please ping me again with a full MWE of what you tried and more descriptions of how it didn't work for you. – moewe Jul 7 '16 at 13:55
  • Yeah, I've been sporting MacTeX 2015, but that was apparently to arcane. Updated to MacTeX 2016 and everything finally worked out. Thanks! – Speldosa Jul 7 '16 at 16:21
4

You might do this using the biblatex 3.4+/biber 2.5+ Data Annotation feature although the linked article from @Guido's comment is also a good solution since you are annotating entries rather than fields in an entry.

\documentclass[man]{apa6}
\usepackage{filecontents,showframe}
\usepackage[american]{babel}
\usepackage{csquotes} 
\usepackage[style=apa]{biblatex}
\DeclareLanguageMapping{american}{american-apa}
\usepackage[T1]{fontenc}
\shorttitle{This is the title of the article}

\begin{filecontents*}{mybib.bib}
@article{ID1,
    Author = {Some Author},
    Author+an = {=ref},
    Journal = {Journal of Non-existence},
    Title = {Being on the top: How it feels},
    Year = {2014},
    Volume = {1},
    Pages = {1-10},
    Keywords = {Reference}}

@article{ID2,
    Author = {Some Dufus},
    Author+an = {=db},
    Journal = {Scandinavian Journal of Bogus},
    Title = {Second to none (except to one)},
    Year = {2015},
    Volume = {2},
    Pages = {11-20},
    Keywords = {Database}}

@article{ID3,
    Author = {Some Writer},
    Author+an = {=data},
    Journal = {Journal of Fake},
    Title = {Number number three: How it feels},
    Year = {2016},
    Volume = {3},
    Pages = {21-30},
    Keywords = {Data received via e-mail}}

\end{filecontents*}
\addbibresource{mybib.bib}
\renewbibmacro*{name:hook}[1]{%
  \iffieldannotation{db}
    {*}
    {}%
  \iffieldannotation{data}
    {**}
    {}}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

enter image description here

  • Running this code with xelatex gave me the following error: ! Undefined control sequence. \abx@macro@name:hook #1->\iffieldannotation {db} {*} {}\iffieldannotation {d... l.53 \end {document}. Replacing the \iffieldannotationwith \ifkeyword and specifying the keywords I want to look for within the brackets works, but then an asterisk is printed in front of each author's name (if there are several), not just in front of the first. – Speldosa Jul 5 '16 at 12:41
  • Which version of biblatex/biber are you using? – PLK Jul 5 '16 at 20:38
  • This is XeTeX, Version 3.14159265-2.6-0.99992 (TeX Live 2015) (preloaded format=xelatex) and INFO - This is Biber 2.1. – Speldosa Jul 6 '16 at 21:57
  • 1
    That's all too old. Data annotations were introduced in biblatex 3.4/biber 2.5 and so you'll need to update both packages. – PLK Jul 7 '16 at 15:23
  • Yeah, you're right. I updated from MacTeX 2015 to MacTeX 2016 and got it to work. – Speldosa Jul 7 '16 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.