Perfect example document (template) for English, Greek and Hebrew (XeLaTeX)

EDIT 2 (23-2-2017): Changed the title and added that the example file in this post specifically works with XeLaTeX.

EDIT 1 (20-2-2017): Due to cfr's request, I have added a file. This is not the original, but a progress file, so to speak, based on cfr's example file. This one works with XeLaTeX:

\documentclass[12pt, a4paper, titlepage]{article}

\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{verbatim}
\usepackage{afterpage}
\usepackage[top=1.00in, bottom=1.00in, left=1.00in, right=1.00in]{geometry}
\usepackage{setspace}

%% for centering section titles
\usepackage[center]{titlesec}

\usepackage{polyglossia}

\setmainlanguage[variant=british]{english}
\setotherlanguage{hebrew}
\setotherlanguage{greek}
\newfontfamily\hebrewfont{SBL Hebrew}
\newfontfamily\greekfont{SBL Greek}

\title{Title}

%%   BEGIN DOCUMENT
\begin{document}
\begin{titlepage}
\maketitle
\thispagestyle{empty}
\end{titlepage}
\pagenumbering{arabic}

\section{First}
\textgreek{αταραξία}. That was in Greek using SBL Greek.

\texthebrew{קֹהֶלֶת}. That was in Hebrew using SBL Hebrew.

\end{document}


OLD ORIGINAL POST:

Perhaps I am foolish in this regard, but I could not---after having tried to figure it out for a long time---manage to get a basic working file with English as the main language and Greek and Hebrew as the ones thrown in every now and then.

First I tried to add Hebrew to my existing working PdfLaTex document (that accepts English and Greek), but this is a very annoying and soul-killing process. Then, since many seem to recommend XeLaTex or LuaLatex, I tried these, but to no avail either (and also a soul-killing process; in fact, do I even have a soul left after all this? Is not the point of technology for the user that it serves him and not the other way around?).

I also followed the instructions in version 5.06 of The Not So Short Introduction to LaTeX 2ε. It is the part on XeLaTeX (starting on p. 34) in section 2.5.8 The Unicode option. Well, it didn't help me at all, even though I followed it.

So will someone please provide a basic working file for PdfLaTeX, XeLaTeX or LuaLaTeX (preferrably the best option) where English is the main language and Greek and Hebrew are the others?

I have installed, by the way, the Hebrew font called SBL Hebrew. For English and Greek I would simply use Computer Modern or something similar.

• Can you please show us the code you tried so that we have a starting point?
– cfr
Feb 19, 2017 at 19:47
• Feb 19, 2017 at 19:59
• @karlkoeller polyglossia/XeTeX is probably the best option here, though, whereas that question is explicitly about how to do it with neither.
– cfr
Feb 19, 2017 at 20:05
• please don't use computer modern for greek. the greek letters in computer modern are designed to be used as math variables, not text. there are now much better alternatives. Feb 20, 2017 at 1:57
• @barbarabeeton Hmm, I think I meant this, that I used the following in my PdfLaTeX file: \usepackage[utf8]{inputenc} \usepackage[LGR,T1]{fontenc} \usepackage[greek,english]{babel} I am no TeX or LaTeX specialist: someone else showed me this and somehow it just gave me the results I needed. The Greek I used (with \textgreek ) looked fine. Feb 20, 2017 at 12:32

Something like this?

\documentclass{article}
\usepackage{polyglossia}
\setmainfont{Noto Serif}
\setsansfont{Noto Sans}
\setmainlanguage[variant=british]{english}
\setotherlanguage{hebrew}
\setotherlanguage{greek}
\newfontfamily\hebrewfont{Noto Sans Hebrew}[Script=Hebrew]
\newfontfamily\greekfont{Noto Serif}
\begin{document}

This is the main language.

\begin{hebrew}
עברית
\end{hebrew}

\begin{greek}
εὐδαιμονία
\end{greek}

\end{document}


Compile with XeLaTeX.

• Note that I have no idea what the Hebrew word(?) is, so I hope it is suitably innocuous.
– cfr
Feb 19, 2017 at 20:06
• I checked your example file. In my own file I had to change the order of certain lines (due to some needing to be loaded before bidi (in polyglossia)). I also changed the fonts to SBL Hebrew and SBL Greek. For now it works. I will add my own file in the first post. Perhaps it can be improved. Feb 20, 2017 at 12:30
• I intended it as an example @Jermain. I don't have the fonts you have, so obviously, I had to change them to ones I do have. And Noto is nice in that it provides fonts designed to work together for a wide variety of scripts, so was an obvious choice.
– cfr
Feb 20, 2017 at 23:25
• @ cfr Indeed. I did not mean to diminish the value of your answer. Perhaps my communication should have been clearer in that. Apologies if it was taken wrongly. Perhaps I should have a look at those fonts you used, now that you say that are intended to work together with a wide variety of scripts. And thanks for the good answer. Feb 21, 2017 at 9:19
• @Jermain Fair enough ;). Noto seems especially popular for screen use. I'm not sure if that is the design intention. But it is worth thinking about fonts which work together so that your document doesn't look like a combination of 2 or 3 differently designed ones :).
– cfr
Feb 21, 2017 at 11:04

Update

babel's BIDI support is coming along nicely, and it's now possible to do this relatively painlessly. babel seems to be being more actively developed than polyglossia, so this is likely to be increasingly the way to go. It also works with both xelatex and lualatex.

\documentclass{article}
\usepackage[nil,bidi=default]{babel}
\babelprovide[import=en-GB,main]{british}
\babelprovide[import=he]{hebrew}
\babelprovide[import=el]{polutonikogreek}
\babelfont[british]{rm}{Latin Modern Roman}
\babelfont[hebrew]{rm}[Contextuals=Alternate]{SBL BibLit}
\babelfont[polutonikogreek]{rm}[Contextuals=Alternate]{SBL BibLit}
\usepackage{parskip}
\pagestyle{empty}
\begin{document}

\textsuperscript{1}In the beginning was the Word, and the Word was with God,
and the Word was God. \textsuperscript{2}He was with God in the beginning.
(John 1:1–2)

\selectlanguage{polutonikogreek}

\textsuperscript{1} Ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν θεόν, καὶ θεὸς
ἦν ὁ λόγος. \textsuperscript{2}Οὗτος ἦν ἐν ἀρχῇ πρὸς τὸν θεόν.
\foreignlanguage{british}{(John 1:1–2)}

\selectlanguage{hebrew}

\textsuperscript{1}בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃
\textsuperscript{2}וְהָאָ֗רֶץ הָיְתָ֥ה תֹ֨הוּ֙ וָבֹ֔הוּ וְחֹ֖שֶׁךְ עַל־פְּנֵ֣י תְהֹ֑ום וְר֣וּחַ אֱלֹהִ֔ים מְרַחֶ֖פֶת
עַל־פְּנֵ֥י הַמָּֽיִם׃ \foreignlanguage{british}{(Genesis 1:1–2)}

\selectlanguage{british}

Inline Greek (\foreignlanguage{polutonikogreek}{Ἐν ἀρχῇ ἦν ὁ λόγος} [John 1:1]) and
Hebrew (\foreignlanguage{hebrew}{בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ} [Genesis
1:1]) also
must work.

\end{document}


Here's a slightly extended example, which also works for lualatex (@cfr's answer will not compile with lualatex — My guess is it ought to, but there are bugs in luabidi.sty).

I've also found problems with \raggedright under xelatex which is worked around in this example (bug in bidi.sty?).

Finally, this shows how to use the SBL BibLit font correctly, specifying the Script and Contextual Alternates needed particularly for Hebrew.

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage[variant=british]{english}
\setotherlanguage{hebrew}
\setotherlanguage[variant=ancient]{greek}
\newfontfamily\greekfont{SBL BibLit}%
[Script=Greek,Contextuals=Alternate,Ligatures=Required]
\newfontfamily\hebrewfont{SBL BibLit}%
[Script=Hebrew,Contextuals=Alternate,Ligatures=Required,Scale=1.2]
\pagestyle{empty}
\ifluatex
\let\luatexpardir\pardir % luabidi needs this
\let\luatextextdir\textdir % luabidi needs this
% text direction gets stuffed up without these workarounds
\let\luatextextgreek\textgreek
\let\luatextextenglish\textenglish
\AtBeginDocument{%
\renewcommand{\textgreek}[1]{\bgroup\textdir TLT\luatextextgreek{#1}\egroup}
\renewcommand{\textenglish}[1]{\bgroup\textdir TLT\luatextextenglish{#1}\egroup}
}
\fi
% \raggedright stuffs up under xelatex
\let\origraggedright\raggedright
\renewcommand{\raggedright}{%
\origraggedright
\ifxetex
\renewenvironment{hebrew}[1][]{%
\par
\raggedleft % add to right align paragraphs
\begin{otherlanguage}[##1]{hebrew}}%
{\end{otherlanguage}\par}%
\fi}
\begin{document}

In the beginning was the Word, and the Word was with God, and the Word was
God. (John 1:1)

\begin{greek}
Ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν θεόν, καὶ θεὸς ἦν ὁ λόγος.
\textenglish{(John 1:1)}
\end{greek}

\begin{hebrew}
בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת הָאָרֶץ. \textenglish{(Genesis 1:1)}
\end{hebrew}

Inline Greek (\textgreek{Ἐν ἀρχῇ}) and Hebrew (\texthebrew{בראשית}) also must
work.

\section*{With \texttt{\textbackslash raggedright}}
\raggedright

In the beginning was the Word, and the Word was with God, and the Word was
God. (John 1:1)

\begin{greek}
Ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν θεόν, καὶ θεὸς ἦν ὁ λόγος.
\textenglish{(John 1:1)}
\end{greek}

\begin{hebrew}
בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת הָאָרֶץ. \textenglish{(Genesis 1:1)}
\end{hebrew}

Inline Greek (\textgreek{Ἐν ἀρχῇ}) and Hebrew (\texthebrew{בראשית}) also must
work.

\end{document}


• It looks very comprehensive. Thanks for the effort you have taken. It is, like with all who have contributed, appreciated. I will try it out soon and let you know how it went on my side. Feb 26, 2017 at 21:26
• @ David Purton: On my old version, it only works with XeLaTeX (pretty fast). On my newer version, it only works with LuaLaTeX (also pretty fast). I thought it shouldn't be a problem, until I had problems with adapting the file to my own needs. The fighting with these kinds of things has cost me too much time now, such that I would probably leave it alone for a while. There should be a superior version or system that "simply works" without having to deal with workarounds, technical issues and the like. On another note, I have added a point to your answer. Feb 27, 2017 at 11:28
• @Jermain, what do you mean by old version and newer version? Things should be very reliable with xelatex and if you don't need \raggedright then you can leave out that work around too. In this case, you are essentially back the answer of @cfr. And this does "simply work" and is the right way of doing things. Feb 27, 2017 at 12:29
• @ David Purton: exactly what I wrote (earlier in responses to cfr). And regarding XeLaTeX, there was still the slowness problem which doesn't seem to be solved elsewhere on this site or it would still require too much tinkering. So I don't see how XeLaTeX just works, for it gives me slowness of compilation which is another problem to deal with. What I meant by a superior system is a superior LaTeX system where one has no need to deal with workarounds (perhaps LaTeX 3). Feb 27, 2017 at 12:55
• I didn't know about the Babel developments: it looks rather nice. (I'm not a great fan of Polyglossia although I cannot really say why.)
– cfr
Feb 17, 2018 at 1:55