2

I am trying to write my own biblatex style, and…

  • The first field in each bibliography entry must be in uppercase;
  • When there is no author or editor, I must print the organization first and it must be in uppercase;
  • If there is no author, editor or organization, then the title goes first and it's in uppercase;
  • If there is an author and an organization, the author goes first and the organization goes last.

So here's what I tried to do:

\begin{filecontents}{\jobname.bib}
@book{withorg,
 year    =1985,
 title   ={The History and Social Influence of the Potato},
 organization = {Some Organization}}
@book{withoutorg,
 year    =1985,
 title   ={The History and Social Influence of the Potato}}
\end{filecontents}

\documentclass{article}

\usepackage[backend=biber, bibstyle=standard]{biblatex}
\addbibresource{\jobname.bib}

\DeclareFieldFormat{uppercase}{\MakeUppercase{#1}}
\DeclareListFormat{uppercase}{\MakeUppercase{#1}}

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/organization}% 1.
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{maintitle+title}% 2.
  \newunit\newblock
  % The organization is always printed here,
  % but it should be printed only when it wasn't already
  % in \usebibmacro{author/editor+others/organization}
  \printlist{organization}% 3.
  \usebibmacro{finentry}}

\newbibmacro*{author/editor+others/organization}{% 1.
    \ifboolexpr{%
        test {\ifnameundef{author}}
        and
        test {\ifnameundef{editor}}
    }
    {\printlist[uppercase]{organization}}
    %\clearlist{organization}} This causes the title to be capitalized when it shouldn't.
    {\usebibmacro{author/editor+others}}}

\renewbibmacro*{title}{% 2.
    \ifboolexpr{%
        test {\iffieldundef{title}}
        and
        test {\iffieldundef{subtitle}}
    }
        {}
        {\printtext[title]{%
            \ifboolexpr{%
                test {\ifnameundef{author}}
                and
                test {\ifnameundef{editor}}
                and
                test {\iflistundef{organization}}
            }
                {\printfield[uppercase]{title}}
                {\printfield[titlecase]{title}}
            \normalfont{\setunit{\subtitlepunct}%
            \printfield[noformat]{subtitle}}}%
        \newunit}%
    \printfield{titleaddon}}

\begin{document}
  \nocite{*}
  \printbibliography
\end{document}
  1. First the author/editor+others/organization macro checks if there is no author or editor, and if there isn't it prints the organization.

  2. Then the title macro checks if there is no author, editor or organization, and if there isn't it prints the title in uppercase.

  3. Then the organization is printed, and as it is it's always printed, but I need it there only when it wasn't already printed before in the author/editor+others/organization macro.

So my first thought was to use \clearlist{organization} after printing the organization, at the end of item 1 there. The problem is that item 2 checks if there is an organization to decide if the title should be capitalized or not. So if I use \clearlist it will be capitalized even if the organization was already printed.

So here's what I get if I don't use \clearlist:

without clearlist

The organization is printed twice in that first entry.

And here's what I get if I do use \clearlist:

with clearlist

The title is capitalized in the first entry, when it shouldn't be.

The bottomline is: if I clear previous fields, I need a way to tell if the title is the first field printed without checking if the previous fields are undefined, so I can make it uppercase only when it's the first. Or else, if I don't clear the previous fields, I need a way to tell if the organization was already printed so I don't print it again. Any ideas?

(I know I could use the author/editor fields for the organization when necessary, but I'd rather not do that… hopefully other people will use my style and their bibliographies are already using the organization field like this, and also that would give me headaches with my custom name formats… and an organization isn't actually a name after all, so I think this is better.)

  • I know you wrote that you don't want to use the author field. But please consider that the biblatex documentation has no probems with using an organization as author (it calls them "corporate authors" and even has a section about them in the documentation: §2.3.3 Corporate Authors and Editors). Corporate authors should not interfere with the name format if they are given in the proper format (see here). – moewe May 1 '16 at 15:03
  • Note also that per the biblatex docs a @book doesn't have an organization (it is neither an optional nor required field), so those that build their .bib file strictly by those rules won't have organizations for @books anyway. – moewe May 1 '16 at 15:05
3

You can just save delete the organization field, but save it in a macro for comparison before doing so.

\newbibmacro*{author/editor+others/organization}{% 1.
   \savelistcs*{organization}{savedorg}%
    \ifboolexpr{%
        test {\ifnameundef{author}}
        and
        test {\ifnameundef{editor}}
    }
    {\printlist[uppercase]{organization}%
     \clearlist{organization}}%
    {\usebibmacro{author/editor+others}}}

then you don't check against \iflistundef{organization} but against \ifcsundef{savedorg}

\renewbibmacro*{title}{% 2.
    \ifboolexpr{%
        test {\iffieldundef{title}}
        and
        test {\iffieldundef{subtitle}}
    }
        {}
        {\printtext[title]{%
            \ifboolexpr{%
                test {\ifnameundef{author}}
                and
                test {\ifnameundef{editor}}
                and
                test {\ifcsundef{savedorg}}
            }
                {\printfield[uppercase]{title}}
                {\printfield[titlecase]{title}}%
            \normalfont{\setunit{\subtitlepunct}%
            \printfield[noformat]{subtitle}}}%
        \newunit}%
    \printfield{titleaddon}}

Note that the uppercase list format is probably better given as

\DeclareListFormat{uppercase}{%
  \usebibmacro{list:delim}{#1}%
  \MakeUppercase{#1}\isdot
  \usebibmacro{list:andothers}}

MWE

\documentclass{article}
\usepackage[backend=biber]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{withorg,
 year    =1985,
 title   ={The History and Social Influence of the Potato},
 organization = {Some Organization and Another One}}
@book{withoutorg,
 year    =1985,
 title   ={The History and Social Influence of the Potato}}
\end{filecontents}
\addbibresource{\jobname.bib}

\DeclareFieldFormat{uppercase}{\MakeUppercase{#1}}
\DeclareListFormat{uppercase}{%
  \usebibmacro{list:delim}{#1}%
  \MakeUppercase{#1}\isdot
  \usebibmacro{list:andothers}}

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/organization}% 1.
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{maintitle+title}% 2.
  \newunit\newblock
  % The organization is always printed here,
  % but it should be printed only when it wasn't already
  % in \usebibmacro{author/editor+others/organization}
  \printlist{organization}% 3.
  \usebibmacro{finentry}}

\newbibmacro*{author/editor+others/organization}{% 1.
   \savelistcs*{organization}{savedorg}%
    \ifboolexpr{%
        test {\ifnameundef{author}}
        and
        test {\ifnameundef{editor}}
    }
    {\printlist[uppercase]{organization}%
     \clearlist{organization}}%
    {\usebibmacro{author/editor+others}}}

\renewbibmacro*{title}{% 2.
    \ifboolexpr{%
        test {\iffieldundef{title}}
        and
        test {\iffieldundef{subtitle}}
    }
        {}
        {\printtext[title]{%
            \ifboolexpr{%
                test {\ifnameundef{author}}
                and
                test {\ifnameundef{editor}}
                and
                test {\ifcsundef{savedorg}}
            }
                {\printfield[uppercase]{title}}
                {\printfield[titlecase]{title}}%
            \normalfont{\setunit{\subtitlepunct}%
            \printfield[noformat]{subtitle}}}%
        \newunit}%
    \printfield{titleaddon}}

\begin{document}
  \nocite{*}
  \printbibliography
\end{document}
| improve this answer | |
  • You are my hero, thank you. And thanks for the tip on the uppercase format. :) – dbmrq May 1 '16 at 19:55
  • Just one catch, in case anybody else needs this: I had to use the stared version, \savelistcs*, otherwise savedorg would still be defined for other entries after the first one. – dbmrq May 1 '16 at 21:26
  • @danielbmarques Ah, yes thank you for spotting that. I have edited the answer to use the starred version. – moewe May 2 '16 at 7:14

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.