1

I tried to define a new entrytype for bib files (mainly inspired by how to adapt the sorting of a custom type; I also want to define a type for standards). My main goal is to have a plain number in the number field, set the defining organization (currently, I use a new field definedby, but being able to reuse the field organization would be even better) and avoiding to state the same information again in other fields.

With my current state (see example below), the bibliography is printed fine (except of style alphabetic -- in this case I'm unable to generate a space between my two label parts). But I have still the following problems:

  • The entries are sorted according to my field definedby, but not according to the field number. I thought it should be easy to concatenate these to for sorting, but it seems something goes wrong.

  • I want to adapt citing to just use the fields definedby (or organization) and number, but only for this new entrytype, not for every type (at least \cite and \textcite should work, without interfering with e.g. \citetitle).

If I use the field shorthand (see commented line in the example), and also set the field sortkey to the same value, I get my desired behaviour. Is it possible to get the same behaviour without setting these fields and duplicating the data?

Any help or hints are appreciated!

MWE:

\begin{filecontents}{biblatex-dm.cfg}
\DeclareDatamodelEntrytypes{standard}
\DeclareDatamodelFields[type=field, datatype=literal, label=true]{definedby}
\DeclareDatamodelEntryfields[standard]{
  title,
  definedby,
  day,
  month,
  year,
  endday,
  endmonth,
  endyear,
  addendum,
  author,
  doi,
  editor,
  editortype,
  howpublished,
  language,
  location,
  note,
  number,
  organization,
  pubstate,
  subtitle,
  titleaddon,
  type,
  url,
  urldate,
  urlday,
  urlmonth,
  urlyear,
  version}
\DeclareDatamodelConstraints[standard]{
    \constraint[type=mandatory]{
      \constraintfieldsxor{
        \constraintfield{date}
        \constraintfield{year}
      }
    }
  }
\DeclareDatamodelConstraints[standard]{
  \constraint[type=mandatory]{
    \constraintfield{title}
    \constraintfield{number}
    \constraintfield{definedby}
  }
}
\end{filecontents}
\begin{filecontents}{lit.bib}
@standard{DIN:222,
  shorthand =  {DIN EN 222},
  definedby =  {DIN EN},
  number =     222,
  month =      mar,
  year =       {2002},
  title =      {Another standard with a long, unwiedly title that should not
    be used by cite in any way}
}
@standard{DIN:111,
  shorthand = {DIN EN 111},
  definedby =  {DIN EN},
  number =     111,
  month =      apr,
  year =       {2001},
  title =      {Title of some standard that is quite long and should not be used
    by cite, because we want the number as a simple, short reference}
}
@standard{DIN:min,
  definedby =    {DIN EN},
  number =       4711,
  title =        {Simple title of some standard},
}
\end{filecontents}
%
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[backend=biber,style=authoryear]{biblatex}

\newbibmacro*{definedby+number}{%
  \printfield{definedby}%
  \setunit{\addnbspace}%
  \printfield{number}}

\DeclareBibliographyDriver{standard}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \iffieldundef{labelalpha}{%
    \usebibmacro{definedby+number}%
  }{}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \printfield{howpublished}%
  \newunit\newblock
  \printfield{type}
  \newunit
  \printfield{version}%
  \newunit
  \printfield{note}%
  \newunit\newblock
  \printdate%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \pertype{standard}
      \step[fieldset=type, fieldvalue=Norm]
    }
    \map[overwrite=false]{
      \pertype{standard}
      \step[fieldsource=definedby]
      \step[fieldset=sortkey, origfieldval, final]
      \step[fieldsource=number]
      \step[fieldset=sortkey, origfieldval, append]
    }
  }
}

\DeclareLabelalphaTemplate[standard]{
  \labelelement{
    \field[final]{shorthand}
    \field{definedby}}
  \labelelement{\addspace}%% seems not to work
  \labelelement{\field{number}}}

\addbibresource{lit.bib}
\begin{document}
\cite{DIN:222}
\nocite{*}
\printbibliography
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.