2

I customized a bbx file for biblatex. I would like to have my references this way:

[namepartprefix] [namepartfamily], [namepartgiveni] ...

Unfortinately, there are some spurious spaces before the name prefix (see attachments below), which I can't get rid of. I know that you have to take care of spaces at the end of a line in your source code. I have put some % signs right at the end of all related lines in my bbx file. Though, it does not work properly. Where is my mistake?

Plus, the name prefix is missing from the label names, that appear as citations. How can I insert the von/de etc part to the label?


bbx-text.tex

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}

\usepackage[backend=biber,style=epicstructure,sorting=nyt]{biblatex}
    \addbibresource{test-companion.bib}

\begin{document}


\nocite{*}
\printbibliography
\end{document}

test-companion.bib:

@Book{Alpha:2002,
  author    = {Beta von Alpha},
  year      = {2002},
  title     = {Book title},
  edition   = {2},
  note      = {(= optional note)},
  keywords  = {Walter,KAetGen},
  publisher = {Chicago},
}

@book{Gamma:2015,
    editor = {Delta Gamma and Zeta Epsilon and Sigma Rho},
    Publisher = {Berlin},
    Title = {Another book},
    Year = {2015},
    edition = {3}}

@article{Iota:1998,
    Author = {Kappa Iota},
    Journal = {journal name},
    Volume = {24},
    Pages = {11--18},
    Title = {article title},
    Year = {1998},
    keywords={KAetGen}}

@incollection{Ny:2018,
    Author = {Lambda Ny},
    Booktitle = {book title},
    Editor = {E. Ditor},
    Pages = {93--129},
    Publisher = {London},
    Title = {article title},
    Year = {2018}}

epicstructure.bbx:

\ProvidesFile{epicstructure.bbx}[2018/06/29 v1.0 biblatex bibliography style]

% Load the standard style to avoid copy-pasting unnecessary material
\RequireBibliographyStyle{authoryear}

\ExecuteBibliographyOptions{dashed=true}
\setlength{\bibparsep}{0em}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Eigene Änderungen                           %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Titel kursiv
\DeclareFieldFormat{title}{\mkbibemph{#1}\isdot}
\DeclareFieldFormat[article]{title}{#1}
\DeclareFieldFormat[inbook,incollection]{title}{#1}


%%% Seitenzahlen in Zitaten ohne "S. " davor
\DeclareFieldFormat{postnote}{#1}
\DeclareFieldFormat{multipostnote}{#1}

%%% Seiten bei article ohne "pp. "
\DeclareFieldFormat{pages}{#1}
\newcommand*{\bibpagespunctarticle}{\addcolon\addspace}
\newcommand*{\bibpagespunctincollinbook}{\adddot\addspace}


%%% "/" zwischen mehreren Autoren
\renewcommand*{\multinamedelim}{\addslash}%
\renewcommand*{\finalnamedelim}{\addslash}%
\renewcommand*{\multilistdelim}{\addslash}%
\renewcommand*{\finallistdelim}{\addslash}%


\DeclareNameFormat{author}{%
  \ifblank{\namepartprefix}{}{\namepartprefix\addspace}%
  \namepartfamily%
    \ifblank{\namepartgiven}{}{\addcomma\addspace\namepartgiveni}%
  \ifthenelse{\value{listcount}<\value{liststop}}%
    {\multinamedelim}%
    {}%
}

\DeclareNameFormat{editor}{%
%  \ifblank{\namepartprefix}{}{\namepartprefix\addspace}%
  \namepartfamily%
    \ifblank{\namepartgiven}{}{\addcomma\addspace\namepartgiveni}%
  \ifthenelse{\value{listcount}<\value{liststop}}%
    {\multinamedelim}%
    {}%
}

\DeclareNameFormat{reversed}{%
  \ifblank{\namepartgiven}{}{\namepartgiveni\addspace}%
  \ifblank{\namepartprefix}{}{\namepartprefix\addspace}%
  \namepartfamily%
  \ifthenelse{\value{listcount}<\value{liststop}}%
    {\multinamedelim}%
    {}%
}

\renewbibmacro*{author}{%
  \ifboolexpr{%
    test \ifuseauthor%
    and%
    not test {\ifnameundef{author}}%
  }%
    {\printnames[author]{author}}%
    {}%
}

\renewbibmacro*{editor}{%
  \ifboolexpr{%
    test \ifuseeditor%
    and%
    not test {\ifnameundef{editor}}%
  }%
    {\printnames[author]{editor}}%
    {}%
}

\renewbibmacro*{author/editor}{%
  \ifboolexpr{%
    test \ifuseauthor%
    and%
    not test {\ifnameundef{author}}%
  }%
    {\usebibmacro{author}}%
    {\usebibmacro{editor}}%
}


\newbibmacro*{pages+article}{%
  \setunit{\bibpagespunctarticle}%
  \printfield{pages}%
  \newunit%
}


\renewcommand*{\bibnamedash}{%
    \rule[.5ex]{2em}{.15ex}.%
}


%%% ed./eds.
\DefineBibliographyStrings{english}{%
  editor={ed\adddot},%
  editors={eds\adddot},%
  in={in}%
}

\newbibmacro*{editorstrng}{%
  \ifthenelse{\value{editor}>1}%\OR\ifandothers{editor}}%
    {\bibstring{editors}}%
    {\bibstring{editor}}%
}

\DeclareFieldFormat{edition}{%
  #1%
}

\newbibmacro*{editionsupscr}{%
  \iffieldundef{edition}%
    {}%
    {\textsuperscript{\printfield{edition}}}%
}

%%% (year)//(ed., year) -- article/book
\newbibmacro*{editor+edition+year}{%
  \ifnameundef{editor}%
    {\mkbibparens{\usebibmacro{editionsupscr}\printfield{year}}}%
    {\mkbibparens{\usebibmacro{editorstrng}\addcomma\addspace\usebibmacro{editionsupscr}\printfield{year}}}%
}

%%% (year) -- inbook/incoll
\newbibmacro*{yearinbkcoll}{%
  \mkbibparens{\printfield{year}}%
}



\newbibmacro*{reversed:author}{%
    \printnames[reversed]{author}%
}

\newbibmacro*{reversed:editor}{%
    \printnames[reversed]{editor}\addspace\mkbibparens{\usebibmacro{editorstrng}}%
}


\renewbibmacro*{in:}{%
  \biblcstring{in}\intitlepunct%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\renewbibmacro*{publisher+location+date}{%
  \printlist{publisher}%
  \iflistundef{publisher}%
    {\setunit*{\addcomma\addspace}}%
    {\setunit*{\addcolon\addspace}}%
  \printlist{location}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{date}%
  \newunit%
}

\renewbibmacro*{volume+number+eid}{%
  \printfield{volume}%
%  \setunit*{\adddot}%
  \iffieldundef{number}{}{(\printfield{number})}%
  \setunit{\addcomma\addspace}%
  \printfield{eid}%
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Änderungen an Bibliography-Drivern          %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% article: FERTIG
\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}\addspace%
  \usebibmacro{editor+edition+year}\newunit\newblock%
  \usebibmacro{title}\addcomma%
  \newunit%
  \usebibmacro{journal+issuetitle}%
  \newunit%
  \usebibmacro{pages+article}%
  \usebibmacro{finentry}%
}



%%% book: FERTIG
\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}\addspace%
  \usebibmacro{editor+edition+year}\newunit\newblock%
  \usebibmacro{maintitle+title}%
  \newunit%
  \iffieldundef{maintitle}%
    {\printfield{volume}%
     \printfield{part}}%
    {}%
  \newunit%
  \printfield{volumes}%
  \newunit\newblock%
  \usebibmacro{series+number}%
  \newunit\newblock%
  \usebibmacro{publisher+location+date}%
  \newunit\newblock%
  \printfield{note}%
  \usebibmacro{finentry}%
}



%%% inbook: work
\DeclareBibliographyDriver{inbook}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author}\addspace%
  \usebibmacro{yearinbkcoll}\newunit\newblock%
  \usebibmacro{title}%
  \newunit\newblock%
  \usebibmacro{in:}%
  \usebibmacro{reversed:editor}%
  \newunit\newblock%
  \usebibmacro{maintitle+booktitle}%
  \newunit\newblock%
  \usebibmacro{publisher+location+date}\adddot%
  \printfield{pages}%
  \printfield{note}%
  \usebibmacro{finentry}%
}


\DeclareBibliographyAlias{incollection}{inbook}

\endinput

epicstructure.cbx:

\ProvidesFile{epicstructure.cbx}
[\abx@cbxid]

\ExecuteBibliographyOptions{labeldateparts,uniquename,uniquelist,autocite=inline}

\renewcommand*{\iffinalcitedelim}{\iflastcitekey}

\newbool{cbx:parens}

\newbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}}
       {\printnames[bibhyperref]{labelname}%
        \setunit{\printdelim{nameyeardelim}}}%
     \usebibmacro{cite:labeldate+extradate}}
    {\usebibmacro{cite:shorthand}}}

\newbibmacro*{citeyear}{%
  \iffieldundef{shorthand}
    {\iffieldundef{labelyear}
       {\usebibmacro{cite:label}}
       {\usebibmacro{cite:labeldate+extradate}}}
    {\usebibmacro{cite:shorthand}}}

\newbibmacro*{textcite}{%
  \ifnameundef{labelname}
    {\iffieldundef{shorthand}
       {\usebibmacro{cite:label}%
        \setunit{%
          \global\booltrue{cbx:parens}%
          \printdelim{nonameyeardelim}\bibopenparen}%
        \ifnumequal{\value{citecount}}{1}
          {\usebibmacro{prenote}}
          {}%
        \usebibmacro{cite:labeldate+extradate}}
       {\usebibmacro{cite:shorthand}}}
    {\printnames[bibhyperref]{labelname}%
     \setunit{%
       \global\booltrue{cbx:parens}%
       \printdelim{nameyeardelim}\bibopenparen}%
     \ifnumequal{\value{citecount}}{1}
       {\usebibmacro{prenote}}
       {}%
     \usebibmacro{citeyear}}}

\newbibmacro*{cite:shorthand}{%
  \printtext[bibhyperref]{\printfield{shorthand}}}

\newbibmacro*{cite:label}{%
  \iffieldundef{label}
    {\printtext[bibhyperref]{\printfield[citetitle]{labeltitle}}}
    {\printtext[bibhyperref]{\printfield{label}}}}

\newbibmacro*{cite:labeldate+extradate}{%
  \iffieldundef{labelyear}
    {}
    {\printtext[bibhyperref]{\usebibmacro{editionsupscr}\printlabeldateextra}}}

\newbibmacro{cite:labelyear+extrayear}{%
  \blx@warning{bibmacro 'cite:labelyear+extrayear' is deprecated.\MessageBreak
    Please use 'cite:labeldate+extradate'.\MessageBreak
    Using 'cite:labeldate+extradate' instead}%
  \usebibmacro{cite:labeldate+extradate}}

\newbibmacro*{textcite:postnote}{%
  \iffieldundef{postnote}
    {\ifbool{cbx:parens}
       {\bibcloseparen}
       {}}
    {\ifbool{cbx:parens}
       {\setunit{\postnotedelim}}
       {\setunit{\extpostnotedelim\bibopenparen}}%
     \printfield{postnote}\bibcloseparen}}

\DeclareCiteCommand{\cite}
  {\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\cite}
  {\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{citeyear}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citeyear}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcite}%[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\smartcite}[\iffootnote\mkbibparens\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \iffirstcitekey
     {\setcounter{textcitetotal}{1}}
     {\stepcounter{textcitetotal}%
      \textcitedelim}%
   \usebibmacro{textcite}}
  {\ifbool{cbx:parens}
     {\bibcloseparen\global\boolfalse{cbx:parens}}
     {}}
  {\usebibmacro{textcite:postnote}}

\DeclareCiteCommand{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printnames[bibhyperref]{labelname}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printnames[bibhyperref][1-1]{labelname}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citeyear}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printfield[bibhyperref]{year}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\citeyear}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printfield[bibhyperref]{\usebibmacro{editionsupscr}year}\printfield{extradate}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareMultiCiteCommand{\textcites}{\textcite}{}

\endinput

enter image description here

  • 1
    I'll have a closer look in a few minutes, but shouldn't you be fine with not redefining the author and editor formats and simply using the options useprefix=true and giveninits=true (and, I forgot, \DeclareNameAlias{sortname}{family-given})? – moewe Jun 29 '18 at 7:10
  • Thanks for your quick reply. I have just added your suggested options and the Alias. Now, I have the prefix part in the label. But still, there are those spurious spaces. EDIT: Reference "von Alpha, B. ..." is now at the very end of the bibliography, as sorted by "_v_on". – rsa-krypto Jun 29 '18 at 7:19
3

The main problem is the use of \ifblank to check for empty name parts. Since the name parts are macros, you must use \ifdefvoid. \ifblank checks if a supplied string is blank, but \ifdefvoid checks if the supplied command sequence expands to a blank string (more or less).

So your name formats should read

\DeclareNameFormat{author}{%
  \ifdefvoid{\namepartprefix}{}{\namepartprefix\addspace}%
  \namepartfamily%
    \ifdefvoid{\namepartgiven}{}{\addcomma\addspace\namepartgiveni}%
  \ifthenelse{\value{listcount}<\value{liststop}}%
    {\multinamedelim}%
    {}%
}

\DeclareNameFormat{editor}{%
%  \ifdefvoid{\namepartprefix}{}{\namepartprefix\addspace}%
  \namepartfamily%
    \ifdefvoid{\namepartgiven}{}{\addcomma\addspace\namepartgiveni}%
  \ifthenelse{\value{listcount}<\value{liststop}}%
    {\multinamedelim}%
    {}%
}

\DeclareNameFormat{reversed}{%
  \ifdefvoid{\namepartgiven}{}{\namepartgiveni\addspace}%
  \ifdefvoid{\namepartprefix}{}{\namepartprefix\addspace}%
  \namepartfamily%
  \ifthenelse{\value{listcount}<\value{liststop}}%
    {\multinamedelim}%
    {}%
}

I believe, however, that

\DeclareNameAlias{sortname}{family-given}

\DeclareNameAlias{reversed}{given-family}

together with the options useprefix=true,giveninits=true would give the same result with less work.


Have a look at §4.11.7 Using the Punctuation Tracker of the biblatex manual. You should never have naked \addspaces in your bibliography driver. They should always be wrapped into a \setunit (or \setunit*).

\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}
  \setunit{\addspace}%
  \usebibmacro{editor+edition+year}
  \newunit\newblock%
  \usebibmacro{title}
  \setunit{\addcomma}%
  \usebibmacro{journal+issuetitle}%
  \newunit%
  \usebibmacro{pages+article}%
  \usebibmacro{finentry}%
}

A few other things.

multinamedelim and friends are context-sensitive now, so I would use

\DeclareDelimFormat{multinamedelim}{\addslash}%
\DeclareDelimAlias{finalnamedelim}{multinamedelim}%
\DeclareDelimFormat{multilistdelim}{\addslash}%
\DeclareDelimAlias{finallistdelim}{multilistdelim}%

I think you can get rid of your redefinitions of author if you just issue the option dashed=false. For editor that might need a bit more work...

Never use \mkbibparens or other direct punctuation or formatting commands in bibmacros. Use \DeclareFieldFormat and \printtext instead (\DeclareFieldFormat is usually the better option, but sometimes one needs \printtext).

\DeclareFieldFormat{superedition}{%
  \ifinteger{#1}
    {}
    {\PackageWarning{epicstructure}{%
       Hang on! #1 does not look like an integer edition.\MessageBreak
       I will print it as superscript,\MessageBreak but it might look weird}}%
  \textsuperscript{#1}%
}

%%% (year)//(ed., year) -- article/book
\newbibmacro*{editor+edition+year}{%
  \printtext[parens]{%
    \ifnameundef{editor}%
      {}
      {\usebibmacro{editorstrng}%
       \setunit{\addcomma\space}}%
    \printfield[superedition]{edition}%
    \iflabeldateisdate
      {\printlabeldate}
      {\printfield{year}}% <- still don't like that...
  }%
}

For yearinbkcoll you could use the global option date=year and then

\newbibmacro*{yearinbkcoll}{%
  \iffieldundef{year}
    {}
    {\printtext[parens]{\printdate}}%
}

\newbibmacro*{reversed:editor}{%
    \printnames[reversed]{editor}%
    \setunit{\addspace}
    \printtext[parens]{\usebibmacro{editorstrng}}%
}
\DeclareFieldFormat[article,periodical]{number}{\mkbibparens{#1}}

\renewbibmacro*{volume+number+eid}{%
  \printfield{volume}%
%  \setunit*{\adddot}%
  \printfield{number}%
  \setunit{\addcomma\addspace}%
  \printfield{eid}%
}
  • Thanks again, @moewe. I would like to change the sorting. With your awesome answer, the von authors are listed under v instead of under the first letter of the family name. Is there an easy way to fix this? Maybe a command, that I may comment out, if the publishers wants me to get back to the current settings someday. – rsa-krypto Aug 30 '18 at 7:04
  • 1
    @rsa-krypto Something like tex.stackexchange.com/q/440133/35864? If not, please ask a new question with an example and the expected output. – moewe Aug 30 '18 at 7:12
  • That's it. But the edition numbers are missing from in text citation. I'm very glad about your wide knowledge und quick help. I found your answer in tex.stackexchange.com/a/438013/164672, but when compiling I get , after the authors' names in the in text citations... – rsa-krypto Aug 30 '18 at 7:22
  • @rsa-krypto Sorry, I don''t understand your point about the edition numbers. Of course the linked code does not have edition numbers in citations, but you only need to copy the usprefix option and the \DeclareSortingNamekeyTemplate (and possibly the begentry definition). Those should not have an effect on the edition number in citations. I thought you already have those ready (I showed how that could work in tex.stackexchange.com/a/438013/35864)? – moewe Aug 30 '18 at 7:25
  • If you have a problem with my code from tex.stackexchange.com/a/438013/35864 I suggest you ask a new question. It will be easier to discuss that with example code, pictures of the output and a longer explanation of what exactly you need to have changed. – moewe Aug 30 '18 at 7:27

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.