Formatting issue with DeclareBibliographyDriver in my Custom Biblatex Style based

Following my initial problems about the creation of a new style as well as my first try which ended in an error with the cite, I've created a new BBX/CBX combo.

So I'm progressing, I chose option 2 from my last post, I took the authortitle-terse as a base and copy-pasted it in my own style, then made some small changes. The code is below.

In short, neither my "book" nor my "thesis" driver definition are working. Here are my issues:

1) Book

1. Delimiter are completely off
2. The case for multiple authors is not consistent, it seems the driver do not recognize family and given name
3. There is an extra "," between family and first name
4. Moreover, I could not code this requirement : if the label field is set, there should be an extra text after the bibliography which says (cité : all author family names in small caps separated by "/"-field

Example for the first cite : Druey Jean-Nicolas, Titre au hasard ,2e éd., Berne 2016 (cité : Druey-Titre)

2) Thesis

1. There are " between the title
2. The title is not in italic
3. There is an extra "," between first and family name
4. The separation for block and unit seems way off from my need...

3) Language not detected

I had to force the recnognition of the language. It was not automatically taken. This caused some real pain, as I only noticed that the issue after adding the "edition" field, noticing that it was in English.

MWE Code

Main.tex

% MweBiblatex Swiss Legal
\documentclass{article}

% Needed by Biblatex
\usepackage{polyglossia}
\setmainlanguage{french}

\usepackage{csquotes}
\usepackage[style=biblatex-xawi, language=french, backend=biber, bibencoding=UTF8]{biblatex}
% \usepackage[style=authortitle-terse, backend=biber, bibencoding=UTF8]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{DrueyComte,
author      = {Druey, Jean-Nicolas and Comte, Alfred Leopold},
title       = {Grundriss des Erbrechts},
edition     = 6,
date        = {2016},
location    = {Berne},
}
@book{Druey,
author      = {Druey, Jean-Nicolas},
title       = {Titre au hasard},
date        = {2016},
edition     = 2,
location    = {Berne},
label       = {Druey-Test},
}
@thesis{gut,
author      = {Gut, Nicolas},
title       = {Die unbezifferte Forderungsklage nach der Schweizerischen Zivilprozessordnung},
date        = {2014},
location    = {Bâle},
label       = {thèse},
}
\end{filecontents}

\begin{document}
\section{expectation}
My goal as a real citation in the reference table as :\\
\textsc{Druey} Jean-Nicolas/\textsc{Comte} Alfred Leopold, \textit{Grundriss des Erbrechts, 6e ed}, Berne 2016\\
Output of the cite command should be like "\textsc{Druey/Comte}".

\section{test}
En matière de successions, le CC offre aux héritiers plusieurs façons de procéder (test 1) \cite{DrueyComte}, (test 2) \cite{Druey}.

Finalement, on cite la thèse de N. Gut ici : \cite{gut}.
\printbibliography

\end{document}


biblatex-xawi.bbx

% Encoding of this file: UTF-8. Code is ASCII compatible.
\ProvidesFile{biblatex-xawi.bbx}[2018/04/13 v1.1 alpha)]
\RequireBiber[2]
\RequireBibliographyStyle{authortitle}

% Formatage de la table
\setlength{\bibhang}{0pt}
\setlength{\bibitemsep}{1.5\baselineskip}

% NOUVELLES COMMANDES DE BIBLIOGRAPHIE %
% \newcommand{\printpaperbibliography}{\printbibliography[nottype=online, title=Bibliographie]}
% \newcommand{\printonlinebibliography}{\printbibliography[type=online, title=Sources en ligne]}

% Format des séparateurs entre les noms: des slash
\renewcommand*{\multinamedelim}{\ifcitation{\slash}{\addnbspace\slash\addspace}}% Dans les citations, pas d'espaces entre les slash (contrairement à la bibliographie)
\renewcommand*{\finalnamedelim}{\multinamedelim}%
\renewcommand*{\newblockpunct}{,}
% \renewcommand*{\newunitpunct}{}

% NOUVELLES COMMANDES DE BIBLIOGRAPHIE %

\DeclareBibliographyDriver{book}{%
\printnames{author}%
\newunit\newblock
\printfield{title}%
\newunit\newblock%
\printfield{edition}%
\newunit\newblock
\printlist{location}%
\printfield{year}%
\finentry}
\endinput

\DeclareBibliographyDriver{thesis}{%
\printnames{author}%
\newunit\newblock%
\printfield{title}%
\newunit\newblock%
\printfield{label}%
\newunit\newblock%
\printlist{location}%
\printfield{year}%
\finentry}
\endinput


biblatex-xawi.cbx (copy-past of authortitle-terse)

% Encoding of this file: UTF8. Code is ASCII compatible.

% PREAMBULE / REGLES GENERALES
\ProvidesFile{biblatex-xawi.cbx}[2018/04/13 v1.0 alpha]

\RequireCitationStyle{authortitle}
\ExecuteBibliographyOptions{singletitle,uniquename,uniquelist,autocite=inline}

\renewbibmacro*{cite}{%
\iffieldundef{shorthand}
{\ifnameundef{labelname}
{\usebibmacro{cite:title}}
{\ifsingletitle
{\printtext[bibhyperref]{\printnames{labelname}}}
{\printnames{labelname}%
\setunit{\nametitledelim}%
\usebibmacro{cite:title}}}}%
{\usebibmacro{cite:shorthand}}}

\renewbibmacro*{textcite}{%
\ifnameundef{labelname}
{\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\iffieldundef{shorthand}
{\usebibmacro{cite:title}}%
{\usebibmacro{cite:shorthand}}}
{\ifthenelse{\ifsingletitle\AND
$$\iffieldundef{prenote}\OR\value{citecount}>1$$}
{\printtext[bibhyperref]{\printnames{labelname}}}
{\printnames{labelname}%
\setunit{%
\global\booltrue{cbx:parens}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\iffieldundef{shorthand}
{\usebibmacro{cite:title}}%
{\usebibmacro{cite:shorthand}}}}}

\endinput

• I have edited your .bib file a bit. The outer {....} were unnecessary and would cause a warning. – moewe Apr 18 '18 at 14:49

@book

1. In general you don't want to change \newblockpunct you need to change \newunitpunct
2. The parser recognises the names correctly, you want

\DeclareNameAlias{sortname}{family-given}

3. You need

\renewcommand*{\revsdnamepunct}{}

4. See below

@thesis

Your main problem was that you had an \endinput after the driver for @book. That line caused biblatex to ignore everything after it, so the @thesis driver was never read.

With

\DeclareFieldFormat*{title}{\mkbibemph{#1}}
\DeclareFieldFormat*{citetitle}{\mkbibemph{#1}}


you get all titles in italics without quotation marks.

Language not detected

Your MWE detected the French language just fine for me without language=french. If you use really ancient versions of biblatex or polyglossia that could be problematic, but with a fairly modern version, you should be fine.

The citation style

The label field is only added if there are two works by the same authors. And only then you get to see 'cité' in the bibliography.

The styles are already equipped to do that for us, we only need

\DeclareLabeltitle{%
\field{label}
\field{shorttitle}
\field{title}
\field{maintitle}
}


and two macros to print the 'cité' information in the bibliography

Test document

\listfiles
\documentclass{article}

% Needed by Biblatex
\usepackage{polyglossia}
\setmainlanguage{french}

\usepackage{csquotes}
\usepackage[style=biblatex-xawi, backend=biber, bibencoding=UTF8]{biblatex}
% \usepackage[style=authortitle-terse, backend=biber, bibencoding=UTF8]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{DrueyComte,
author      = {Druey, Jean-Nicolas and Comte, Alfred Leopold},
title       = {Grundriss des Erbrechts},
edition     = 6,
date        = {2016},
location    = {Berne},
}
@book{Druey,
author      = {Druey, Jean-Nicolas},
title       = {Titre au hasard},
date        = {2016},
edition     = 2,
location    = {Berne},
label       = {Druey-Test},
}
@thesis{gut,
author      = {Gut, Nicolas},
title       = {Die unbezifferte Forderungsklage nach der Schweizerischen Zivilprozessordnung},
date        = {2014},
location    = {Bâle},
label       = {thèse},
}
@book{gut2,
author      = {Gut, Nicolas},
title       = {Ein Buch},
date        = {2015},
location    = {Berne},
label       = {Buch},
}
\end{filecontents}

\begin{document}
\section{expectation}
My goal as a real citation in the reference table as :\\
\textsc{Druey} Jean-Nicolas/\textsc{Comte} Alfred Leopold, \textit{Grundriss des Erbrechts, 6e ed}, Berne 2016\\
Output of the cite command should be like "\textsc{Druey/Comte}".

\section{test}
En matière de successions, le CC offre aux héritiers plusieurs façons de procéder (test 1) \cite{DrueyComte}, (test 2) \cite{Druey}.

Finalement, on cite la thèse de N. Gut ici : \cite{gut}.

\cite{gut2}

\printbibliography

\end{document}


.bbx

\ProvidesFile{biblatex-xawi.bbx}[2018/04/18 v1.1 alpha]
\RequireBiber[2]
\RequireBibliographyStyle{authortitle}
\ExecuteBibliographyOptions{dashed=false}

% Formatage de la table
\setlength{\bibhang}{0pt}
\setlength{\bibitemsep}{1.5\baselineskip}

\DeclareDelimFormat{multinamedelim}{\slash}
\DeclareDelimAlias{finalnamedelim}{multinamedelim}%

\DeclareNameAlias{sortname}{family-given}
\renewcommand*{\revsdnamepunct}{}

\DeclareFieldFormat*{title}{\mkbibemph{#1}}
\DeclareFieldFormat*{citetitle}{\mkbibemph{#1}}

\DefineBibliographyStrings{french}{citedas = {cit\'e}}

\newbibmacro{citedas:cite}{%
\begingroup
\delimcontext{cite}%
\DeclareFieldFormat{bibhyperref}{##1}%
\csuse{blx@hook@cite}%
\csuse{blx@hook@citekey}%
\undef\cbx@lasthash
\undef\cbx@lastyear
\citetrackerfalse\pagetrackerfalse\backtrackerfalse
\defcounter{maxnames}{\blx@maxcitenames}%
\usebibmacro{cite}%
\endgroup
}

\newbibmacro{citedas}{%
\ifsingletitle
{}
{\printtext[parens]{%
\bibstring{citedas}%
\usebibmacro{citedas:cite}}}}

\renewbibmacro*{location+date}{%
\printlist{location}%
\usebibmacro{date}%
\newunit}

\DeclareBibliographyDriver{book}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author}%
\setunit{\printdelim{nametitledelim}}\newblock
\usebibmacro{maintitle+title}%
\newunit\newblock
\printfield{edition}%
\newunit\newblock
\usebibmacro{location+date}%
\usebibmacro{citedas}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}}

\DeclareBibliographyDriver{thesis}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author}%
\setunit{\printdelim{nametitledelim}}\newblock
\usebibmacro{title}%
\newunit\newblock
\printfield{label}%
\newunit\newblock
%  \setunit{\addspace}% <--- do you really want that?
\usebibmacro{location+date}%
\usebibmacro{citedas}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}}

\endinput % <- only at the very end!


.cbx

\ProvidesFile{biblatex-xawi.cbx}[2018/04/18 v1.1]

\RequireCitationStyle{authortitle}
\ExecuteBibliographyOptions{singletitle,uniquename,uniquelist,autocite=inline}

\DeclareDelimFormat{nametitledelim}{\textendash}

\DeclareLabeltitle{%
\field{label}
\field{shorttitle}
\field{title}
\field{maintitle}
}

\renewbibmacro*{cite}{%
\iffieldundef{shorthand}
{\ifnameundef{labelname}
{\usebibmacro{cite:title}}
{\ifsingletitle
{\printtext[bibhyperref]{\printnames{labelname}}}
{\printnames{labelname}%
\setunit{\printdelim{nametitledelim}}%
\usebibmacro{cite:title}}}}%
{\usebibmacro{cite:shorthand}}}

\renewbibmacro*{textcite}{%
\ifnameundef{labelname}
{\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\iffieldundef{shorthand}
{\usebibmacro{cite:title}}%
{\usebibmacro{cite:shorthand}}}
{\ifthenelse{\ifsingletitle\AND
$$\iffieldundef{prenote}\OR\value{citecount}>1$$}
{\printtext[bibhyperref]{\printnames{labelname}}}
{\printnames{labelname}%
\setunit{%
\global\booltrue{cbx:parens}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\iffieldundef{shorthand}
{\usebibmacro{cite:title}}%
{\usebibmacro{cite:shorthand}}}}}

\endinput


• Thanks Moewe, for the language, the option works fine. But I had not expected the option to be mandatory. I thought it would be automated through my use of Polygossia \setmainlanguage. But at the end, yes, it worked. And thanks again for the remark on endinput (stupid mistake), I'll edit and apply your change one by one. One quick remark on DeclareFieldFormat : is it possible to make it variable by type of bibliography ? For example, I got some other style were the title or author must be in regular (no small caps, no italics), but only is the type is "article", would that work too ? – XaWin Apr 19 '18 at 7:02
• @XaWi As I said, the language=french options should not be necessary and it was not necessary in my tests, I got a French bibliography nonetheless, because biblatex picked up the \setmainlanguage. You can use the optional argument of \DeclareFieldFormat to restrict it to certain entry types: \DeclareFieldFormat[article,incollection]{title}{\mkbibquote{#1}} wraps only the titles of @article and @incollection in quotation marks. – moewe Apr 19 '18 at 7:10
• Ok, no joy, I'm getting an error "! Undefined control sequence. \DeclareDelimFormat". From my search, these commands should be defined in biblatex.def. According to the listfiles, the biblatex at my work place is v2.7a. – XaWin Apr 19 '18 at 7:16
• @XaWi That version is seriously outdated. 2.7a is almost five years old now. The current version is 3.11 and the code above generally assumes at least version 3.8. With 2.7a chances are biblatex-swiss-legal still works without modifications. – moewe Apr 19 '18 at 7:19
• And that explains the differences I experienced when switching between work and personal laptop... Anyway, hence I'll test later on an update platform. And btw, the biblatex-swiss-legal do not work on my work environment neither. – XaWin Apr 19 '18 at 7:59