[Tex/LaTex] Biblatex customization: author name format defined by hyphenation (localization)

babelbiblatexhungarian

I try to use biblatex (to be customized) with Hungarian babel language definition files. The babel language for Hungarian is called magyar (means: Hungarian).

I am writing a text in which I cite English and Hungarian articles also. I managed to create magyar.lbx based on english.lbx to be able to use Hungarian text in the bibliography with the help of specifying hyphenation = {magyar} in bib files, and it works like a charm.

The problem is that I would like to modify the format of bibliography further, as in Hungarian the last and first name are in reversed order, e.g. in Hungarian Jules, Verne is written like: Verne Jules.

This is implemented in huplain.bst for using with BibTeX (with the option specifying huname =1), but unfortunatelly it does not work with author-year format citation (e.g. natbib or babelbib), that is why I had to look for other solutions. It looks like for me, that modifying biblatex's code is the easiest way.

Does anyone have idea about how could I put some conditional statements maybe to \DeclareNameFormat{labelname} to be able to list Hungarian names in reverse order without a comma between last and first name? I hope it can be done. Thanks for reading!


Editing on the bases of @michal.h21's answer:

I have made a summary in Hungarian language about the results of this topic based on @michal.h21's answer and comments. You can find it here.

Most important features do work, some lesser parts are not so sexy, but will work it out somehow. Any extra comments are welcome!

Best Answer

you can try to define formatting command in \DeclareBibliographyExtras section in lbx file.

so in magyar.lbx

\protected\def\nameprint#1#2{#1\space#2}

and in english.lbx

\protected\def\nameprint#1#2{#2\addcomma\space#1}

and in bbx define name format:

\DeclareNameFormat{default}{%
   \nameprint{#1}{#3}
   ..call macro for punctation
   ..call macro for and others
 }


Edit: I was in hurry yesterday, so didn't post complete example.

DeclareNameFormat is command, which accepts 8 parameters. they are:

  • #1 The last names. If a name consists of a single part only (for example, ‘Aristotle’), this part will be treated as the last name.
  • #2 The last names, given as initials.
  • #3 The first names. This argument also includes all middle names.
  • #4 The first names, given as initials.
  • #5 The name prefixes, for example von, van, of, da, de, del, della, etc. Note that name prefixes are referred to as the ‘von part’ of the name in the BibTeX documentation.
  • #6 The name prefixes, given as initials.
  • #7 The name aYxes, for example ‘junior’, ‘senior’, ‘der Jüngere’, ‘der Ältere’, etc. Note that name aYxes are referred to as the ‘junior part’ of the name in the BibTeX documentation.
  • #8 The name aYxes, given as initials.

This command is called on every name in list, if number of authors is smaller than \value{maxnames}. If you have 8 authors and maxnames is set to 5, it will print only authors up to \value{minnames}, I have this value set to 3.

We call command \nameprint with full last and first name. If you need other parts of name use some parameter from list above.

Then we have to print punctuation after every author. I do that with folowning macro:

\newbibmacro{names:separator}{%
  \ifthenelse{\value{listcount}<\value{liststop}}%
  {\addsemicolon\addspace}%
  {}%
 }

This macro prints semicolon and space after every author except last one. If you want other punctuation than semicolon, you can replace it with some other punctuation command. Their list is on the page 155 of biblatex manual. Or you can directly print char with \printtext command.

My andothers macro look like this:

\newbibmacro*{names:andothers}{%
 \ifboolexpr{%
   test {\ifnumequal{\value{listcount}}{\value{liststop}}}%
   and%
   test \ifmorenames%
 }{\bibsstring{andothers}}%
 {}%
}

We don't have to add punctuation after andothers, because it is printed automatically with next \newunit command in your \DeclareBibliographyDriver.

So my \DeclareNameFormat now looks this way:

\DeclareNameFormat{default}{%
 \nameprint{#1}{#3}
 \usebibmacro{names:separator}%
 \usebibmacro{names:andothers}%
 }

Now I see, that my first version of \nameprint was incorrect. Magyar version should probably be:

 \protected\def\nameprint#1#2{#2\space#1}

And English:

\protected\def\nameprint#1#2{#1\addcomma\space#2}

You have to define this macro for every language you use in your bibliography, otherwise you will get error message about undefined command.


Another edit based on comments below this post:

you must create bbx and cbx file. For example:

huglain.bbx

\ProvidesFile{hugplain.bbx}

\DeclareLanguageMapping{magyar}{magyar}
\RequireBibliographyStyle{authoryear}

\renewcommand*{\finalnamedelim}{%
  \ifnumgreater{\value{liststop}}{2}{\finalandcomma}{}%
  \addspace\bibsstring{and}\space}

\newbibmacro{names:separator}{%
  \ifthenelse{\value{listcount}<\value{liststop}}%
  {\addcomma\addspace}%
  {}%
 }

\newbibmacro{names:separator2}{%
  \ifthenelse{\value{listcount}<\value{liststop}}%
  {\addspace}%
  {}%
 }

\newbibmacro*{names:andothers}{%
 \ifboolexpr{%
   test {\ifnumequal{\value{listcount}}{\value{liststop}}}%
   and%
   test \ifmorenames%
 }{\bibsstring{andothers}\addcomma}%
 {}%
}

%\DeclareNameFormat{default}{%
% \nameprint{#1}{#3}
% \usebibmacro{names:separator}%
% \usebibmacro{names:andothers}%
% }

\DeclareNameFormat{sortname}{%
 \nameprint{#1}{#3}
 \usebibmacro{names:separator}%
 \usebibmacro{names:andothers}%
 }



\endinput

notice line

    \DeclareLanguageMapping{magyar}{magyar}

this is loading of your magyar.lbx file. In your current version, this file is not used at all, so in your citation there is "and" before last name instead of "és"

hugplain.cbx is rather simple

\ProvidesFile{hugplain.cbx}
\RequireCitationStyle{authoryear}
\endinput

In your tex file delete all biblatex macros and call babel with \usepackage[english,magyar]{babel}. Last language is the main language of document.

at top of file magyar.lbx, right below line \PorvidesFile... add lines

\InheritBibliographyExtras{english}
\InheritBibliographyStrings{english}

and you have error in bibliography strings, replace

bibliography     = {{Felhasznált\addspaceirodalom}{Felhasznált\addspaceirodalom}},

with

bibliography     = {{Felhasznált\addspace{}irodalom}{Felhasznált\addspace{}irodalom}},

and finally, you should add hyphenation fields even to english publications in your bib files, unless you want to have citation like Berk, Kriegler, és Ylvisaker

Related Question