5

I am creating a bilingual (main: greek, secondary: english) document with xelatex and polyglossia and I'm using biblatex with biber for the bibliography management. As biblatex is currently setup the bibliography is output in greek which is fine. However, since most of the bibliography is english, the bibliography fields are not hyphenated properly.

If I add autolang=hyphen to the biblatex options, the hyphenation is correct, but the whole entry converts to english which is something I do not want. Is there any way to change language on a per field basis only? For now I have created a simple macro \newcommand{\en}{\selectlanguage{english}} and add \en to the fields I want in english, but this is tiresome and error-prone on a document with way too many references. Is there any way to change the language of the specified fields (title, author, journal, booktitle) but not alter the language of the whole entry?

MWE

\documentclass{book}

% Change these if you want
\newcommand{\MainFont}{Times New Roman}
\newcommand{\SansFont}{Arial}
\newcommand{\MonoFont}{Courier New}

\usepackage{filecontents}

\begin{filecontents}{bibliography.bib}
  @article{anarticle,
    author={Lathrop, J.W.},
    journal={Electron Devices, IRE Transactions on},
    title={Photolithographic fabrication techniques for transistors},
    year={1958},
    month={April},
    volume={5},
    number={2},
    pages={117},
    doi={10.1109/T-ED.1958.14395},
    ISSN={0096-2430},
    langid={english},
    hyphenation={english}
  }
\end{filecontents}

\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{greek}
\setotherlanguage{english}
\usepackage[backend=biber,style=alphabetic,maxcitenames=2]{biblatex}
\setmainfont[Mapping=tex-text,Ligatures={TeX,Common}]{\MainFont}
\setsansfont[Mapping=tex-text,Ligatures={TeX,Common}]{\SansFont}
\setmonofont[Mapping=tex-text,Ligatures={TeX,Common}]{\MonoFont}
\newfontfamily\greekfont[Script=Greek,Mapping=tex-text,Ligatures={Common,TeX}]{\MainFont}
\newfontfamily\greekfontsf[Script=Greek,Mapping=tex-text,Ligatures={Common,TeX}]{\SansFont}
\newfontfamily\greekfonttt[Script=Greek,Mapping=tex-text,Ligatures={Common,TeX}]{\MonoFont}

\addbibresource{bibliography.bib}

\begin{document}

\cite{anarticle}

\printbibliography

\end{document}
  • I think the autolang=hyphen option does exactly this: the bibliography will be in the main language, but hyphenation will respect langid – Alan Munn Aug 11 '15 at 19:42
  • you can try language=autobib,autolang=other or language=autocite,autolang=other you will see a difference. this is also ho to set manually fields. You will not need to set maunually in bbl or bib file: \DeclareFieldFormat{title}{% \iffieldundef{langid} {#1} {\foreignlanguage{\thefield{langid}}{#1}}% } \DeclareListFormat{location}{% \iffieldundef{langid} {#1} {\foreignlanguage{\thefield{langid}}{#1}}% } \DeclareFieldFormat{institution}{% \iffieldundef{langid} {#1} {\foreignlanguage{\thefield{langid}}{#1}}% } – Levan Shoshiashvili Aug 11 '15 at 21:14
  • and to set names and initials \renewcommand*{\mkbibnamefirst}[1]{\foreignlanguage{\thefield{langid}}{\scshape #1}} \renewcommand*{\mkbibnamelast}[1]{\foreignlanguage{\thefield{langid}}{\scshape #1}} but you need to have langid fields in bib file – Levan Shoshiashvili Aug 11 '15 at 21:19
3

The autolang=hyphen option does what you want. Here's your example but I've made the margins deliberately large to show the hyphenation. Because of the very big margins this still results in some bad boxes, but this is to be expected. For comparison, the example without autolang=hyphen is given also. (I also corrected the month field to a numeric field, which is what biblatex prefers.)

\documentclass[draft]{article}
\usepackage[margin=2.8in]{geometry}
% Change these if you want
\newcommand{\MainFont}{Times New Roman}
\newcommand{\SansFont}{Arial}
\newcommand{\MonoFont}{Courier New}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
  @article{anarticle,
    author={Lathrop, J.W.},
    journal={Electron Devices, IRE Transactions on},
    title={Photolithographic fabrication techniques for transistors},
    year={1958},
    month={4},
    volume={5},
    number={2},
    pages={117},
    doi={10.1109/T-ED.1958.14395},
    ISSN={0096-2430},
    langid={english},
    hyphenation={english}
  }
\end{filecontents}

\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{greek}
\setotherlanguage{english}
\usepackage[backend=biber,style=alphabetic,maxcitenames=2,language=auto,autolang=hyphen]{biblatex}
\setmainfont[Mapping=tex-text,Ligatures={TeX,Common}]{\MainFont}
\setsansfont[Mapping=tex-text,Ligatures={TeX,Common}]{\SansFont}
\setmonofont[Mapping=tex-text,Ligatures={TeX,Common}]{\MonoFont}
\newfontfamily\greekfont[Script=Greek,Mapping=tex-text,Ligatures={Common,TeX}]{\MainFont}
\newfontfamily\greekfontsf[Script=Greek,Mapping=tex-text,Ligatures={Common,TeX}]{\SansFont}
\newfontfamily\greekfonttt[Script=Greek,Mapping=tex-text,Ligatures={Common,TeX}]{\MonoFont}

\addbibresource{\jobname.bib}

\begin{document}

\cite{anarticle}

\printbibliography

\end{document}

With the option

output of code

Without the option

output without option specified

  • 1
    This is the correct answer so I'm selecting it. I have found that there was a language switching statement before my bibliography, so it was my fault. I apologize. – spystath Aug 11 '15 at 21:08

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.