3

I cannot figure out how babel works for truely multilingual texts. Need at least the following, of which so far German, English, Russian and Greek seem to work, while Korean, Chinese and Arabic do not. I am running XeLaTeX.

\documentclass[a4paper, twoside, ngerman]{book}

\usepackage{fontspec}
\setromanfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}

\newfontfamily\arabicfont[Script=Arabic]{Arial Unicode MS}
\newcommand\textarabic[1]{{\arabicfont #1}}
\newfontfamily\koreanfont{UnGungseo}
\newcommand\textkorean[1]{{\koreanfont #1}}

\newfontfamily\chinesefont{FandolSong}
\newcommand\textchinese[1]{{\chinesefont #1}}

\usepackage[bidi=default]{babel}
    \babelprovide[main, import=de]{ngerman}
    \babelprovide[import]{russian}
    \babelprovide[import]{korean}
    \babelprovide[import]{chinese-traditional}
    \babelprovide[import]{arabic}
    \babelprovide[import]{greek}

\begin{document}
    deutsch \foreignlanguage{russian}{Видео урок по живописи маслом} deutsch \textkorean{미술부화실} deutsch
    \textchinese{墨子} deutsch deutsch \foreignlanguage{greek}{πόλεις} deutsch \textarabic{أبو علي الحسن بن الهيثم} deutsch
\end{document} 

  • Let babel set up and switch the fonts with \babelfont. You may also want \babeltags. See the manual for details. Also, if there is an ldf file, which is loaded as class or package option, use it, except if for some reason you don't like it. As you are with XeTeX, consider bidi=bidi-l instead of `bidi=default', but this depends largely on the document contents. – Javier Bezos Oct 25 '19 at 16:43

2 Answers2

3

Here is how to do it, with some explanations:

\documentclass[a4paper, twoside, russian, ngerman]{book}

% As there is very good support for both Russian and German with 'ldf'
% files, load them as class options. The last one is the main language.

\usepackage[bidi=default]{babel}

% Depending on the contents you may prefer bidi=bidi-l.

% Now the rest of languages. It is worth noting that 'import' is
% not always required if you need neither captions nor dates, just
% short texts.

\babelprovide[import]{korean}
\babelprovide[import]{chinese-traditional}
\babelprovide[import]{arabic}
\babelprovide[import]{greek}

% Set fonts up. As CMU Serif contains Greek letters, there is no need
% for an explicit setting. 

\babelfont{rm}{CMU Serif}

\babelfont[arabic]{rm}{Arial Unicode MS}
\babelfont[korean]{rm}{UnGungseo}
\babelfont[chinese-traditional]{rm}{FandolSong}

\babelfont{sf}{CMU Sans Serif}

\babelfont{tt}{CMU Typewriter Text}

% Create language macros: \textkorean, \textchinese, \textarab. Note
% I'm not using 'arabic' but 'arab' because \babeltags tries to define
% \arabic, which is already defined. This should be fixed somehow in
% babel.

\babeltags{
  korean=korean,
  chinese=chinese-traditional,
  arab=arabic} 

\begin{document}

    deutsch \foreignlanguage{russian}{Видео урок по живописи маслом} deutsch \textkorean{미술부화실} deutsch 
    \textchinese{墨子} deutsch \textarab{أبو علي الحسن بن الهيثم} deutsch \foreignlanguage{greek}{πόλεις} deutsch

\end{document} 
Javier Bezos
  • 10,003
1

IMHO you need to load other fonts and then locally switch font. I based my answer below on Typesetting arabic with LuaLaTeX (arabic), How to use Chinese with lualatex? (chinese) and Korean Characters Not Working (Korean). Compile with lualatex

\documentclass[a4paper, twoside, ngerman]{book}

\usepackage{fontspec}
\setromanfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}

\newfontfamily\arabicfont[Script=Arabic]{Arial Unicode MS}
\newcommand{\textarabic}[1]     % Arabic inside LTR
    {\foreignlanguage{arabic}{{\arabicfont #1}}}

\newfontfamily\koreanfont{UnGungseo}
\newcommand\textkorean[1]{{\koreanfont #1}}

\newfontfamily\chinesefont{FandolSong}
\newcommand\textchinese[1]{{\chinesefont #1}}

\usepackage[bidi=default]{babel}
    \babelprovide[main, import=de]{ngerman}
    \babelprovide[import]{russian}
    \babelprovide[import]{korean}
    \babelprovide[import]{chinese-traditional}
    \babelprovide[import]{arabic}
    \babelprovide[import]{greek}

\begin{document}
    deutsch \foreignlanguage{russian}{Видео урок по живописи маслом} deutsch \textkorean{미술부화실} deutsch 
    \textchinese{墨子} deutsch \textarabic{أبو علي الحسن بن الهيثم} deutsch \foreignlanguage{greek}{πόλεις} deutsch
\end{document} 
ebcontrol
  • 564
  • ! Undefined control sequence. \bgroup \textdir TRT\arabicfont أبو علي الحسن بن الهيثم\egroup l.28 ...utsch \textarabic{أبو علي الحسن بن الهيثم} deutsch \foreignlanguage{...

    ? X No pages of output. Transcript written on mwe.log.


    XeLaTeX Compilation Report (Pages: 0)

    Errors: 1 Warnings: 0 Bad Boxes: 0

    – Erik Itter Oct 25 '19 at 11:48
  • can you try to replace "\bgroup\textdir TRT\arabicfont #1\egroup" by "\arabicfont #1" – ebcontrol Oct 25 '19 at 12:11
  • the code edited does the characters, but I am pretty sure Arabic is not right-to-left. I am also a bit irritated because of the multiple direct fontspec calls. From the babel documentation I get the impression this should look different – Erik Itter Oct 25 '19 at 12:35
  • looks good, just the doubts about the direct fontspec calls, but works, so thx. – Erik Itter Oct 25 '19 at 12:47
  • I removed the text direction part, see my edit. – ebcontrol Oct 25 '19 at 12:52
  • maybe also you should try polyglossia instead of babel – ebcontrol Oct 25 '19 at 12:56
  • 1
    @ErikItter If you have current babel, doing it this way probably isn't the best idea, as you say. Use of Script etc. is positively discouraged. – cfr Oct 25 '19 at 13:00
  • @ebcontrol Polyglossia is deprecated, isn't it? – cfr Oct 25 '19 at 13:00
  • Note that use of foreignlanguage can be problematic as it only changes some things. For the odd word, that's probably what you want. For chunks, it probably isn't. – cfr Oct 25 '19 at 13:01
  • @cfr I am starting the next book right now and would love to do it best practise. Any chance you could correct the mwe to the proper babel use? – Erik Itter Oct 25 '19 at 14:19
  • @ErikItter Let's see if somebody else answers first. I'm not the best person for this. I do some bilingual typesetting, but the second language has minimal out-of-the-box support, uses a Latin script and works with pdfTeX. Somebody familiar with more complex scenarios will likely give you a better basis. (I know the \foreignlanguage thing for this reason, but I'm sure there's more to think about with Cyrillic scripts, say, and right-to-left typesetting.) I can't quite figure out if babel is yet up to speed or if polyglossia might be better for Arabic, even though the package is deprecated. – cfr Oct 25 '19 at 14:52