2

this week I already got some help on the following problem. I have to write a thesis with the bibliography in authoryear style. However, there are some special entry types like norms that have to appear differently. While books and articles work fine, a norm has to look like this in the bibliography:

DIN 18351-1:2006-10: Title, Version.

in the text I want: text text text (DIN 18351-1, 2010)

Here I got a first version of a skript that I tried to modify: Bibliography entry apart from author year style

In the original version, the text "DIN" was written manually in the text and in the bibliography by \printtext{DIN}. Now I tried to define a field like "institute", where I can write for example ISO, DIN, VDI and so on. I defined a new field "institute" by \DeclareFieldFormat[norm]{institute}{#1} and tried to replace \printtext{DIN ISO} by printfield{institute}, but it doesn't appear when I compile. And I also have the problem that, as there is no author, I don't know how it will sort in the end. If you could help me on that I'd be so grateful!

this is what I have got so far:

\documentclass{article}

\usepackage[
%style = alphabetic,
citestyle=authoryear-comp,
bibstyle=authoryear,
]{biblatex}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib} 
@norm{diniso18351,
  title = {Title},
  number = {18351-1},
  version = {Entwurf},
  %pubstate = {DIN ISO 18351-1:2010-06},
  date = {2010-06},
  institute = {VDI}},
@book{Kaltschmitt.2003,
 year = {2003},
 title = {Erneuerbare Energien: Systemtechnik, Wirtschaftlichkeit, Umweltaspekte},
 address = {Berlin, Heidelberg and s.l.},
 edition = {dritte, vollst{\"a}ndig neu bearbeitete und erweiterte Auflage},
 publisher = {{Springer Berlin Heidelberg}},
 isbn = {978-3-662-07116-8},
 editor = {Kaltschmitt, Martin and Wiese, Andreas and Streicher, Wolfgang},
 doi = {10.1007/978-3-662-07115-1}
}  

\end{filecontents*}

\addbibresource{\jobname.bib} 

% add new diniso entry type
\DeclareDatamodelEntrytypes{
  norm}

% set bibliography label template for diniso entry type
\DeclareLabelalphaTemplate[norm]{%
  \labelelement{
    \field{number}
  }
}

% use comma before year in citations without authors
% this will apply to all entry types
\renewcommand*{\nonameyeardelim}{\addcomma\space}

% field formats for diniso entry type
\DeclareFieldFormat[norm]{version}{#1}
\DeclareFieldFormat[norm]{institute}{#1}
%\DeclareFieldFormat[norm]{pubstate}{\mkbibparens{#1}}
\DeclareFieldFormat[norm]{date}{%
  \thefield{year}%
  \bibdatesep
  \mkmonthzeros{\thefield{month}}}



% custom driver for diniso entry type
\DeclareBibliographyDriver{norm}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
%  \printtext{DIN EN ISO}%
  \printfield{institute}%   This field is not printed
  \setunit{\addspace}%
  \printfield{number}%
  \setunit{\addcolon}%
  \printdate
  \setunit{\addcolon\space}%
  \usebibmacro{title}%
  \setunit{\addcomma\space}%
  \printfield{version}%
  \setunit{\addspace}%
  %\printfield{pubstate}%
  \usebibmacro{finentry}}

% custom citation label for diniso entry type
\newbibmacro*{cite:label}{%
  \iffieldundef{label}
    {\ifentrytype{norm}
      {\printtext[bibhyperref]{%
         %\printtext{DIN EN1 ISO}%
         \printfield{institute}%   This field is not printed
         \printfield{number}
         \setunit{\addspace}%
        }}
       {\printtext[bibhyperref]{\printfield[citetitle]{labeltitle}}}}
    {\printtext[bibhyperref]{\printfield{label}}}}

\pagestyle{empty}
\begin{document}
\section{First section}

quote 1 \parencite{diniso18351}\\
quote 2 \parencite{Kaltschmitt.2003}

\printbibliography

\end{document}
6

The problem is that institute is not a default field name in biblatex. You need to declare it using:

\begin{filecontents*}{norm.dbx}
    \DeclareDatamodelEntrytypes{
        norm}
    \DeclareDatamodelFields[type=field,datatype=literal]{
        institute,
    }
    \DeclareDatamodelEntryfields[norm]{
        institute,
    }
\end{filecontents*}

and then use the option datamodel=norm when adding the package biblatex.

\usepackage[
    %style = alphabetic,
    datamodel=norm,
    citestyle=authoryear-comp,
    bibstyle=authoryear,
    ]{biblatex}

Note that either a comma or a closing brace } must appear directly after institute: otherwise the field name is added with a trailing space. See this answer for details.

enter image description here

\documentclass{article}

\usepackage{filecontents}

\begin{filecontents*}{norm.dbx}
    \DeclareDatamodelEntrytypes{
        norm}
    \DeclareDatamodelFields[type=field,datatype=literal]{
        institute,
    }
    \DeclareDatamodelEntryfields[norm]{
        institute,
    }
\end{filecontents*}
\begin{filecontents*}{\jobname.bib} 
    @norm{diniso18351,
        title = {Title},
        number = {18351-1},
        version = {Entwurf},
        %pubstate = {DIN ISO 18351-1:2010-06},
        date = {2010-06},
        institute = {VDI}},
    @book{Kaltschmitt.2003,
        year = {2003},
        title = {Erneuerbare Energien: Systemtechnik, Wirtschaftlichkeit, Umweltaspekte},
        address = {Berlin, Heidelberg and s.l.},
        edition = {dritte, vollst{\"a}ndig neu bearbeitete und erweiterte Auflage},
        publisher = {{Springer Berlin Heidelberg}},
        isbn = {978-3-662-07116-8},
        editor = {Kaltschmitt, Martin and Wiese, Andreas and Streicher, Wolfgang},
        doi = {10.1007/978-3-662-07115-1}
    }  

\end{filecontents*}

\usepackage[
%style = alphabetic,
datamodel=norm,
citestyle=authoryear-comp,
bibstyle=authoryear,
]{biblatex}

\addbibresource{\jobname.bib} 

% set bibliography label template for diniso entry type
\DeclareLabelalphaTemplate[norm]{%
    \labelelement{
        \field{number}
    }
}

% use comma before year in citations without authors
% this will apply to all entry types
\renewcommand*{\nonameyeardelim}{\addcomma\space}

% field formats for diniso entry type
\DeclareFieldFormat[norm]{version}{#1}
\DeclareFieldFormat[norm]{institute}{#1}
%\DeclareFieldFormat[norm]{pubstate}{\mkbibparens{#1}}
\DeclareFieldFormat[norm]{date}{%
    \thefield{year}%
    \hyphen
    {\thefield{month}}}



% custom driver for diniso entry type
\DeclareBibliographyDriver{norm}{%
    \usebibmacro{bibindex}%
    \usebibmacro{begentry}%
    %  \printtext{DIN EN ISO}%
    \printfield{institute}%   This field is not printed
    \setunit{\addspace}%
    \printfield{number}%
    \setunit{\addcolon}%
    \printdate
    \setunit{\addcolon\space}%
    \usebibmacro{title}%
    \setunit{\addcomma\space}%
    \printfield{version}%
    \setunit{\addspace}%
    %\printfield{pubstate}%
    \usebibmacro{finentry}}

% custom citation label for diniso entry type
\newbibmacro*{cite:label}{%
    \iffieldundef{label}
    {\ifentrytype{norm}
        {\printtext[bibhyperref]{%
                %\printtext{DIN EN1 ISO}%
                \printfield{institute}%   This field is not printed
                \printfield{number}
                \setunit{\addspace}%
            }}
            {\printtext[bibhyperref]{\printfield[citetitle]{labeltitle}}}}
        {\printtext[bibhyperref]{\printfield{label}}}}

    \pagestyle{empty}
    \begin{document}
        \section{First section}

        quote 1 \parencite{diniso18351}\\
        quote 2 \parencite{Kaltschmitt.2003}

        \printbibliography

    \end{document}
  • One could use the list institution instead, which is available by default (but it's a list and not a field). type (which is a field) might also be a possible alternative. – moewe Dec 24 '17 at 19:42
  • Thank you a lot! I integrated the script now into the template I have to use and there is one small issue: When I cite a norm, there is a space before and after VDI 18351-1, so basically before the citation and between name and year. It looks like this: text text text VDI 4640-1 2010. That double space doesn't appear when I cite articles, books etc.. Can you image how this happens or is there a command I could add to suppress it? – Pjay Dec 25 '17 at 12:13
  • I am not sure because I am not getting any extra space when I compile the code. I get something like text text textVDI 4640-1, 2010, with only one space before 2010. Maybe there is some additional code in your template that causes this? – javi_gg1 Dec 25 '17 at 13:52
  • thank you javi! I figured out it's the package hyperref... \usepackage[ extension=pdf, hypertexnames=true, bookmarksopen, pdfnewwindow ]{hyperref} abload.de/img/unbenanntzmsd0.jpg Do you have an idea how to get rid of that? Or why it only happens with the newly defined entry type? maybe it's because the link is on all the reference and not only on the year... can we change that? – Pjay Dec 27 '17 at 11:41
  • @Pjay If you are happy with only having the year hyperlinked to the bibliography entry, just remove all instances of [bibhyperref] and the spacing problem will be solved (make sure to load the package hyperref last). If you want the whole citation label to be hyperlinked, you can have a look here tex.stackexchange.com/q/27607/150114 . – javi_gg1 Dec 27 '17 at 18:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.