3

I would like to change certain aspects of how the bibliography looks for those entries that are in Hungarian, i.e. marked as langid = {magyar} in the bib file. Changing the look of the bibliography based on the langid field works well in these cases for example:

% no comma between family and given name if langid is magyar
\renewcommand{\revsdnamepunct}{%
  \ifboolexpr{%
     test {\iffieldequalstr{langid}{magyar}}%
  }{}{,\space}%
}
% book title is in italics if langid is magyar
\DeclareFieldFormat[book]{title}{
    \ifboolexpr{%
         test {\iffieldequalstr{langid}{magyar}}}{\emph{#1}}{#1}}

enter image description here

With the code below I can change the order of authors to family name first then given name, which I would like to have for Hungarian names, but this modifies the order of all names not just the Hungarian ones:

\DeclareNameAlias{sortname}{family-given}

enter image description here

And so I would like to introduce the same condition as in the above examples that only those names should have the family-given order where langid={magyar} in the bib file, but this gives an error:

\DeclareNameAlias{sortname}{
\ifboolexpr{%
     test {\iffieldequalstr{langid}{magyar}}}{family-given}{given-family}}}
! Missing \endcsname inserted.
<to be read again> 
                   \begingroup 
l.45 ...id}{magyar}}}{family-given}{given-family}}
                                                  }
? 

How can I change the order of authors to family-given for the bib entries for the Hungarian language entries?

Full minimal example:

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
    \setdefaultlanguage{hungarian}
\usepackage[backend=biber,
    bibstyle=authoryear,citestyle=authoryear-comp,
    sorting=nyt,
    maxbibnames=10,maxcitenames=2]{biblatex}
\usepackage{filecontents}

\begin{filecontents*}{\jobname.bib} @Book{KovacsKiss2022, author = {Kovács, Béla and János Kiss}, date = {2022}, title = {A {Hungarian} book with two authors}, location = {Budapest}, publisher = {Kiadó}, langid = {magyar}, }

@Book{Smith2022, author = {Smith, John and Leslie Taylor}, date = {2022}, title = {An {English} book with two authors}, publisher = {Publisher}, address = {City}, } \end{filecontents*} \addbibresource{\jobname.bib}

\renewcommand{\revsdnamepunct}{% \ifboolexpr{% test {\iffieldequalstr{langid}{magyar}}% }{}{,\space}% } \DeclareFieldFormat[book]{title}{ \ifboolexpr{% test {\iffieldequalstr{langid}{magyar}}}{\emph{#1}}{#1}}

\DeclareNameAlias{sortname}{family-given}

\DeclareNameAlias{sortname}{ \ifboolexpr{% test {\iffieldequalstr{langid}{magyar}}}{family-given}{given-family}}}

\begin{document}

\nocite{Smith2022,KovacsKiss2022}

\printbibliography[heading=subbibliography]

\end{document}

GKZ
  • 33
  • 1
    Welcome to TeX.se, and thanks for making a really clear question with a minimal example! – Alan Munn Aug 07 '22 at 13:22
  • @Alan Munn yes, thank you, "first" should have been "family", I edited the minimal example to the intended correct code – GKZ Aug 07 '22 at 14:28

2 Answers2

4

\DeclareNameAlias only lets you select an existing name format. It does not allow for complex logic, for that you need \DeclareNameFormat.

We build upon the definition of family-given/given-family, which can be found in biblatex.def (ll. 910-940). Since the format already inverts the first name in the list into family-given order, we we just add a test to also do so if the entry is in Hungarian.

Note that if \iffieldequalstr is the only condition you test for, it need not be wrapped in \ifboolexpr. \ifboolexpr only needs to come in if you want to combine several tests with "or" or "and".

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setdefaultlanguage{hungarian}

\usepackage[ backend=biber, style=authoryear-comp, maxbibnames=10, maxcitenames=2, ]{biblatex}

\renewcommand{\revsdnamepunct}{% \iffieldequalstr{langid}{magyar} {} {\addcomma\space}}

\DeclareFieldFormat[book]{title}{% \iffieldequalstr{langid}{magyar} {\emph{#1}} {#1}}

\DeclareNameAlias{sortname}{family-given/given-family:hungarian}

\DeclareNameFormat{family-given/given-family:hungarian}{% \ifboolexpr{ test {\ifnumequal{\value{listcount}}{1}} or test {\iffieldequalstr{langid}{magyar}}} {\ifgiveninits {\usebibmacro{name:family-given} {\namepartfamily} {\namepartgiveni} {\namepartprefix} {\namepartsuffix}} {\usebibmacro{name:family-given} {\namepartfamily} {\namepartgiven} {\namepartprefix} {\namepartsuffix}}% \ifboolexpe{% test {\ifdefvoid\namepartgiven} and test {\ifdefvoid\namepartprefix}} {} {\usebibmacro{name:revsdelim}}} {\ifgiveninits {\usebibmacro{name:given-family} {\namepartfamily} {\namepartgiveni} {\namepartprefix} {\namepartsuffix}} {\usebibmacro{name:given-family} {\namepartfamily} {\namepartgiven} {\namepartprefix} {\namepartsuffix}}}% \usebibmacro{name:andothers}}

\begin{filecontents*}{\jobname.bib} @Book{KovacsKiss2022, author = {Kovács, Béla and János Kiss}, date = {2022}, title = {A {Hungarian} book with two authors}, location = {Budapest}, publisher = {Kiadó}, langid = {magyar}, }

@Book{Smith2022, author = {Smith, John and Leslie Taylor}, date = {2022}, title = {An {English} book with two authors}, publisher = {Publisher}, address = {City}, } \end{filecontents*} \addbibresource{\jobname.bib}

\begin{document} \nocite{Smith2022,KovacsKiss2022}

\printbibliography[heading=subbibliography] \end{document}

Hivatkozások
Kovács Béla és Kiss János (2022). A Hungarian book with two authors. Budapest: Kiadó.
Smith, John és Leslie Taylor (2022). An English book with two authors. City: Publisher.

Depending on what you want to happen to the other name formats (e.g. "edited by ...") it may be more elegant to define a new bibmacro for Hungarian names and switch to using that on a case-by-case basis.

If you want to support lists of Hungarian and non-Hungarian names a different approach might be needed. nametemplates could help here (but might also be overkill): Bibtex/Biber: how to cite an author using Ethiopian conventions?.

moewe
  • 175,683
3

There may be a more elegant way to do this (so I would wait a bit before accepting this as an answer), but you can put your conditional inside \AtEveryBibitem to select the sortname alias that way:

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
    \setdefaultlanguage{hungarian}
\usepackage[backend=biber,
    bibstyle=authoryear,citestyle=authoryear-comp,
    sorting=nyt,
    maxbibnames=10,maxcitenames=2]{biblatex}
\usepackage{filecontents}

\begin{filecontents*}{\jobname.bib} @Book{KovacsKiss2022, author = {Kovács, Béla and János Kiss}, date = {2022}, title = {A {Hungarian} book with two authors}, location = {Budapest}, publisher = {Kiadó}, langid = {magyar}, }

@Book{Smith2022, author = {Smith, John and Leslie Taylor}, date = {2022}, title = {An {English} book with two authors}, publisher = {Publisher}, address = {City}, } \end{filecontents*} \addbibresource{\jobname.bib}

\renewcommand{\revsdnamepunct}{% \ifboolexpr{% test {\iffieldequalstr{langid}{magyar}}% }{}{,\space}% } \DeclareFieldFormat[book]{title}{ \ifboolexpr{% test {\iffieldequalstr{langid}{magyar}}}{\emph{#1}}{#1}}

\DeclareNameAlias{sortname}{family-given}

\AtEveryBibitem{ \iffieldequalstr{langid}{magyar} {\DeclareNameAlias{sortname}{given-family}} {\DeclareNameAlias{sortname}{family-given}} }

\begin{document}

\nocite{Smith2022,KovacsKiss2022}

\printbibliography[heading=subbibliography]

\end{document}

output of code

Alan Munn
  • 218,180