# Customise biblatex entry type or amend existing one?

I was wondering whether it's possible to add a biblatex entry type (as I do not wish to use a different biblatex style) to something like "law".

When it comes to law, unfortunately my university's ruleset is not too strict (so I don't know if and where to add fields like "publisher", "location" and such - if you have a neat idea, let me know!) - however there are some requirements when it comes to law texts:

I have tried to stick to this: example, however, it doesn't work (I tried the exact sample, which worked, however, when I changed configurations in terms of class, bibliography and tried to compile, it already broke. I am also completely lost, why that happens and just tried to still adapt things to my necessities, which obviously didn't work either)

That's my current non-working MWE, which does not even contain any bib formatting, since I already failed many steps earlier.

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@legislation{help,
legaltitle = {Kaisei minp\={o} j\={o}bun},
law = {Saik\={o}-saiban-sho},
date = {1947},
location = {T\={o}ky\={o}},
maintitle = {testmaintitle},
legaltitleaddon = {{\"U}berarbeiteter Gesetzestext des Zivilgesetzbuchs},
doi = {10.11501/1275567},
urldate = {2019-08-01},
legalbook = {5},
legalchapter = {3},
legalarticle = {2}
}
\end{filecontents*}
\begin{filecontents}{legislation.dbx}
\DeclareDatamodelEntrytypes{legislation}
\DeclareDatamodelFields[type=field,datatype=literal]{
court,
legalcode,
law,
legaltitle,
}
\DeclareDatamodelFields[type=field, datatype=verbatim]{
legalbookno,
legalchapterno,
legalarticleno
}
\DeclareDatamodelEntryfields[legislation]{
court,
legalcode,
legaltitle,
law,
date,
urldate,
legalbookno,
legalchapterno,
legalarticleno,
maintitle,
url,
doi,
location
}
\end{filecontents}
\documentclass[a4paper]{scrartcl}
\usepackage[main=ngerman, english]{babel}
\usepackage[babel, german=quotes]{csquotes}
\usepackage[ngerman]{isodate}
\usepackage[ngerman]{datetime}
\usepackage[datamodel=legislation,backend=biber]{biblatex}
\usepackage{hyperref}

\DeclareLanguageMapping{ngerman}{legislation}

\DeclareFieldFormat[legislation]{legaltitle}{#1\isdot}

\newbibmacro*{bookchaparticle}{%
\bibstring{legalbook}%
\printfield{legalbookno}
\bibstring{legalchapter}%
\printfield{legalchapterno}
\bibstring{legalarticle}%
\printfield{legalarticleno}

\DeclareBibliographyDriver{legislation}{%
\usebibmacro{bibindex}%
\usebibmacro{bookchaparticle}%
\newunit\newblock
\usebibmacro{finentry}}

\begin{document}
\nocite{*}
\cite{help}

\printbibliography
\end{document}


Thank you!

output before (currently no output due to errors in my code): required output:

That's what I tried to use as the closest example to this one, however this also doesn't work.

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@stackexchange{se:l3help,
sitetopic = {tex},
title   = {What can \textit{I} do to help the \LaTeX3 Project},
ansp    = {Frank Mittelbach},
anspid  = {10109},
ansdate = {2012-03-01},
ansid   = {46427},
}
\end{filecontents*}
\begin{filecontents}{stackexchange.dbx}
\DeclareDatamodelEntrytypes{stackexchange}
\DeclareDatamodelFields[type=field,datatype=literal]{
sitekey,
sitetopic,
}
\DeclareDatamodelFields[type=list,datatype=name]{
ansp,
}
\DeclareDatamodelFields[type=field, datatype=date, skipout]{
ansdate,
anseditdate}
\DeclareDatamodelFields[type=field, datatype=verbatim]{
anspid,
ansid,
}
\DeclareDatamodelEntryfields[stackexchange]{
sitekey,
sitetopic,
ansp,
anspid,
ansid,
ansyear,
ansmonth,
ansday,
ansedityear,
anseditmonth,
anseditday,
title}
\end{filecontents}
\documentclass[
12pt,
a4paper,
listof=totoc,
numbers=noenddot
]{scrartcl}

\usepackage{showframe}
\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.00cm, footskip=1cm]{geometry}
\usepackage[onehalfspacing]{setspace}
\usepackage[main=ngerman, english]{babel}
\usepackage[babel, german=quotes]{csquotes}
\usepackage[ngerman]{isodate}
\usepackage[ngerman]{datetime}
\usepackage[
backend=biber,
style=ext-authoryear,
sorting=nyvt,
maxnames=25,
innamebeforetitle=true,
usetranslator=true,
alldates=terse,
labeldate=year,
dashed=false,
isbn=false
]{biblatex}
\usepackage{hyperref}

\begin{filecontents*}{english-stack.lbx}
\ProvidesFile{english-stack.lbx}[2014/05/07 english with additions for stackexchange]
\InheritBibliographyExtras{english}
\DeclareBibliographyStrings{%
inherit   = {english},
edited    = {{edited}{edited}},
}
\end{filecontents*}
\DeclareLanguageMapping{ngerman}{ngerman}

\DeclareFieldFormat[stackexchange]{title}{\mkbibquote{#1\isdot}}
\mkbibparens{\ifhyperref

\DeclareFieldFormat{anspid}{%
\mkbibparens{\ifhyperref

\mkbibparens{\ifhyperref

\DeclareFieldFormat{ansid}{%
\mkbibparens{\ifhyperref

\newbibmacro*{stackexchangequestion}{%
\printfield{title}%
}

{}
{\printtext[parens]{%
\bibstring{edited}%
\bibstring{byauthor}%
}

\newbibmacro*{stackexchangeans}{%
\printansdate%
\iffieldundef{ansedityear}
{}
{\printtext[parens]{%
\bibstring{edited}%
\printanseditdate}}%
\bibstring{byauthor}%
\printnames{ansp}%
\printfield{anspid}%
}

\newbibmacro*{stackexchangesite}{%
\printfield{sitetopic}}

\DeclareBibliographyDriver{stackexchange}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{stackexchangequestion}%
\newunit\newblock
\newunit\newblock
\usebibmacro{stackexchangeans}%
\newunit\newblock
\usebibmacro{stackexchangesite}%
\newunit\newblock
\usebibmacro{finentry}}

\begin{document}
\nocite{*}
\cite{se:l3help}

\printbibliography
\end{document}

• – Alan Munn Jul 23 '19 at 20:07
• The existing types @jurisdiction, @legislation and @legal might be appropriate (check the biblatex docs for their intended meaning), but the standard styles all treat them as @misc. So the types are there, but work is probably needed to get them to look like you want. – moewe Jul 23 '19 at 20:29
• Hey @moewe, sorry for all the questions! I have tried to use your MWE (tex.stackexchange.com/questions/175776/…) and change it according to the wording I will use - however it doesn't recognise my bibstrings and I have tried to figure out how to fix that for hours now - I have not even started to try to style them according to my uni's ruleset, as I thought, I'd just like it to basically work first - however I even failed to do that - however, I have updated my MWE (which doesn't work) – user168390 Jul 24 '19 at 9:04

There is one syntax error in the MWE that makes things break down badly quite quickly. The block

\newbibmacro*{bookchaparticle}{%
\bibstring{legalbook}%
\printfield{legalbookno}
\bibstring{legalchapter}%
\printfield{legalchapterno}
\bibstring{legalarticle}%
\printfield{legalarticleno}


is missing a closing curly brace. Just add the missing } at the end. That's pretty much it for the error!

If the } is added, the example will compile, but the output won't quite be as expected. That is due to two reasons.

1. The MWE uses bibliography strings, but doesn't declare or translate them (you did so in an earlier iteration of your question and I just copied the relevant .lbx file from there).

2. There seems to be a slight mixup with the field names: Sometimes it says legalbookno (in the .dbx and the driver), sometimes legalbook (in the .bib file). Similarly for legalarticle(no) and legalchapter(no). I saw little point in adding the no and normalised all names to legalbook, legalchapter, legalarticle.

Finally one small aesthetic detail: I prefer to use \bibstring in field formats instead of the bibmacros directly, so that is what I did here.

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@legislation{help,
legaltitle      = {Kaisei minpō jōbun},
law             = {Saikō-saiban-sho},
date            = {1947},
location        = {Tōkyō},
maintitle       = {testmaintitle},
legaltitleaddon = {Überarbeiteter Gesetzestext des Zivilgesetzbuchs},
doi             = {10.11501/1275567},
urldate         = {2019-08-01},
legalbook       = {5},
legalchapter    = {3},
legalarticle    = {2},
}
\end{filecontents*}
\begin{filecontents}{legislation.dbx}
\DeclareDatamodelEntrytypes{legislation}
\DeclareDatamodelFields[type=field,datatype=literal]{
court,
legalcode,
law,
legaltitle,
legalbook,
legalchapter,
legalarticle,
}
\DeclareDatamodelEntryfields[legislation]{
court,
legalcode,
legaltitle,
law,
date,
urldate,
legalbook,
legalchapter,
legalarticle,
maintitle,
url,
doi,
location,
}
\end{filecontents}
\begin{filecontents*}{legislation-ngerman.lbx}
\ProvidesFile{legislation-ngerman.lbx}[2019 Legislation according to IOA]
\InheritBibliographyExtras{ngerman}

\DeclareBibliographyStrings{%
inherit       = {ngerman},
legalbook     = {{legalbook}{legalbook}},
legalchapter  = {{legalchapter}{legalchapter}},
legalarticle  = {{legalarticle}{legalarticle}},
}
\end{filecontents*}
\documentclass[a4paper]{scrartcl}
\usepackage[main=ngerman, english]{babel}
\usepackage[babel, german=quotes]{csquotes}
\usepackage[ngerman]{isodate}
\usepackage[ngerman]{datetime}
\usepackage[datamodel=legislation,backend=biber]{biblatex}
\usepackage{hyperref}

\NewBibliographyString{legalbook,legalchapter,legalarticle}
\DeclareLanguageMapping{ngerman}{legislation-ngerman}

\DeclareFieldFormat[legislation]{legaltitle}{#1\isdot}

\DeclareFieldFormat{legalbook}{\bibstring{legalbook}~#1}
\DeclareFieldFormat{legalchapter}{\bibstring{legalchapter}~#1}
\DeclareFieldFormat{legalarticle}{\bibstring{legalarticle}~#1}

\newbibmacro*{bookchaparticle}{%
\printfield{legalbook}%
\printfield{legalchapter}%
\printfield{legalarticle}}

\DeclareBibliographyDriver{legislation}{%
\usebibmacro{bibindex}%
\usebibmacro{bookchaparticle}%
\newunit\newblock
\usebibmacro{finentry}}

\begin{document}
\nocite{*}
\cite{help}

\printbibliography
\end{document}


biblatex only allows you to load a single .dbx file, which is no real obstacle for your use case, since you are the one writing all of the .dbx files anyway, and so it is no big deal to merge them. But there are workarounds to load several if need be: Datamodel distribution with biblatex, https://ctan.org/pkg/biblatex-multiple-dm.

I'd keep the field names as short as possible and would try to re-use as existing fields. So I would probably rename legalbook to book etc. I didn't see the need to declare legalarticle and friends as verbatim (where similar to \begin{verbatim}...\end{verbatim} special characters don't have their special meaning; this is useful for URL-like fields), so I turned them into a "normal" literal. I also don't quite get the meaning of law and legaltitle vs. title, maintitle etc.

• thank you very much! I have spent the whole day trying to figure things out - thanks for all the help! I managed to get a MWE, however there are some small things, that still need to be changed and I don't know how - would it be okay to add them to this ticket or create a new one? – user168390 Jul 24 '19 at 17:46
• @user168390 In general I think it is frowned upon to completely rewrite the question after you have gotten an answer, especially if it completely invalidates the answer. It would be nicer to ask a new question. I won't have time to look at this tonight anyway, but I will have a look tomorrow (preferably in a new question, with this one rolled back to its state when I answered it; but if you absolutely don't want to do that I'll try to see what to do with this answer here). – moewe Jul 24 '19 at 20:26