1

Since hyphenation will work differently for different languages, I need to include information in my .bib file about the language of certain entries (e.g. title, author, publisher), if they are not in the main language. This seems to work fine when including e.g. {\begin{otherlanguage}{french} ... \end{otherlanguage}} inside an entry (the opening and closing curly braces are needed), cf. the following MWE.

\documentclass{article}
\usepackage{polyglossia}
    \setdefaultlanguage[variant = american]{english}
    \setotherlanguage{french}
    \setotherlanguage[variant = german]{german}

\usepackage[style = authoryear-comp]{biblatex}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}

@BOOK{smith1968,
    AUTHOR = "John Smith",
    TITLE = "Jackknife juggernaut",
    YEAR = "1968",
    PUBLISHER = "Oxford University Press"}

@BOOK{quenneville1975,
    AUTHOR = "{\begin{otherlanguage}{french}Dominic Quenneville\end{otherlanguage}}",
    TITLE = "Subterranean homesick",
    YEAR = "1975",
    PUBLISHER = "{\begin{otherlanguage}{german}Der beste Verlag Deutschlands\end{otherlanguage}}"}

\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}
\parbox{0pt}{\hspace{0pt}\printbibliography}
\end{document}

enter image description here

But sometimes everything within the reference will be in another language, and it seems tedious to put {\begin{otherlanguage}{...} ... \end{otherlanguage}} inside every line of this reference. But I haven't been able to find a way to specify the language of the whole reference (the following MWE, for example, will disregard the {otherlanguage} environment around the paul1920 reference as "junk"). How can I do this?

\documentclass{article}
\usepackage{polyglossia}
    \setdefaultlanguage[variant = american]{english}
    \setotherlanguage{french}
    \setotherlanguage[variant = german]{german}

\usepackage[style = authoryear-comp]{biblatex}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}

\begin{otherlanguage}{german}
@BOOK{paul1920,
    AUTHOR = "Hermann Paul",
    TITLE = "Prinzipien der Sprachgeschichte",
    YEAR = "1920",
    EDITION = "5",
    LOCATION = "Halle a.\@ S.",
    PUBLISHER = "Max Niemeyer"}
\end{otherlanguage}

@BOOK{quenneville1975,
    AUTHOR = "{\begin{otherlanguage}{french}Dominic Quenneville\end{otherlanguage}}",
    TITLE = "Subterranean homesick",
    YEAR = "1975",
    PUBLISHER = "{\begin{otherlanguage}{german}Der beste Verlag Deutschlands\end{otherlanguage}}"}

\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}
\parbox{0pt}{\hspace{0pt}\printbibliography}
\end{document}
  • Have a look at tex.stackexchange.com/q/444016/35864 (see also github.com/plk/biblatex/issues/895). – moewe Jun 1 at 16:02
  • @moewe But isn't your first suggestion in that answer ("Wrap the entire entry in the otherlanguage environment") precisely what I'm unsuccessful in accomplishing here? – Sverre Jun 1 at 16:05
  • But then there is option 2 and the answer goes on to implement option 2... – moewe Jun 1 at 16:06
  • @moewe Right, but you seem to be saying that option 1 will work too. How? Regarding option 2, if I understand it correctly, (also per this question), wouldn't it be sufficient in my case to simply add a langid entry in my reference? EDIT: No, adding langid = "german" did not work - it still won't hyphenate "Sprachgeschichte". – Sverre Jun 1 at 16:11
3

While biblatex has a good reputation for supporting multi-language typesetting, there are a few things that are not implemented at the moment. In particular there is no per-field language switching, you can only switch the language of the entire entry, and even that may have some undesirable side-effects (see below).

Language markup in fields

One of the simplest idea to switch languages for specific fields is probably to add (polyglossia or babel) language switching commands to the respective fields directly. For example

title = {\foreignlanguage{german}{Prinzipien der Sprachgeschichte}},

This works for many fields and is a quick solution, but it comes with some caveats

  • The language switching markup may mess up sorting. Biber strips some macros before sorting, but since it does not parse TeX (and does not know the definition of all macros), the example would be sorted under g and not under P.
  • The switching markup can get messed up in or block field parsing. This becomes apparent in name fields.

    author = {\begin{otherlanguage}{french}Dominic Quenneville\end{otherlanguage}},
    

    Will fail completely, because Biber (and BibTeX) parse this as a name whose given component is \begin{otherlanguage}{french}Dominic and whose family component is Quenneville\end{otherlanguage}. biblatex needs to be able to process these name parts independently of each other. But when the name parts are processed independently, the environments are unmatched leading to fatal errors.

    So we would need to add a pair of additional braces to stop the name parsing (similar to Using a 'corporate author' in the "author" field of a bibliographic entry (spelling out the name in full))

    author = {{\begin{otherlanguage}{french}Dominic Quenneville\end{otherlanguage}}},
    

    Now the name is interpreted as consisting solely of the family part {\begin{otherlanguage}{french}Dominic\bibnamedelimb Quenneville\end{otherlanguage}}. This means that again the sorting will be off and that the name formats will not work as one would expect. In particular the name will always show as "Dominic Quenneville" even if the name would normally be reversed ("Quenneville, Dominic") or only show the family name ("Quenneville"). Options like giveninits will not work as expected, \mkbibnamefamily and \mkbibnamegiven will not have the desired effect.

So this method is only applicable for simple literal fields whose value should not matter for sorting. In general I would probably advise against it.

langid & autolang

This langid field should be the answer to your use case paul1920. As explained in How does langid field in biblatex differ from language field? and elsewhere, this field can be used to switch the language of a complete entry.

With the default settings the field does not have any effect, however. You need to set the option autolang to a value other than (the default) none. You'd probably be interested in autolang=hyphen. (Note that the option langid should be set to autobib (the default), autocite or auto if you want biblatex to pick up the language from the langid field. Setting language to a language name will override all langid field with that explicit values.) Then the entire entry is wrapped in \begin{hyphenrules}{<langid>}...\end{hyphenrules}, which means that the entry is hyphenated according to the rules of <langid>.

\documentclass{article}
\usepackage{polyglossia}
  \setdefaultlanguage[variant = american]{english}
  \setotherlanguage[variant = german]{german}

\usepackage[style = authoryear-comp, autolang=hyphen]{biblatex}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{paul1920,
  author    = {Hermann Paul},
  title     = {Prinzipien der Sprachgeschichte},
  year      = {1920},
  edition   = {5},
  location  = {Halle a.~S.},
  publisher = {Max Niemeyer},
  langid    = {german},
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\parbox{0pt}{\hspace{0pt}\printbibliography}
\end{document}

Entry hyphenated according to German rules

If you set autolang=other, the entry will be wrapped in \begin{otherlanguage}{<langid>}...\end{otherlanguage}, which means that not only will hyphenation be according to <langid>, the bibstrings will also be in <langid>, so in the example above you will not see "5th. ed.", you'll see "5. Aufl.".

Same as above (we only see an excerpt) but this time we have "5. Aufl." instead of "5th ed."

This highlights one issue with autolang=hyphen. The entire entry will be hyphenated according to the rules of <langid>, this does the right thing for field contents, which are in <langid>, but the bibstrings are in the main document language (which may or may not be equal to <langid>). In the example above "edition" would have been hyphenated according to German rules. This could be problematic.

Adding \begin{otherlanguage}{german}...\end{otherlanguage} to the .bib file outside of an entry will do nothing. Text outside of entries is ignored (silently by BibTeX and with a warning by Biber).

But I need something else

Unfortunately, this is all biblatex offers at the moment.

You can't have per-field language switching with possibly different languages per entry (see https://github.com/plk/biblatex/issues/895).

It is sort of possible, but quite tricky, to switch only the field contents to <langid> leaving the rest (bibstrings, punctuation) in the main document language (this works around the issues mentioned with autolang=hyphen above). See Change language on a per field basis, part 2: Fonts, case transformation and sorting, note that the implementation has some drawbacks, it does for example not work with \MakeSentenceCase.

Unfortunately, the implementation of a more sophisticated language switching mechanism looks quite complicated...

polyglossia

I should mention that biblatex's polyglossia support is not great. biblatex can't detect polyglossia's language variants and thus fails to produce the expected date format for british or austrian (or australian). See for example \DeclareLanguageMappingSuffix, inheritance, and polyglossia in biblatex.

It should also be mentioned that the preferred way to switch languages according to the polyglossia documentation seems to be \text<language>{...} for a few words and \begin{<language>}...\end{<language>} for longer passages in <language>. \foreignlanguage{<language>}{...} and \begin{otherlanguage}{<language>}...\end{otherlanguage} are still supported, but only mentioned under Other commands.

  • Thanks for the detailed explanation. It seems like the best solutions are: (a) Use \begin{otherlanguage} (or equivalent commands) when parts of a reference are in another language, and said parts aren't sorted anyway (e.g. titles, names of publishers). (b) Use autolang=hyphen + langid when the whole reference is in another language. If (b) causes e.g. a German hyphenation of an English word like "edition", it should be possible to manually fix this by adding a hyphenation rule for the word "edition" under \begin{hyphenrules}{german}, right? – Sverre Jun 2 at 13:47
  • @Sverre Titles are often used for sorting (if only as secondary or tertiary fields, so often they do not matter a great deal) and publisher is a list field, so one would have to be careful again with braces and the word and. Since the bibliography is automatically generated fixing things manually is tricky. I'm not sure if there is a way to locally add hyphenation exceptions. You could redefine the bibstring to include explicit \-s at the allowed break points, that would probably be the most robust workaround. – moewe Jun 2 at 14:00
  • I'm close to concluding that the only way to accomplish what I want is to add \- in the .bib file manually. I have a Danish reference, so I added autolang=hyphen + langid=danish. It hyphenated the name of the capital as "Kø-benhavn", which I don't like, so I added \begin{hyphenrules}{danish}\hyphenation{Køben-havn}\end{hyphenrules} to my list of manual hyphenation corrections. This didn't change anything - but when adding \hyphenation{Køben-havn} under the hyphenrules of the main language of the document, it works. – Sverre Jun 2 at 14:13
  • biber apparently will only accept manual hyphenation rules for the main language, and it will use those even when the entry has a langid for another language. – Sverre Jun 2 at 14:13
  • 1
    @Sverre Yes, if one has langid fields and wants to use them setting the language option to anything other than autobib, autocite or auto kind of defeats the purpose of langid. In general language=<language name>, is rarely what people want. – moewe Jun 2 at 15:58

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.