1

As per (this ticket) I tried to figure out how to create a new BibLaTeX entry type and have managed to get a a working MWE.

However, there are still some amendments I need to make and I don't know how and where to start.

This is my current MWE:

% arara: lualatex: { shell: true, synctex: true }
% arara: biber
% arara: lualatex: { shell: true, synctex: true }

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@law{se:l3help,
  lawtitle   = {Kaisei minp\={o} j\={o}bun},
  date = {2012-02-26},
  year   = {2012},
  lawtitleaddon    = {{\"U}berarbeiteter Gesetzestext des Zivilgesetzbuchs},
  lawsubtitle = {Tsuika},
  maintitle = {testmaintitle},
  maintitleaddon = {testmaintitleaddon},
  urldate = {2019-07-21},
  url = {http://dl.ndl.go.jp/info:ndljp/pid/1275567},
  organization = {Saik\={o}-saiban-sho},
  paragraph = {5},
  subparagraph = {3}, 
  number = {2}
}
\end{filecontents*}
% DBX ___________________________________________________________________________________
\begin{filecontents}{customstyles.dbx}
\DeclareDatamodelFields[type=field, datatype=literal]{
  journaltitleaddon}

\DeclareDatamodelEntryfields[article,periodical]{
  journaltitleaddon}

\DeclareDatamodelEntrytypes{law}
\DeclareDatamodelFields[type=field,datatype=literal]{
  lawsubtitle,  lawsubtitle,
  lawtitle,
  lawtitleaddon,
}
\DeclareDatamodelFields[type=field, datatype=verbatim]{
  paragraph,
  subparagraph,
  article,
}
\DeclareDatamodelEntryfields[law]{
  paragraph,
  subparagraph,
  article,
  lawsubtitle,
  lawtitle,
  lawtitleaddon,
}
\end{filecontents}
% DBX ___________________________________________________________________________________
\documentclass[
  12pt,
  a4paper,
  headings=standardclasses,
  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,
  datamodel=customstyles,
  maxnames=25,
  innamebeforetitle=true,
  usetranslator=true,
  alldates=terse,
  labeldate=year,
  dashed=false,
  isbn=false
]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}

% editor and et al. spelling
\DefineBibliographyStrings{german}{
  andothers = {et al\adddot},
  byeditor    = {Hg\adddotspace von},
  editor    = {Hg\adddot},
  editors   = {Hg\adddot},
  urlseen = {letzter Abruf},
}
% LBX ___________________________________________________________________________________
\begin{filecontents*}{custombibstrings.lbx}
  \ProvidesFile{custombibstrings.lbx}[2014/05/07 english with additions for law]
  \InheritBibliographyExtras{ngerman}
  \NewBibliographyString{paragraph,subparagraph,article}
  \DeclareBibliographyStrings{%
    inherit   = {ngerman},
    paragraph = {{Paragraph}{\S}},
    subparagraph = {{Absatz}{Abs.}},
    article = {{Artikel}{Art.}}
  }
\end{filecontents*}
% LBX ___________________________________________________________________________________
\DeclareLanguageMapping{ngerman}{custombibstrings}

\renewcommand*{\titleaddonpunct}{\addspace}
\DeclareFieldFormat{titleaddon}{\mkbibbrackets{#1}}
\DeclareFieldAlias{booktitleaddon}{titleaddon}
\DeclareFieldAlias{maintitleaddon}{titleaddon}
\DeclareFieldAlias{journaltitleaddon}{titleaddon}
\DeclareFieldAlias{lawtitleaddon}{titleaddon}

\urlstyle{same}% 
\DeclareFieldFormat{url}{\url{#1}}
\DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{urlseen}\addcolon\space#1}}

\DeclareFieldFormat[law]{lawtitle}{#1\isdot}

   \newbibmacro*{lawtitles}{%
 \printfield{lawtitle}%
 \setunit{\adddot\addspace}
  \printfield{lawsubtitle}%
  \setunit{\addspace}%
  \printfield{lawtitleaddon}
   \setunit{\addspace}%
  {\printtext[parens]{%
  \printdate}}%
  \setunit{\adddot\addspace}%
   {\printtext[smallcaps]{%
   \printlist{organization}}}
   \setunit{\addcolon\addspace}%
   {\printtext[italics]{%
   \printfield{maintitle}}}
   \setunit{\addspace}%
  \printfield{maintitleaddon}
   \setunit{\addspace}%
}

\renewbibmacro*{paragraphs}{%
  {\printtext{%
  \bibstring{paragraph}%
  \setunit{\addspace}%
    \printfield{paragraph}}}%
  \ifnameundef{paragraph}%
    {}
    {\printtext{%
       \bibstring{article}%
       \setunit{\addspace}%
       \printfield{article}}}%
  \setunit{\addcomma\addspace}%
 \bibstring{subparagraph}%
  \setunit{\addspace}%
  \printfield{subparagraph}%
  \setunit{\addcomma\addspace}%
   \bibstring{number}%
  \setunit{\addspace}%
  \printfield{number} 
}

\newbibmacro*{url}{%
  \printfield{url}%
  \setunit{\addspace}
  \printfield{urldate}%
}


\DeclareBibliographyDriver{law}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{lawtitles}%
  \newunit\newblock
  \usebibmacro{paragraphs}%
  \newunit\newblock
  \usebibmacro{url}%
   \newunit\newblock
  \usebibmacro{finentry}}



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

\printbibliography
\end{document}

Current output

  1. Instead of the maintitle, it would be great if the lawtitle field would be displayed.

  2. The linebreak is slightly off.

  3. I have managed to get the bibstrings to work and article and paragraph are now displayed correctly as well! However, the ifundef parameter is not setup correctly, apparently, if I use article instead.

  4. After the url there should be printed the urldate with a certain style, see

    here

    I was wondering whether settings concerning online sources could be reused (which is why I added the following snippet to the code, however it only helped not to display the text "url:" in front of the url)

    \urlstyle{same}% 
    \DeclareFieldFormat{url}{\url{#1}}
    \DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{urlseen}\addcolon\space#1}}
    
  5. Somewhat unrelated, but I was wondering, whether it's okay to "merge" the dbx file the way I just did - (basically added my existing dbx file content in there journaltitleaddon).

If there's anything you could assist me with, I'd be forever grateful!

Sorry for the recurring questions, but to me that's the only way to improve and I am quite happy that I managed to create a working MWE with your help!

1 Answer 1

3
  1. When an authoryear style does not find an author or editor to use in the citation and there is no fallback label field either, it goes back to labeltitle. labeltitle is an artificial field that is automatically generated from several available title fields. The default definition is

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

    which just means that biblatex tries the fields in that order and sets labeltitle to the first field that is not empty. Hence, we get maintitle in the MWE. If you want lawtitle to play a role here, you can redefine the order of precedence of the fields

    \DeclareLabeltitle[law]{%
      \field{shorttitle}
      \field{title}
      \field{lawtitle}
      \field{maintitle}
    }
    

    The law ins square brackets means that this definition only applies to @law entries.

  2. This is a common issue in automatically-generated bibliographies. Have a look at How to adjust the breaking in the bibliography? for a discussion of a similar case with several possible workarounds. (This issue isn't fundamentally related to the other issues discussed here, so I suggest you ask a new question only about the line break if the linked discussion does not help you.)

  3. I'm not quite sure what you mean here, but there are a few pitfalls with \iffieldundef and friends. Firstly you need to know the datatype of a field you query. There are (proper) fields, lists and name lists. They are queried with \iffieldundef{<field>}, \iflistundef{<list>}, \ifnameundef{<name list>}, respectively. (The type of the fields in the standard data model are documented in the biblatex documentation. For your custom data model you know the type because you have to specify it.) Date fields are special beasts, since they are parsed and decomposed by the backend. This means that instead of \iffieldundef{date} you'd have to use \iffieldundef{year}.

  4. Things are already set up for that. Don't redefine the url bibmacro and call \usebibmacro{url+urldate} instead of the simple \usebibmacro{url}, which will only print the URL.

  5. Yes it is fine to combine several .dbx files the way you did. Depending on whether you find it more natural to separate the different \DeclareDatamodelFields by 'topic' (one for journaltitleaddon one for @law fields etc.) you may want to keep the \DeclareDatamodelFields declarations separate (as they are now) or merge them for a more compact feel. biblatex doesn't care.

Modified MWE

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@law{se:l3help,
  lawtitle       = {Kaisei minp\={o} j\={o}bun},
  date           = {2012-02-26},
  year           = {2012},
  lawtitleaddon  = {{\"U}berarbeiteter Gesetzestext des Zivilgesetzbuchs},
  lawsubtitle    = {Tsuika},
  maintitle      = {testmaintitle},
  maintitleaddon = {testmaintitleaddon},
  urldate        = {2019-07-21},
  url            = {http://dl.ndl.go.jp/info:ndljp/pid/1275567},
  organization   = {Saik\={o}-saiban-sho},
  paragraph      = {5},
  subparagraph   = {3},
  number         = {2},
}
@article{Ueda.2005,
 title             = {Heian-ky\={o} no seiritsu to higashiajia},
 titleaddon        = {Die Errichtung von Heian-ky\={o} und Ostasien},
 journaltitle      = {Kodai higashi ajia no rekishi to bunka},
 journaltitleaddon = {Geschichte und Kultur im ostasiatischen Altertum},
 author            = {Ueda, Masaaki},
 year              = {2005},
 volume            = {122},
 publisher         = {Higashiajia no kodai bunka kodai-gaku kenky\={u}-jo},
 location          = {Japan},
 pages             = {2-8},
 Catalogue-Link*   = {http://iss.ndl.go.jp/books/R000000004-I7260043-00}
}

\end{filecontents*}
\begin{filecontents}{customstyles.dbx}
\DeclareDatamodelFields[type=field, datatype=literal]{
  journaltitleaddon}

\DeclareDatamodelEntryfields[article,periodical]{
  journaltitleaddon}

\DeclareDatamodelEntrytypes{law}
\DeclareDatamodelFields[type=field,datatype=literal]{
  lawsubtitle,
  lawtitle,
  lawtitleaddon,
}
\DeclareDatamodelFields[type=field, datatype=verbatim]{
  paragraph,
  subparagraph,
  article,
}
\DeclareDatamodelEntryfields[law]{
  paragraph,
  subparagraph,
  article,
  lawsubtitle,
  lawtitle,
  lawtitleaddon,
}
\end{filecontents}
\documentclass[
  12pt,
  a4paper,
  headings=standardclasses,
  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,
  datamodel=customstyles,
  maxnames=25,
  innamebeforetitle=true,
  usetranslator=true,
  alldates=terse,
  labeldate=year,
  dashed=false,
  isbn=false
]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}


\begin{filecontents*}{custombibstring-ngerman.lbx}
\ProvidesFile{custombibstring-ngerman.lbx}[2019/07/26 english with additions for law]
\InheritBibliographyExtras{ngerman}
\DeclareBibliographyStrings{%
  inherit      = {ngerman},
  andothers    = {{et al\adddot}{et al\adddot}},
  byeditor     = {{herausgegeben von}{hg\adddotspace von}},
  editor       = {{Herausgeber}{Hg\adddot}},
  editors      = {{Herausgeber}{Hg\adddot}},
  urlseen      = {{letzter Abruf}{letzter Abruf}},
  paragraph    = {{Paragraph}{\S}},
  subparagraph = {{Absatz}{Abs\adddot}},
  article      = {{Artikel}{Art\adddot}},
}
\end{filecontents*}


\DeclareLabeltitle[law]{%
  \field{shorttitle}
  \field{title}
  \field{lawtitle}
  \field{maintitle}
}

\DeclareSortingTemplate{nyvt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{lawtitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{volume}
    \literal{0}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
}


\NewBibliographyString{paragraph,subparagraph,article}
\DeclareLanguageMapping{ngerman}{custombibstring-ngerman}

\renewcommand*{\titleaddonpunct}{\addspace}
\DeclareFieldFormat{titleaddon}{\mkbibbrackets{#1}}
\DeclareFieldAlias{booktitleaddon}{titleaddon}
\DeclareFieldAlias{maintitleaddon}{titleaddon}
\DeclareFieldAlias{journaltitleaddon}{titleaddon}
\DeclareFieldAlias{lawtitleaddon}{titleaddon}


\DeclareFieldFormat[law]{lawtitle}{#1\isdot}
\DeclareFieldFormat[law]{date}{\mkbibparens{#1}}
\DeclareListWrapperFormat[law]{organization}{\textsc{#1}}

\newbibmacro*{lawtitles}{%
  \printfield{lawtitle}%
  \setunit{\subtitlepunct}%
  \printfield{lawsubtitle}%
  \setunit{\titleaddonpunct}%
  \printfield{lawtitleaddon}
  \setunit{\addspace}%
  \printdate
  \newunit
  \printlist{organization}%
  \setunit{\addcolon\addspace}%
  \printfield{maintitle}%
  \setunit{\titleaddonpunct}%
  \printfield{maintitleaddon}%
}

\DeclareFieldFormat[law]{article}{\bibstring{article}~#1}
\DeclareFieldFormat[law]{paragraph}{\bibstring{paragraph}~#1}
\DeclareFieldFormat[law]{subparagraph}{\bibstring{subparagraph}~#1}
\DeclareFieldFormat[law]{number}{\bibstring{number}~#1}

\newbibmacro*{paragraphs}{%
  \printfield{article}%
  \setunit*{\addcomma\space}%
  \printfield{paragraph}%
  \setunit{\addcomma\space}%
  \printfield{subparagraph}%
  \setunit*{\addcomma\space}%
  \printfield{number}%
}

\urlstyle{same}%
\DeclareFieldFormat{url}{\url{#1}}
\DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{urlseen}\addcolon\space#1}}


\DeclareBibliographyDriver{law}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{lawtitles}%
  \newunit\newblock
  \usebibmacro{paragraphs}%
  \newunit\newblock
  \usebibmacro{url+urldate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}}


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

\printbibliography
\end{document}

Kaisei minpo jobun. Tsuika [Überarbeiteter Gesetzestext des Zivilgesetzbuchs] (26.02.2012). Saik¯ o-saiban-sho: testmaintitle [testmaintitleaddon]. § 5, Abs. 3, Nr. 2. http://dl.ndl.go.jp/info:ndljp/pid/1275567 (letzter Abruf: 21.07.2019).

I changed a few more things about your code. Most changes are because I prefer to avoid \iffieldundef and friends where possible. biblatex is very good at dealing with missing fields if they are printed with \printfield and formatted only through \DeclareFieldFormat. Usually this requires moving \printtext formatting and \bibstrings into \DeclareFieldFormat.

A last note on the date fields: As mentioned above date fields are special. In the .bib file a date is ideally given in the date field (year and month are retained for backwards compatibility with BibTeX). The date is then parsed and split into its components so that LaTeX can parse it more easily. LaTeX only gets to see the decomposed date parts (year, month, day, ...). biblatex does not (quite) know whether a date came from date or year in the .bib files, so you can simply alway use \printdate, a special macro that handles the date formatting and printing for you.

edit: Added lawtitle to sorting scheme.

7
  • thank you very much! :) Looking forward to it - as you might have guessed, I did not plan to print the date twice, but either the date or (if undefined) the year :)
    – user168390
    Jul 26, 2019 at 7:15
  • 1
    @user168390 Have a look at the edit, please. I have recoded the bibmacros roughly like I would write them.
    – moewe
    Jul 26, 2019 at 12:56
  • Thank you @moewe that worked perfectly fine! :) what would we do without you! just a quick follow-up question. If I don't want to use filecontents for the lbx file, can I use a separate file as well (just like with the dbx file) and link it in the bib definition like "datamodel=customstyles" ?
    – user168390
    Jul 26, 2019 at 13:50
  • 1
    @user168390 Yes. You don't need the filecontents at all. It's just to make the example self-contained. The role of datamodel=customstyles is played by \DeclareLanguageMapping{ngerman}{custombibstrings}. I would recommend, however, to add the language to the .lbx file name as well (will edit the answer in a moment to show what I mean).
    – moewe
    Jul 26, 2019 at 13:54
  • Thank you very much! I just noticed, that the sorting is off - is there a way to tell it to sort according to lawtitle? Or should I open a new ticket for it? Sorry and thank you! @moewe
    – user168390
    Jul 27, 2019 at 10:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .