30

I would like to create a custom format for citing authors' names in the text, let's call it "newformat". One option I can think of is creating a new bibmacro for names where the parameters are changed to my liking, such as

\documentclass{article}

  \usepackage{filecontents}
  \usepackage[backend=biber]{biblatex}[2016/01/01] %the latest version of biblatex?
  % biber is version 2.4; the latest?

\begin{filecontents}{\jobname.bib}
@misc{Doe12,
  author = {Doe, John},
  year = {2012},
  title = {A macro for formatting names},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\nocite{*}

\newbibmacro{name:newformat}{\printnames{authors}}
\DeclareNameFormat{newformat}{%
  \usebibmacro{name:newformat}{\textbf{#1}}{\textbf{#3}}{#5}{#7}%
  \usebibmacro{name:andothers}%
}

\begin{document}

  \section*{Testing the format here}

  I am citing
  \citename{Doe12}[newformat]{author}

  \printbibliography % to make sure that the .bib file is properly formated.

\end{document}

Here, I just used \textbf for the sake of the example, but I ultimately want to use other functions, say upper case or palindrome!

However, I get this weird error message:

! Illegal parameter number in definition of \blx@defformat@d.
<to be read again> 
                   3
l.20   \usebibmacro{name:last}{#1}{#3
                                     }{#5}{#7}%

which seems to indicate that the second option {#3} is not expected. I am a bit at a lost here; I checked the biblatex package and \usebibmacro{name:last} must be given 4 parameters, isn't it? Please advise.

3
  • 2
    The syntax of the command has changed. See github.com/plk/biblatex/issues/372 Commented Mar 14, 2016 at 21:14
  • You could probably achieve what you want here by temporary redefining \mkbibnamefamily and friends. That way you don't have to fiddle round with name formats.
    – moewe
    Commented Mar 15, 2016 at 6:59
  • @UlrikeFischer Do you want to write up an answer? I feel we are going to see quite some of those questions (this one, for example) and a good go-to answer would be nice.
    – moewe
    Commented Mar 15, 2016 at 7:00

2 Answers 2

35

In biblatex 3.3. the format of \DeclareNameFormat has changed. In its code part it no longer accepts 8 arguments, but only one. For the various parts of a name there are now macros which you get by splitting the main name data with \namepart.

The change in the name formatting also affects commands like \mkbibnamelast (now \mkbibnamefamily) and bib-macros like \name:first-last (now name:given-family) and options like firstinits (now giveninits). This means that quite a number of older documents and styles must be adapted. One should to check the documentation when using older examples involving the formatting of names.

Your example could look like this in the new format

\documentclass{article}

  \usepackage{filecontents}
  \usepackage[backend=biber]{biblatex}[2016/01/01] %the latest version of biblatex?
  % biber is version 2.4; the latest?

\begin{filecontents}{\jobname.bib}
@misc{Doe12,
  author = {Doe, John},
  year = {2012},
  title = {A macro for formatting names},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\nocite{*}

\newbibmacro{name:newformat}{%
   \textbf{\namepartfamily}  % #1->\namepartfamily, #2->\namepartfamilyi
   \textbf{\namepartgiven}   % #3->\namepartgiven,  #4->\namepartgiveni
   [prefix: \namepartprefix] % #5->\namepartprefix, #6->\namepartprefixi
   [suffix: \namepartsuffix] % #7->\namepartsuffix, #8->\namepartsuffixi
   }

\DeclareNameFormat{newformat}{%
  \nameparts{#1}% split the name data, will not be necessary in future versions
  \usebibmacro{name:newformat}%
  \usebibmacro{name:andothers}%
}

\begin{document}

  \section*{Testing the format here}

  I am citing
  \citename{Doe12}[newformat]{author}

\end{document}

Be aware: I did not try to make a good looking format. E.g I didn't add suitable tests for empty name parts.

The example also don't use the same style as the standard definitions. biblatex itself would define the bib macro as a macro with 4 arguments:

   \newbibmacro*{name:newformat}[4]{ \textbf{#1} \textbf{#2} ...}

and then call the macro with arguments in \DeclareNameFormat

    \usebibmacro{name:newformat}{\namepartfamily}{\namepartgiven}{...}{...}

Imho my version is easier to understand and easier to extend, but this is a matter of taste.

The bonus is that the name system is now extensible and new name parts can be added in the future.

Links for further reading:

https://github.com/plk/biblatex/issues/372

http://www.texdev.net/2016/03/13/biblatex-a-new-syntax-for-declarenameformat/

Check also the documentation, the release notes (in the doc folder of biblatex) and the examples (for an example how to extend the name system).

8
  • 2
    Thank you very much. I believe this answer would work very well as a go-to name formatting with version >= 3.3 answer. Would you mind adding some of the links and references you put in tex.stackexchange.com/questions/299061/…
    – moewe
    Commented Mar 15, 2016 at 9:41
  • Maybe you could add an easy to parse list of things that need changing along with their new counterparts. I suppose we are going to send a lot of people here and it would be nice if this answer could give an easy-to-find solution to all name-related problems in v 3.3.
    – moewe
    Commented Mar 15, 2016 at 13:35
  • @moewe: I will try to expand the answer when I see new related questions. But I don't have much time now, so it will have to go step by step. (I already moved the list of other things to change to the top, so that it can be seen directly). Commented Mar 15, 2016 at 13:38
  • Oh, there is no need to rush this at all.
    – moewe
    Commented Mar 15, 2016 at 13:49
  • 1
    @PWillms this is not a bug and my code is not a workaround. The format changed between version 3.3. and 3.4. and I'm describing how to adapt the name format in the newer biblatex versions. Commented Oct 31, 2017 at 20:04
1

Bolding name, family name and date in biblatex. I tried, it works

\AtBeginBibliography{%
    \renewcommand*\mkbibnamegiven[1]{\mkbibbold{#1}}
    \renewcommand*\mkbibnamefamily[1]{\mkbibbold{#1}}
    \renewcommand*\mkbibnameprefix[1]{\mkbibbold{#1}}
    \renewcommand*\mkbibnameaffix[1]{\mkbibbold{#1}}
    \DeclareFieldFormat{parens}{\mkbibbold{\mkbibparens{#1}}}
    \DeclareFieldFormat{date}{\mkbibbold{#1}}
    \DeclareFieldFormat{author}{\mkbibbold{#1}}
    }
    \DeclareNameAlias{sortname}{family-given}
    \DeclareNameAlias{default}{family-given}
1
  • 1
    Welcome to TeX.SX! You may want to add a few % here and there to prevent unwanted space. I don't think this quite answers the question as posed in the OP. While you show how to bold certain elements of the bibliography, this answer does not show how to adapt code using the old name format to the new format.
    – moewe
    Commented May 31, 2018 at 16:34

You must log in to answer this question.

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