# custom citation format based on custom tag in .bib-file

first off: I will very much try to do this myself. I'll probably fail epicly but at least I will have tried :)

If you look into my post history, you will notice I am (forced to) create my own APA-style. My university is very strict on this and points will be deducted if you miss against their citation-laws... During a draft-meeting of my current paper, I was pointed to such a failure.

I would like to use this book in my paper. As you can see, the APA-style is mentioned so this should be a breeze...

However, this book was created in 1947, but it is an edition of a text from back in 1626. Therefor, we have to use the special-invented-university-format:

EDITORS (ed.) (YEAR). AUTHOR. TITLE. (EDITION). PLACE: PUBLISHER.

Meertens, P.J.,N.B. Tenhaef & A. Komter-Kuipers (ed.) (1942). Adrianus Valerius. Nederlandtsche gedenck-clanck. Amsterdam: wereldbibliotheek.

It gets even better :( - If you point to a chapter (The life of Adrianus), written by one of the EDITORS (Meertens), that should also become an entry in the bibliography:

AUTHOR_OF_CHAPTER (YEAR). 'TITLE_OF_CHAPTER'. In: WORK_ABOVE

Meertens, P.J. (1942). 'The Life of Adrianus'. In: Meertens, P.J.,N.B. Tenhaef & A. Komter-Kuipers (ed.) (1942). Adrianus Valerius. Nederlandtsche gedenck-clanck. Amsterdam: wereldbibliotheek.

This! however, should not be confused by a book with multiple writers. Notice (the total lack of) difference :/

The correct citation for this book is

AUTHORS (YEAR). TITLE. (EDITION). PLACE: PUBLISHER.

Absillis, K., Jaspers, J., & Van Hoof, S. (2000). De manke usurpator : over verkavelingsvlaams. Gent: Academia press.

Jaspers, J. (2000). 'Some chapter'. In: Absillis, K., Jaspers, J., & Van Hoof, S. (red.). (2000). De manke usurpator : over verkavelingsvlaams. Gent: Academia press.

first: the simple questions

• 3de ed. should become (3e dr.) << that e is superscript.
• 'title' should have single quotes, not double ones - found it (not reflected in the screenshot above the MWE)

now: the main question = about the last two entries of the bibliography.

How can I have biblatex differentiate between these two different type of @books? Can I program a macro in such way that it checks for

• This book has an author and a (or multiple) editors => must be type 1, format accordingly
• This book has only authors => must be type 2, format accordingly
• This book has only editoros => zotero turns this into an @collection, so this falls out of the scope of this question because this is about @books.

the working example:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{refs.bib}
@book{ValeriusNederlandtschegedenckclanck1942,
langid = {dutch},
location = {{Amsterdam}},
title = {Nederlandtsche gedenck-clanck},
pagetotal = {287},
publisher = {{Wereldbibliotheek}},
date = {1942},
author = {Valerius, Adrianus},
editor = {Meertens, Pieter Jacobus and Tenhaeff, Nicolaas Bernardus and Komter-Kuipers, Aafke}
}

langid = {dutch},
location = {{Amsterdam}},
title = {Adriaen Valerius' leven en werken},
booktitle = {Nederlandtsche gedenck-clanck},
publisher = {{Wereldbibliotheek}},
date = {1942},
pages = {V-XXII},
author = {Meertens, Pieter Jacobus},
editor = {Meertens, Pieter Jacobus and Tenhaeff, Nicolaas Bernardus and Komter-Kuipers, Aafke}
}

@book{Usurpator-book-1,
location = {{Gent}},
title = {De Manke Usurpator},
isbn = {978-90-382-2005-5},
pagetotal = {1234},
publisher = {{Academia press}},
date = {2012},
author = {Absillis, Kevin},
edition = {1}
}

@book{Usurpator-book-2,
location = {{Gent}},
title = {De Manke Usurpator},
isbn = {978-90-382-2005-5},
pagetotal = {1234},
publisher = {{Academia press}},
date = {2012},
author = {Absillis, Kevin and Jaspers, Jürgen},
edition = {2}
}

@book{Usurpator-book-3,
location = {{Gent}},
title = {De Manke Usurpator},
isbn = {978-90-382-2005-5},
pagetotal = {1234},
publisher = {{Academia press}},
date = {2012},
author = {Absillis, Kevin and Jaspers, Jürgen and Van Hoof, Sarah},
edition = {3}
}

@incollection{Usurpator-book-3-chapter,
langid = {dutch},
location = {{Gent}},
title = {Some Chapter},
booktitle = {De Manke Usurpator},
publisher = {{Academia press}},
date = {2012},
pages = 123-145,
author = {Absillis, Kevin},
bookauthor = {Absillis, Kevin and Jaspers, Jürgen and Van Hoof, Sarah},
edition = {3}
}

\end{filecontents*}

\usepackage[dutch]{babel}               % Nederlands
\usepackage[autostyle]{csquotes}        % Context sensitive quotation facilities

\usepackage[bibstyle=authoryear,citestyle=authoryear,giveninits=true,maxnames=3,doi=false,isbn=false,dashed=false,backend=biber]{biblatex}

\DeclareDelimFormat{finalnamedelim}{\addspace\&\space}    % Multiple authors? => &

% Bold Author and Year

\DeclareFieldFormat{bold}{\mkbibbold{#1}}

\renewbibmacro*{author}{%
\printtext[bold]{%
\ifboolexpr{
test \ifuseauthor
and
not test {\ifnameundef{author}}
}
{\usebibmacro{bbx:dashcheck}
{\bibnamedash}
{\usebibmacro{bbx:savehash}%
\printnames{author}%
\iffieldundef{authortype}
{\setunit{\printdelim{nameyeardelim}}}
{\setunit{\printdelim{authortypedelim}}}}%
\iffieldundef{authortype}
{}
{\usebibmacro{authorstrg}%
\setunit{\printdelim{nameyeardelim}}}}%
{\global\undef\bbx@lasthash
\usebibmacro{labeltitle}%
\setunit*{\printdelim{nonameyeardelim}}}%

\renewbibmacro{in:}{%
\ifentrytype{article}
{}
{\printtext{\bibstring{in}\intitlepunct}}}

% article number must be between parenthesis

\renewbibmacro*{volume+number+eid}{%
\printfield{volume}%
\printfield{number}%
\printfield{eid}}
\DeclareFieldFormat[article]{number}{\mkbibparens{#1}}

% please don't put p. before pagenumbers

\DeclareFieldFormat[incollection]{pages}{#1}
\DeclareFieldFormat[article]{pages}{#1}

\AtEveryBibitem{%
\clearlist{language}%
\clearfield{pagetotal}%
}

\begin{document}

\section{Valerius}

let me quote this old text by \citeauthor{ValeriusNederlandtschegedenckclanck1942} - which was edited by \citename{ValeriusNederlandtschegedenckclanck1942}{editor}

\citeauthor{MeertensAdriaenValeriusleven1942} wrote an introduction for that text, you know!

\section{Usurpator}

\begin{itemize}
\item \cite{Usurpator-book-1}
\item \cite{Usurpator-book-2}
\item \cite{Usurpator-book-3}
\item \cite{Usurpator-book-3-chapter}
\end{itemize}

\setquotestyle{british} % easiest way for single quotes
\printbibliography
\end{document}

• Anyway, FWIW I have never seen such a style and I find it extremely illogical. For the Valerius can't you just put Adrianus Valerius into the title field? That should roughly give the expected output (give or take, as I said above I don't know what your style does at the moment). Together with a custom editortype value you could probably get "ed." instead of the standard "red.". – moewe Nov 12 '18 at 14:58
• MWE added, as per requested. - I had to leave work before I could provide it in the Original Post, you beat me to it :) – LooselySubtle Nov 12 '18 at 16:18
• Thanks. The MWE in its current form will give a wildly different output for @inbook/@incollection than you want. Is that also part of your question, will that be a future question or do you already have code for that set up? (If you consider it part of this question, please consider asking a separate, new question about it, so that you only ask one question per question. If you already have code for it set up, it might make sense to add it to the MWE.) – moewe Nov 12 '18 at 16:21
• I updated my question (left the @incollection out, will first try it myself and ask a future question about it if I can't figure it out.) my code and provided a better MWE. The 'easy questions' are also valid for this main question. – LooselySubtle Nov 12 '18 at 18:21
• I'll probably only be able to write something up tomorrow (if no one else has answered then), but if you have the time could you please check up on *Absillis, Jaspers & Van Hoof"? In the first example with that work it looks like they are authors (meaning the work should be a @book), but in the second example you use them with "(red.)" meaning they are editors in an @incollection, hence the work should be a @collection. Zotero's heuristic to export 'books' with no authors and only editors as @collection is quite good (as a rule of thumb, of course there might be edge cases). – moewe Nov 12 '18 at 21:05

While I still think that the desired style for @books with editors and authors is completely bizarre in almost all cases, there might be some cases where one would want to stress the editor or translator of a work over the actual author (translations of classical texts come to mind or heavily edited, commented and annotated works). In those cases one could use the option useauthor=false to move the author to after the title and promote the editor or translator to the primary spot (see butler_frankenstein_1998 in the example below taken from Which bibtex style lists book editor first?, and aristotle:physics taken from samcarter's answer to Citing a translator), the demoted author will then be mentioned after the title.

I understand that your ValeriusNederlandtschegedenckclanck1942 is a special case. The original work from 1626 by Valerius in itself was already borderline as to whether it was a @book and Valerius its author or a @collection and Valerius its editor. Adding more editors of a later edition into the mix does not make the situation simpler.

But I still think that placing the author/editor directly between the year and the title is weird even in this case and I don't think it makes sense to rewrite the style for what I regard as a half-baked ad-hoc requirement. Note how in the required output it is impossible to tell that "Adrianus Valerius" is the original author/editor, instead the name seems to be part of the title. That is what I would exploit: If the style guide formats the name exactly as the title, we can just add the name to the title field and be done with it.

For this particular entry you also want to change the editor label from "red." to "ed.", that can be achieved with the editortype field. We can define a new 'editor type' specialed (you could have a look at dutch.lbx to see if one of the other types would be more appropriate) by defining the three bibstrings specialed (singular), specialeds (plural form) and byspecialed ("edited by ..." form) and giving them the desired values. You can then add the field editortype = {specialed}, to all works whose editors are to be "ed." instead of "red.".

Note that after reading https://www.academiapress.be/nl/producten/nederlandse-taal-en-letterkund/de-manke-usurpator I would class the Usurpatores as @collection and not @book. The requirements

Absillis, K., Jaspers, J., & Van Hoof, S. (2000). De manke usurpator : over verkavelingsvlaams. Gent: Academia press.

Jaspers, J. (2000). 'Some chapter'. In: Absillis, K., Jaspers, J., & Van Hoof, S. (red.). (2000). De manke usurpator : over verkavelingsvlaams. Gent: Academia press.

were a bit inconsistent in that regard. I would have expected Absillis, Jaspers & Van Hoof to be either "red" in both cases or not at all. Changing that between the complete work and a chapter seems terribly inconsistent.

In general you may benefit from using crossref more often.

For the most part the difference between @collection and @book is very small: About the only big difference is that @collection will simply ignore any author. Similarly @inbook and @incollection are very similar. Choosing the "right" type is then often more a question of semantics and having a "nice" database, rather than a question of different results in the output. If you apply changes for @collection and @incollection usually they can be mapped one-to-one to changes for @book and @inbook and usually it is a good idea to apply these changes there as well to avoid inconsistencies.

In the case you mentioned in the question I agree with Zotero's heuristic that it makes sense to classify a 'book' with editors and no authors as @collection. There may be the occasional exception, but as a rule of thumb it's pretty solid.

I would try the following

\documentclass{article}
\usepackage[dutch]{babel}
\usepackage[autostyle]{csquotes}

\usepackage[style=authoryear, backend=biber,
giveninits=true, uniquename=init, maxnames=3, dashed=false,
doi=false, isbn=false]{biblatex}

\letbibmacro*{author:unwrapped}{author}
\renewbibmacro{author}{%
\printtext[bold]{\usebibmacro{author:unwrapped}}}

\DeclareFieldFormat{editortype}{\mkbibparens{#1}}

\letbibmacro*{editor:unwrapped}{editor}
\renewbibmacro{editor}{%
\printtext[bold]{\usebibmacro{editor:unwrapped}}%
\ifuseeditor{\clearname{editor}}{}}

\letbibmacro*{editor+others:unwrapped}{editor+others}
\renewbibmacro{editor+others}{%
\printtext[bold]{\usebibmacro{editor+others:unwrapped}}%
\ifuseeditor{\clearname{editor}}{}}

\DeclareFieldAlias{translatortype}{editortype}
\DeclareDelimAlias{translatortypedelim}{editortypedelim}

\letbibmacro*{translator:unwrapped}{translator}
\renewbibmacro{translator}{%
\printtext[bold]{\usebibmacro{translator:unwrapped}}%
\ifusetranslator{\clearname{translator}}{}}

\letbibmacro*{translator+others:unwrapped}{translator+others}
\renewbibmacro{translator+others}{%
\printtext[bold]{\usebibmacro{translator+others:unwrapped}}%
\ifusetranslator{\clearname{translator}}{}}

\NewBibliographyString{specialed,specialeds,byspecialed}
\DefineBibliographyStrings{dutch}{
byspecialed = {geredigeerd door},% wat gaan we hier doen?
}

% "De achtervoegsels -ste, -de en -e staan op dezelfde hoogte als het getal."
\DefineBibliographyExtras{dutch}{%
\protected\def\mkbibordinal#1{\stripzeros{#1}\textsuperscript{e}}%
}
\DeclareFieldFormat{edition}{%
\mkbibparens{%
\ifinteger{#1}
{#1\isdot}}}

\renewbibmacro{in:}{%
\ifentrytype{article}
{}
{\printtext{\bibstring{in}\intitlepunct}}}

\renewbibmacro*{volume+number+eid}{%
\printfield{volume}%
\printfield{number}%
\printfield{eid}}
\DeclareFieldFormat[article]{number}{\mkbibparens{#1}}

\DeclareFieldFormat{pages}{#1}

\AtEveryBibitem{%
\clearlist{language}%
\clearfield{pagetotal}}

\DeclareQuoteStyle{dutch}
{\textquoteleft}
{\textquoteright}
[0.05em]
{\textquotedblleft}
{\textquotedblright}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@collection{ValeriusNederlandtschegedenckclanck1942,
langid    = {dutch},
location  = {Amsterdam},
title     = {Adrianus Valerius. Nederlandtsche gedenck-clanck},
pagetotal = {287},
publisher = {Wereldbibliotheek},
date      = {1942},
editor    = {Meertens, Pieter Jacobus and Tenhaeff, Nicolaas Bernardus and Komter-Kuipers, Aafke},
editortype = {specialed},
}
title     = {Adriaen Valerius' leven en werken},
date      = {1942},
pages     = {V-XXII},
author    = {Meertens, Pieter Jacobus},
crossref  = {ValeriusNederlandtschegedenckclanck1942},
}
@collection{Usurpator-book-1,
location  = {Gent},
title     = {De Manke Usurpator},
isbn      = {978-90-382-2005-5},
pagetotal = {1234},
publisher = {{Academia press}},
date      = {2012},
editor    = {Absillis, Kevin},
edition   = {1}
}
@collection{Usurpator-book-2,
location  = {{Gent}},
title     = {De Manke Usurpator},
isbn      = {978-90-382-2005-5},
pagetotal = {1234},
publisher = {{Academia press}},
date      = {2012},
editor    = {Absillis, Kevin and Jaspers, Jürgen},
edition   = {2}
}
@collection{Usurpator-book-3,
location  = {Gent},
title     = {De Manke Usurpator},
isbn      = {978-90-382-2005-5},
pagetotal = {1234},
publisher = {{Academia press}},
date      = {2012},
editor    = {Absillis, Kevin and Jaspers, Jürgen and Van Hoof, Sarah},
edition   = {3}
}
@incollection{Usurpator-book-3-chapter,
title      = {Some Chapter},
pages      = {123-145},
author     = {Absillis, Kevin},
crossref   = {Usurpator-book-3},
}
@book{butler_frankenstein_1998,
address    = {Oxford and New York},
series     = {Oxford world's classics},
title      = {Frankenstein, or, {The} modern {Prometheus}},
subtitle   = {the 1818 text},
isbn       = {978-0-19-283366-2},
publisher  = {Oxford University Press},
author     = {Shelley, Mary Wollstonecraft},
editor     = {Butler, Marilyn},
year       = {1998},
options    = {useauthor=false},
}
@book{aristotle:physics,
options    = {useauthor=false,usetranslator=true},
author       = {Aristotle},
title        = {Physics},
date         = 1929,
translator   = {Wicksteed, P. H. and Cornford, F. M.},
publisher    = {G. P. Putnam},
location     = {New York},
keywords     = {primary},
langid       = {english},
langidopts   = {variant=american},
shorttitle   = {Physics},
annotation   = {A \texttt{book} entry with a \texttt{translator} field},
}
\end{filecontents*}

\begin{document}
\section{Valerius}

let me quote this old text by \citeauthor{ValeriusNederlandtschegedenckclanck1942} which was edited by \citename{ValeriusNederlandtschegedenckclanck1942}{editor}.

\citeauthor{MeertensAdriaenValeriusleven1942} wrote an introduction for that text, you know!

\section{Usurpator}
\begin{itemize}
\item \cite{Usurpator-book-1}
\item \cite{Usurpator-book-2}
\item \cite{Usurpator-book-3}
\item \cite{Usurpator-book-3-chapter}
\end{itemize}

\section{Oter examples}
\cite{aristotle:physics,butler_frankenstein_1998}

\printbibliography
\end{document}


• first off: I highly appreciate your work on this community and for me. I do not take this for granted and therefor I would like to buy you a coffee. Do you have a donate-me-a-coffee-page or a paypall I can send you some brown nectar to? – LooselySubtle Nov 13 '18 at 9:56
• about Valerius being a special case: You can treat this book the same way as you would a heavily edited or translated work; in this case it would be the butler_frankenstein_1998 case. A translated work - wouldn't you know it - has yet another format :/ – LooselySubtle Nov 13 '18 at 9:58
• about your note whether the 'usurpator' is a @book or @collection: I did not edit the OP enough. As you can see now: a book with only authors is a @book. the (red) should not be added, sorry for that. – LooselySubtle Nov 13 '18 at 10:03
• @LooselySubtle Your suggested edit had a slight syntax problem. It was missing the 'false' branch of the \ifinteger conditional. I fixed that and slightly changed the order of the commands. The result should be as expected. – moewe Nov 13 '18 at 12:42
• @LooselySubtle You can get "In: Meertens, P. J., N. B. Tenhaeff & A. Komter-Kuipers (ed.) (1942). Adrianus Valerius. Nederlandtsche gedenck-clanck". But I thought you would ask a new question about that. If you are using a current LaTeX installation with biblatex 3.11 or 3.12 installed and can install biblatex-ext that should be pretty straightforward. In this question I was focussing on the position of the "Adrianus Valerius" and the "ed."/"red." thing. – moewe Nov 13 '18 at 12:51