# Fine tuning on a crazy citation style

I'm almost there. In the past days I built a citation style according to the requests of my publisher.

The hard work was made in this thread, when we defined the behavior of Idem, Ibidem and a "Ivi".

Unfortunately, putting all the things together, something got broken. In my example, that for this reason cannot be so "minimal", I have two problems:

1. a missing comma between date and postnote in the book driver
2. a colon instead of comma after "Ivi" in footnote 3.

I tried to move things but I managed just to worsen the situation, so I'm begging again for help.

This is the not-so-minimal-WE:

% !TEX TS-program = XeLaTeX
% !TEX encoding = UTF-8 Unicode

\begin{filecontents}{archivio.bib}

@incollection{Rae:Rap,
Author = {Gilbert Raes},
Booktitle = {La S. Sindone. Ricerche e studi della commissione di esperti nominata dall'Arcivescovo di Torino},
Editor = {P. Caramello},
Pages = {79-83},
Series = {Supplemento Rivista diocesana torinese},
Title = {Rapport d'analyse},
Year = {gennaio 1976}}

@incollection{Rae:His,
Author = {Gilbert Raes},
Booktitle = {Prélèvement sur le linceul effectué le 21 avril 1988 et études du tissu},
Date-Modified = {2018-02-28 16:02:55 +0000},
Pages = {71-74},
Publisher = {\textsc{o.e.i.l.}},
Title = {Historique de l'échantillon remis le 24 novembre 1973. Problème de la bande latérale. Fibres de coton dans l'échantillon remis au laboratoire d'Oxford},
Year = {1990}}

@article{Dan:Ind,
Author = {Avinoam Danin},
Date-Modified = {2017-08-29 20:04:48 +0000},
Journal = {Il Telo},
Pages = {12-21},
Title = {Indicazioni floreali per l'origine geografica della Sindone di Torino},
Volume = {II},
Year = {2001}}

@book{Lan:Rom,
Author = {Bertrand Lancon AND Antonia Nevill},
Publisher = {Edinburgh University Press},
Title = {Rome in Late Antiquity: Everyday Life and Urban Change, \textsc{ad} 312-609},
Year = {2000}}

@book{Hal:Sul,
Editor = {C. Halm},
Langid = {german},
Number = {1},
Publisher = {C. Geroldi filium bibliopolam academiae},
Series = {\textsc{csel}},
Title = {Sulpici Severi libri qui supersunt},
Year = {1866}}

\end{filecontents}

\documentclass[11pt, openany]{book}
\usepackage{polyglossia}
\setmainlanguage[babelshorthands=true]{italian}
\setotherlanguages{latin, english, french}

\usepackage[]{csquotes} %autostyle,italian=guillemets
\usepackage{xpatch}
language=auto,
ibidpage=true,
babel=other,                        % Ed / hrsg / Éd
useprefix=true,
giveninits=true,
indexing=cite,                 %
citepages=permit,                   %
backend=biber,
]{biblatex}

\DeclareFieldFormat[article, inbook, incollection, inproceedings]{title}{\mkbibemph{#1}}
\DeclareFieldFormat{journaltitle}{\textquotedblleft #1\textquotedblright}                   % Journaltitle in double inverted commas
\DeclareFieldFormat[book, inbook, incollection, inproceedings]{volume}{#1}              % kills "vol."

\renewbibmacro*{byeditor+others}{%  Ed/Edd after Editor name
\ifnameundef{editor}
{}
{\printnames[byeditor]{editor}%
\clearname{editor}%
\newunit}%
\usebibmacro{byeditorx}%
\usebibmacro{bytranslator+others}}

\xpatchbibdriver{incollection}{%           Editore before title in incollection
\usebibmacro{maintitle+booktitle}%
\newunit\newblock
\usebibmacro{byeditor+others}%
}%
{%
\usebibmacro{byeditor+others}%
\usebibmacro{maintitle+booktitle}%
}%
{}{}%

\makeatletter                           % All this shit just to kill a comma between Editor and (Ed.)
\renewbibmacro*{bbx:editor}[1]{%
\ifboolexpr{
test \ifuseeditor
and
not test {\ifnameundef{editor}}
}
{\usebibmacro{bbx:dashcheck}
{\bibnamedash}
{\printnames{editor}%
\usebibmacro{bbx:savehash}}%
%     \usebibmacro{#1}% DELETED
\clearname{editor}}
{\global\undef\bbx@lasthash}}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\xpatchbibmacro{name:andothers}{%                                              % et al. emphatic (xpatch needed)
\bibstring{andothers}%
}{%
\bibstring[\emph]{andothers}%
}{}{}
\renewbibmacro{in:}{\bibstring{in}\space}                                           % no colon after IN

\NewBibliographyString{ibidemloccit,ibidemnoloccit}     % Customising Idem e Ibidem e Ivi
\DefineBibliographyStrings{italian}{%
idem           = {\textsc{id}},
idemsm = {\textsc{id}},
idemsf= {\textsc{id}},
idemsn = {\textsc{id}},
idempm = {\textsc{id}},
idempf = {\textsc{id}},
idempn = {\textsc{id}},
idempp = {\textsc{id}},
ibidemnoloccit = {Ivi},
}

\xpatchbibmacro{author}
{\printnames{author}}
{\iffootnote
{\ifthenelse{\ifciteidem\AND\NOT\boolean{cbx:noidem}}
{\usebibmacro{cite:idem}}
{\printnames{author}}}
{\printnames{author}}}
{}{}
\xpatchbibmacro{bbx:editor}
{\printnames{editor}}
{\iffootnote
{\ifthenelse{\ifciteidem\AND\NOT\boolean{cbx:noidem}}
{\usebibmacro{cite:idem}}
{\printnames{editor}}}
{\printnames{editor}}}
{}{}
\xpatchbibmacro{bbx:translator}
{\printnames{translator}}
{\iffootnote
{\ifthenelse{\ifciteidem\AND\NOT\boolean{cbx:noidem}}
{\usebibmacro{cite:idem}}
{\printnames{translator}}}
{\printnames{translator}}}
{}{}

\renewbibmacro*{cite:ibid}{%
\printtext{%
\ifloccit
{\bibstring[\mkibid]{ibidemloccit}%
\global\toggletrue{cbx:loccit}}
{\bibstring[\mkibid]{ibidemnoloccit}}}}}

\DefineBibliographyExtras{italian}{%            %% I always want the short dash
\protected\def\bibrangedash{%
-\penalty\hyphenpenalty}}

\DeclareFieldFormat[article, inbook, incollection, inproceedings]{citetitle}{\mkbibemph{#1}}        % Title emphatic in shorthands

\renewbibmacro*{cite:title}{%                 "cit" in tondo
\printfield[citetitle]{labeltitle}%
\bibstring{opcit}}}

\DefineBibliographyStrings{italian}{opcit = {cit\adddot\nopunct}}        % no comma after cit. If it doesn't work see:
% https://tex.stackexchange.com/questions/417733/custom-short-citations-biblatex-verbose/418206#418206

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\renewbibmacro*{publisher+location+date}{%             First publisher, then location
\printlist{publisher}%
\iflistundef{location}
\printlist{location}%
\setunit*{\space}%
\usebibmacro{date}%
\newunit}

\renewbibmacro*{series+number}{%
\iffieldundef{series}{}{%
\printfield{number}}}%
\newunit}

\DeclareBibliographyDriver{book}{%                  %  pub+loc+year before ser+num
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{maintitle+title}%
\newunit
\iffieldundef{maintitle}
{\printfield{volume}%
\printfield{part}}
{}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\printfield{edition}%
\newunit
\printfield{volumes}%
\newunit\newblock
\printfield{note}%
\newunit\newblock
\usebibmacro{publisher+location+date}%
\newunit\newblock
\usebibmacro{chapter+pages}%
\newunit
\printfield{pagetotal}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{isbn}}
{}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\newunit\newblock
\usebibmacro{pageref}%
\newblock\nopunct%
\usebibmacro{series+number}\addcomma%       Comma added by me. It works, but is this the right place?
\newunit\newblock
\usebibmacro{finentry}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\textit{Incollection:}\\
\cite[80]{Rae:Rap}\\

\textit{Book without author but with series}\\
\cite[55-56]{Hal:Sul}\\

\textit{Book}\\
\cite[55-56]{Lan:Rom}\\

\textit{Article with specific pagerange cited}\\
\cite[19-20]{Dan:Ind}\\

First cite\footcite[1]{Rae:Rap}, Same work, same page->ibidem\footcite[1]{Rae:Rap}, Same work, different page->ivi\footcite[3]{Rae:Rap} and same author, different work->idem\footcite[4]{Rae:His}

\end{document}

• Just so I understand you correctly: In point (2) you are saying that currently you see a colon (so do I) and that you want a comma instead? – moewe Mar 10 '18 at 11:07
• Yes, as it was after your work here: tex.stackexchange.com/questions/418701/… – Teodoro Mar 10 '18 at 11:22
• Can you explain in more details what your modifications of the book driver were supposed to achieve? They seem to be problematic and I would like to re-write them, but I would need to know what the expected outcome should be. – moewe Mar 10 '18 at 12:31
• Yes, I messed it to achieve the sorting order you see: Auhor, title, Publisher, Location year (series), postnotes. So basically to have pub+loc+year before ser+num, plus some minor issues like the comma after the series (even though I think that's not the right place to put it). However, in the example everything is fine except the two things I mentioned. – Teodoro Mar 10 '18 at 12:48
• The thing is: If I change something, there are cases where the output would differ and I'm not sure if those cases matter. You have, for example, placed the series+number after the related function at the moment. I would move it before the related loop, but of course then the output will be different if related is used. So I can compare with the MWE but that does not contain all possible cases ... – moewe Mar 10 '18 at 12:51

You can get the different separator for pages in the postnote by abusing the citepages=separate option.

We do not redefine \postnotedelim to be a colon and we do not meddle with the postnote and multipostnote formats, instead we only need

\renewbibmacro*{cite:postnote:pages}{%
\printfield{postnote}}


I modified a few other things as well, so please check the code and the output carefully. (Warning! The MWE uses filecontents and will overwrite a .bib file with the same base name as the .tex file if compiled. Test this in a separate directory to make sure this does not damage your production environment.) I have removed your comments and added comments myself to explain little code changes.

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@incollection{Rae:Rap,
Author = {Gilbert Raes},
Booktitle = {La S. Sindone. Ricerche e studi della commissione di esperti nominata dall'Arcivescovo di Torino},
Editor = {P. Caramello},
Pages = {79-83},
Series = {Supplemento Rivista diocesana torinese},
Title = {Rapport d'analyse},
date = {1976-01}}% gennaio 1976 is not a valid year value. Use this (and dateabbrev=false) instead

@incollection{Rae:His,
Author = {Gilbert Raes},
Booktitle = {Prélèvement sur le linceul effectué le 21 avril 1988 et études du tissu},
Pages = {71-74},
Publisher = {\textsc{o.e.i.l.}},
Title = {Historique de l'échantillon remis le 24 novembre 1973. Problème de la bande latérale. Fibres de coton dans l'échantillon remis au laboratoire d'Oxford},
Year = {1990}}

@article{Dan:Ind,
Author = {Avinoam Danin},
Journal = {Il Telo},
Pages = {12-21},
Title = {Indicazioni floreali per l'origine geografica della Sindone di Torino},
Volume = {II},
Year = {2001}}

@book{Lan:Rom,
Author = {Bertrand Lancon AND Antonia Nevill},
Publisher = {Edinburgh University Press},
Title = {Rome in Late Antiquity: Everyday Life and Urban Change, \textsc{ad} 312-609},
Year = {2000}}

@book{Hal:Sul,
Editor = {C. Halm},
Langid = {german},
Number = {1},
Publisher = {C. Geroldi filium bibliopolam academiae},
Series = {\textsc{csel}},
Title = {Sulpici Severi libri qui supersunt},
Year = {1866}}
\end{filecontents}

\documentclass[11pt, openany]{book}
\usepackage{polyglossia}
\setmainlanguage[babelshorthands=true]{italian}
\setotherlanguages{latin, english, french}

\usepackage[]{csquotes}
\usepackage{xpatch}
language=auto,
ibidpage=true,
autolang=other,% use new option name
useprefix=true,
giveninits=true,
indexing=cite,%
citepages=separate,%
dateabbrev=false,
backend=biber,
]{biblatex}

\DeclareFieldFormat[article, inbook, incollection, inproceedings]{title}{\mkbibemph{#1}}
\DeclareFieldFormat{journaltitle}{\textquotedblleft #1\textquotedblright}
\DeclareFieldFormat[book, inbook, incollection, inproceedings]{volume}{#1}

% the colon/comma issues for pages together with citepages=separate
\renewbibmacro*{cite:postnote:pages}{%
\printfield{postnote}}

\renewbibmacro*{byeditor+others}{%
\ifnameundef{editor}
{}
{\printnames[byeditor]{editor}%
\clearname{editor}%
\newunit}%
\usebibmacro{byeditorx}%
\usebibmacro{bytranslator+others}}

\xpatchbibdriver{incollection}{%
\usebibmacro{maintitle+booktitle}%
\newunit\newblock
\usebibmacro{byeditor+others}%
}%
{%
\usebibmacro{byeditor+others}%
\usebibmacro{maintitle+booktitle}%
}%
{}{}%

% NEW
% All this shit just to kill a comma between Editor and (Ed.)
% nope, it's easier
% I assume you also have ?
\DeclareFieldFormat{editortype}{\mkbibparens{#1}}
% same for translator
\DeclareFieldFormat{translatortype}{\mkbibparens{#1}}

\xpatchbibmacro{name:andothers}{%
\bibstring{andothers}%
}{%
\bibstring[\emph]{andothers}%
}{}{}

% NEW
\DeclareDelimAlias{finalnamedelim}{multinamedelim}% comma instead of AND between multiple authors

\renewbibmacro{in:}{\bibstring{in}\space}

\NewBibliographyString{ibidemloccit,ibidemnoloccit}
\DefineBibliographyStrings{italian}{%
idem   = {\textsc{id}},
idemsm = {\textsc{id}},
idemsf = {\textsc{id}},
idemsn = {\textsc{id}},
idempm = {\textsc{id}},
idempf = {\textsc{id}},
idempn = {\textsc{id}},
idempp = {\textsc{id}},
ibidemnoloccit = {Ivi},
}

\xpatchbibmacro{author}
{\printnames{author}}
{\iffootnote
{\ifthenelse{\ifciteidem\AND\NOT\boolean{cbx:noidem}}
{\usebibmacro{cite:idem}}
{\printnames{author}}}
{\printnames{author}}}
{}{}
\xpatchbibmacro{bbx:editor}
{\printnames{editor}}
{\iffootnote
{\ifthenelse{\ifciteidem\AND\NOT\boolean{cbx:noidem}}
{\usebibmacro{cite:idem}}
{\printnames{editor}}}
{\printnames{editor}}}
{}{}
\xpatchbibmacro{bbx:translator}
{\printnames{translator}}
{\iffootnote
{\ifthenelse{\ifciteidem\AND\NOT\boolean{cbx:noidem}}
{\usebibmacro{cite:idem}}
{\printnames{translator}}}
{\printnames{translator}}}
{}{}

\renewbibmacro*{cite:ibid}{%
\printtext{%
\ifloccit
{\bibstring[\mkibid]{ibidemloccit}%
\global\toggletrue{cbx:loccit}}
{\bibstring[\mkibid]{ibidemnoloccit}}}}}

\DefineBibliographyExtras{italian}{%
\protected\def\bibrangedash{%
-\penalty\hyphenpenalty}}

\DeclareFieldFormat[article, inbook, incollection, inproceedings]{citetitle}{\mkbibemph{#1}}

% I don't think you needed the redefinition of cite:title.

% slightly simplified
\renewbibmacro*{publisher+location+date}{%
\printlist{publisher}%
\printlist{location}%
\setunit*{\space}%
\usebibmacro{date}%
\newunit}

\renewbibmacro*{series+number}{%
\iffieldundef{series}
{}
\printtext[parens]{%
\printfield{series}%
\printfield{number}}}%
\newunit}

% modified
\DeclareBibliographyDriver{book}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{maintitle+title}%
\newunit
\iffieldundef{maintitle}
{\printfield{volume}%
\printfield{part}}
{}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\printfield{edition}%
\newunit
\printfield{volumes}%
\newunit\newblock
\printfield{note}%
\newunit\newblock
\usebibmacro{publisher+location+date}%
\newunit\newblock
\usebibmacro{series+number}%
\newunit\newblock
\usebibmacro{chapter+pages}%
\newunit
\printfield{pagetotal}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{isbn}}
{}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit\newblock
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}}

\begin{document}

\textit{Incollection:}\\
\cite[80]{Rae:Rap}\\

\textit{Book without author but with series}\\
\cite[55-56]{Hal:Sul}\\

\textit{Book}\\
\cite[55-56]{Lan:Rom}\\

\textit{Article with specific pagerange cited}\\
\cite[19-20]{Dan:Ind}\\

First cite\footcite[1]{Rae:Rap}, Same work, same page->ibidem\footcite[1]{Rae:Rap}, Same work, different page->ivi\footcite[3]{Rae:Rap} and same author, different work->idem\footcite[4]{Rae:His}

\footcite{westfahl:frontier}

\footcite{westfahl:space}

\footcite[1]{Rae:Rap}
\end{document}


If you need to set the "idem" thing for several languages at once,

\newcommand*{\mklangidem}[1]{%
\DefineBibliographyStrings{#1}{%
idem   = {\textsc{id}},
idemsm = {\textsc{id}},
idemsf = {\textsc{id}},
idemsn = {\textsc{id}},
idempm = {\textsc{id}},
idempf = {\textsc{id}},
idempn = {\textsc{id}},
idempp = {\textsc{id}},
ibidemnoloccit = {Ivi},

• @Teodoro If you don't want to update, you can use \renewcommand{\finalnamedelim}{\multinamedelim} instead. But my shorter solution to "All this shit just to kill a comma between Editor and (Ed.)" will not work with your old version, either. So you will have to revert to your longer solution. – moewe Mar 10 '18 at 16:17
• @Teodoro You have language=auto, and autolang=other, that means that your entries switch language according to their langid field. None of your entries have a langid field and so they fall back to the main language (Italian), but the entries from biblatex-examples.bib have a langid and so the citation in footnote 6 goes with the English localisation. We only changed the Italian translation of idem to "ID", the English remains "idem". You otherwise hardly notice the switch since "ed", "pp." and "in" seem to be the same for Italian and English. – moewe Mar 11 '18 at 16:15
• ... So this should not be a problem for you actual document if you never have a langid field. You could also work around this by choosing different values for the language and autolang options. – moewe Mar 11 '18 at 16:16
• @Teodoro OK. The best course of action depends on what you want. If you want your references to switch languages, but you want the "ID" to stay the same, you'll need the \DefineBibliographyStrings{italian} block above for all languages you use. I have a added a hack to my answer that lets you do that for many languages at once. If you don't want your entries to switch language you probably only want autolang=hyphen or even autolang=none. – moewe Mar 11 '18 at 16:43