6

following up on THIS QUESTION, I want to embed the solution in a document (Beamer presentation) I compile (in English) with LuaLaTeX, but I just don't find the way. I just want to include a slide with text in different languages and the code for teaching purposes, but it is the first time I try to write something in a non-latin alphabet... But my document needs LuaLaTeX (and I actually like it!).

Additionally, if someone knows how to include text in a couple of other non-latin alphabets as well, like Arabic and Thai, it would be much appreciated.

So this it the code I want to embed in my document compiled with LuaLaTeX:

\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1,T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian, english]{babel}% note - it is recommended to specify the variant of English required to avoid unexpected divergence depending on the version of babel e.g. american or british
\usepackage[encapsulated]{CJK}
\usepackage{setspace}
\doublespacing
\usepackage{natbib}
\begin{document}
\selectlanguage{russian}
слово

\begin{CJK}{UTF8}{gbsn}
你好
\end{CJK}

\selectlanguage{english}
Here is some text in English.

\selectlanguage{russian}
слово

\end{document}
DaniCee
  • 2,217
  • 1
    You'll need fontspec commands to select appropriate fonts, unless you have one that covers all these alphabets. – musarithmia Jun 15 '15 at 01:24
  • How can I do that? Which would be the required fonts, and where to get them for Ubuntu? Thanks! – DaniCee Jun 15 '15 at 01:47
  • 2
    Don't load inputenc or fontenc if you are compiling with LuaTeX. (In some cases, you can use fontenc but generally not. You definitely don't want inputenc ever here.) – cfr Jun 15 '15 at 02:12
  • I suspect you ought not load CJK either but I'm not entirely sure. Also if it supports the languages you need, consider polyglossia as a replacement for babel with this engine. – cfr Jun 15 '15 at 02:14
  • 1
    Which solution are you referring to? At least 3 different solutions are mentioned there, none involving LuaTeX. One uses the encapsulated option of CJK. One uses the CJKutf8 package. A third uses XeTeX (and is linked rather than given directly). The first two solutions are for (pdf)TeX - not XeTeX or LuaTeX. XeTeX or LuaTeX should be much easier here but you need to do a little bit of work to set your document up appropriately i.e. a bit of reading so that you understand the basics of switching engines. texdoc fontspec is a great resource. – cfr Jun 15 '15 at 02:22
  • If "embed the solution" means that you want to show the exact code e.g. with listings then check http://tex.stackexchange.com/questions/25391/the-listings-package-and-utf-8/25396#25396 – Ulrike Fischer Jun 15 '15 at 07:25

1 Answers1

6

Here I demonstrate only how to use fontspec to select many different fonts for different languages in one document. I use a main font that already covers a wide Unicode range, and then select other fonts as appropriate. I used fonts either available in TeXLive or freely available elsewhere. Compile with lualatex.

Note that for Hebrew and Arabic you have to use \luatextexdir TRT to set the right-to-left text direction, and with Arabic you need [Script=Arabic]. See the fontspec package documentation and other questions on these sites about these languages for more information.

I don't know all these languages, so I have likely gotten some things wrong, and I hope others will correct me.

To this you can add using babel or polyglossia for hyphenation patterns specific to each language, but I leave this up to someone else to demonstrate. With only short excerpts of different languages, that may be overkill anyway.

\documentclass{article}
\usepackage{url} % just to format urls 
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
% Libertine covers Latin, Hebrew, Greek, and Russian

\newfontfamily{\hebrewfont}{Linux Libertine O} 
\newcommand{\texthebrew}[1]{%
    \bgroup\luatextextdir TRT\hebrewfont #1\egroup%
}

\newfontfamily{\chinesefont}{IPAMincho} % in TeXLive
\newcommand{\textchinese}[1]{\bgroup\chinesefont #1\egroup}

\newfontfamily{\arabicfont}[Script=Arabic]{Droid Arabic Naskh} % free with Debian GNU/Linux
\newcommand{\textarabic}[1]{%
     \bgroup\luatextextdir TRT\arabicfont #1\egroup%
}

\newfontfamily{\thaifont}{Norasi} % free with Debian
\newcommand{\textthai}[1]{\bgroup\thaifont #1\egroup}

\begin{document}
\section*{The Tower of Babel, Genesis 11:7}

\subsection*{English}
Come, let us go down and confuse their language so they will not understand each other. 

\subsection*{Hebrew}
\texthebrew{%
הָ֚בָה נֵֽרְדָ֔ה וְנָבְלָ֥ה שָׁ֖ם שְׂפָתָ֑ם אֲשֶׁר֙ לֹ֣א יִשְׁמְע֔וּ אִ֖ישׁ שְׂפַ֥ת רֵעֵֽהוּ׃%
}

\subsection*{Greek}
δεῦτε καὶ καταβάντες συγχέωμεν ἐκεῖ αὐτῶν τὴν γλῶσσαν, ἵνα μὴ ἀκούσωσιν ἕκαστος τὴν φωνὴν τοῦ πλησίον.

\subsection*{Latin}
venite igitur descendamus et confundamus ibi linguam eorum ut non audiat unusquisque vocem proximi sui

\subsection*{Spanish}
Será mejor que bajemos a confundir su idioma, para que ya no se entiendan entre ellos mismos.

\subsection*{Russian}
сойдем же и смешаем там язык их, так чтобы один не понимал речи другого.

\subsection*{Chinese (Simplified)}
\textchinese{%
来,我们下去,在那里混乱他们的语言,使他们听不懂对方的话。%
}

\subsection*{Thai}
\textthai{%
มาเถิด ให้เราลงไปทำให้เขามีภาษาสับสนแตกต่างกันออกไป เพื่อเขาจะได้ไม่เข้าใจกัน%
}

\subsection*{Arabic}
\textarabic{%
هَيَّا نَنْزِلْ إِلَيْهِمْ وَنُبَلْبِلْ لِسَانَهُمْ، حَتَّى لَا يَفْهَمَ بَعْضُهُمْ كَلامَ بَعْضٍ.%
}

\bigskip
\small
Texts from \url{https://www.biblegateway.com}.
Greek Septuagint text from \url{https://www.academic-bible.com/en/online-bibles/septuagint-lxx/read-the-bible-text/}.


\end{document}

enter image description here

musarithmia
  • 12,463
  • The Arabic isn’t right (no bidi). You’ll need \newfontfamily\arabicfont[Script=Arabic]{Droid Arabic Naskh}, though that won’t suffice. In the case of Arabic, xetex makes life easier than luatex, though I use luatex for everything else. Haven’t yet had time to update to TeX Live 2015, but when I do I’ll revisit this question if the situation has changed. – Thérèse Jun 16 '15 at 15:14
  • Closer. The letters are joined where they should be now, but the text is backward. (Don’t feel bad: some of my colleagues were proudly displaying an Arabic book upside-down until I pointed it out..) – Thérèse Jun 16 '15 at 19:48
  • @Thérèse How about now? – musarithmia Jun 16 '15 at 20:15
  • 1
    Excellent. You’ve unconfused our language. – Thérèse Jun 16 '15 at 20:19
  • Thank you so much, this is amazing!! I'm just having trouble with the Chinese, cause the IPAMincho font cannot be found... which TeX Live package contains it?? – DaniCee Jun 18 '15 at 01:49
  • I have installed "texlive-lang-cjk", "fonts-ipafont", "fonts-ipafont-mincho", "fonts-ipafont-nonfree-jisx0208", and "fonts-ipamj-mincho", and I still get ! fontspec error: "font-not-found"! The font "IPAMincho" cannot be found. – DaniCee Jun 18 '15 at 02:00
  • Anyone knows how to get the IPAMincho font please??? – DaniCee Jun 18 '15 at 09:27
  • When I say TeXLive, I mean a full installation of the TeX distribution put together by the TeX Users' Group at www.tug.org. It sounds like you are using the Debian/ Ubuntu package, which is also called "texlive", but is not quite the same thing. There are many questions here about installing TeX on Linux which might help. – musarithmia Jun 18 '15 at 14:32
  • If you installed texlive-lang-cjk, I think you should have it. search for thr font name in the terminal with this command: fc-list | grep Mincho – musarithmia Jun 18 '15 at 14:34
  • "/usr/share/fonts/opentype/ipafont-mincho/ipam.ttf: IPAMincho,IPA明朝:style=Regular" appears in the output of "fc-list | grep Mincho", but the error persists... – DaniCee Jun 18 '15 at 14:36
  • My guess is you need to update your luaotfload database so that luatex knows about this system font. Try this: luaotfload-tool --update --force – musarithmia Jun 18 '15 at 14:40
  • I followed these instructions (http://tex.stackexchange.com/questions/204145/some-fonts-not-recognized-by-lualatex/204438#204438) and it works now!! – DaniCee Jun 19 '15 at 07:29
  • Sorry to refloat this, but I upgraded my system from Ubuntu 14.04 to 16.04, and texlive from 2013 to 2015; Now Arabic and Hebrew text do not seem to work anymore, and I posted a question to revise this answer, if you can have a look at it: http://tex.stackexchange.com/questions/326976/revision-on-chinese-russian-and-english-and-arabic-and-thai-if-possible-in – DaniCee Aug 29 '16 at 09:40
  • I solved it, in case anyone is interested! – DaniCee Aug 30 '16 at 06:31