# Greek (Unicode) in Org mode export to PDF

I am working on a project that deals with polytonic Greek, and wish to write everything in Org mode, and export to a PDF with one of the compilers (like XeLaTeX).

I have spent hours today reading posts and StackExchange threads about Unicode and Org mode, but feel no closer to solving my problem than when I first started. For example, I have a table like the following in my Org file:

| Greek letter | IPA                      | English match |
|--------------+--------------------------+---------------|
| Α α          | [a], [aː]                | A             |
| Β β          | [b]                      | B             |
| Γ γ          | [g], [ŋ] (before velars) | G             |
| Δ δ          | [d]                      | D             |
| Ε ε          | [e]                      | E             |
| Ζ ζ          | [zd]                     | Z             |
| Η η          | [ɛː]                     |               |
| Θ θ          | [θ]                      |               |
| Ι ι          | [i], [iː]                | I             |
| Κ κ          | [k]                      | K             |
| Λ λ          | [l]                      | L             |
| Μ μ          | [m]                      | M             |
| Ν ν          | [n]                      | N             |
| Ξ ξ          | [ks]                     | X             |
| Ο ο          | [o]                      | O             |
| Π π          | [p]                      | P             |
| Ρ ρ          | [r]                      | R             |
| Σ σ          | [s]                      | S             |
| Τ τ          | [t]                      | T             |
| Υ υ          | [y], [yː]                | U             |
| Φ φ          | [f]                      | F             |
| Χ χ          | [kʰ]                     |               |
| Ψ ψ          | [ps]                     |               |
| Ω ω          | [ɔː]                     |               |


And these lines in my .spacemacs file (evidently XeLaTeX supports Unicode better than PDFLaTeX?):

;; Use XeLaTeX
(setq org-latex-pdf-process
'("xelatex -interaction nonstopmode -output-directory %o %f"
"xelatex -interaction nonstopmode -output-directory %o %f")) ;; for multiple passes


I have been unable to get any of the Greek characters in the table to show up in the PDF when I use C-C C-e l p. I am not getting any build errors: the intermediate .tex file is produced and looks absolutely fine. It's just that when the PDF is produced, it doesn't have any of the Unicode characters I want. I am at a complete loss as to what I need to do, what packages I need to install, and so forth.

I'd like to get a handle on how to include Unicode symbols in general as I'll probably need to use IPA symbols and Hebrew letters as well in this project. But I'd be happy to get even just basic Greek letters working at this point.

Help?

• Do you have #+latex_header: \usepackage[utf8]{inputenc} in your Org file? Is org file itself encoded using some Unicode coding? (does Emacs show U in the bottom left corner of the buffer?) (but don't mix the two). With XeLaTeX you need to specify fonts you want for languages and then use the font you defined: pokristensson.com/unicodelatex.html May 27, 2018 at 5:54
• Just to try to expand on this: PDF embeds fonts in the document using a structure it calls font table, so your goal would be to make it embed the fonts that you need and also to make it understand that some characters map to those tables. It may easily be the case that the font you are using to render your document in PDF simply doesn't have Greek characters, so check that too. May 27, 2018 at 6:03
• \usepackage[utf8]{inputenc} is used by default in the Org mode export to .tex. Here's the relevant header info in the .tex file produced:  \documentclass[11pt]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{graphicx} \usepackage{grffile} \usepackage{longtable} \usepackage{wrapfig} \usepackage{rotating} \usepackage[normalem]{ulem} \usepackage{amsmath} \usepackage{textcomp} \usepackage{amssymb} \usepackage{capt-of} \usepackage{hyperref}  There is no U in the bottom left corner. I have unix in the bottom right of the Spacemacs modeline? May 28, 2018 at 15:05
• As to the fonts: could you point me to some place that explains this mapping clearly (particularly how you do it)? Would I change \usepackage[T1]{fontenc} to something different? How would I say "use this font for English stuff and this font for Greek stuff?" May 28, 2018 at 15:10
• Oh... it's Spacemacs, I don't know what it shows in its modeline. But you might be able to get this information from M-: buffer-file-coding-system (it should be utf-8). May 29, 2018 at 9:24

I figured out a basic implementation but am still interested to hear other people's takes.

Assuming you are using XeLaTeX and have fontspec, polyglossia, and bidi (for right to left language support, if you need it), you can use the default Org mode export variables (without messing with them in your config file) as long as you add some additional file-specific configuration when you'll need Greek, Hebrew, and Unicode. For example:

#+LaTeX_HEADER: \usepackage{fontspec}



You could use a different main font than Cardo (I'm using it because it has Greek and IPA support out of the box, and has bold and italic faces for most Roman glyphs, unlike, say, Gentium Plus), and a different Hebrew font than SBL too. Cardo has the Hebrew block, but I found the diacritics to be more finnicky than SBL Hebrew's implementation.

Usage is pretty simple. Greek works just like normal text, but Hebrew requires some wrapping:

Here is some inline Hebrew (Genesis 1:1) \texthebrew{בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ} with English around it. And now a longer chunk: \\

\begin{hebrew}
‏ בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ ‎2‏ וְהָאָ֗רֶץ הָיְתָ֥ה תֹ֨הוּ֙ וָבֹ֔הוּ וְחֹ֖שֶׁךְ עַל־פְּנֵ֣י תְה֑וֹם וְר֣וּחַ אֱלֹהִ֔ים מְרַחֶ֖פֶת עַל־פְּנֵ֥י הַמָּֽיִם׃ ‎3‏ וַיֹּ֥אמֶר אֱלֹהִ֖ים יְהִ֣י א֑וֹר וַֽיְהִי־אֽוֹר׃ ‎4‏ וַיַּ֧רְא אֱלֹהִ֛ים אֶת־הָא֖וֹר כִּי־ט֑וֹב וַיַּבְדֵּ֣ל אֱלֹהִ֔ים בֵּ֥ין הָא֖וֹר וּבֵ֥ין הַחֹֽשֶׁךְ׃ ‎5‏ וַיִּקְרָ֨א אֱלֹהִ֤ים ׀ לָאוֹר֙ י֔וֹם וְלַחֹ֖שֶׁךְ קָ֣רָא לָ֑יְלָה וַֽיְהִי־עֶ֥רֶב וַֽיְהִי־בֹ֖קֶר י֥וֹם אֶחָֽד׃ פ ‎6‏ וַיֹּ֣אמֶר אֱלֹהִ֔ים יְהִ֥י רָקִ֖יעַ בְּת֣וֹךְ הַמָּ֑יִם וִיהִ֣י מַבְדִּ֔יל בֵּ֥ין מַ֖יִם לָמָֽיִם׃
\end{hebrew}\newline

And here is some inline Greek from the /Iliad/ μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος with English around it. And now a longer chunk: \\

μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος οὐλομένην, ἣ μυρί᾽ Ἀχαιοῖς ἄλγε᾽ ἔθηκε, πολλὰς δ᾽ ἰφθίμους ψυχὰς Ἄϊδι προΐαψεν ἡρώων, αὐτοὺς δὲ ἑλώρια τεῦχε κύνεσσιν οἰωνοῖσί τε πᾶσι, Διὸς δ᾽ ἐτελείετο βουλή, ἐξ οὗ δὴ τὰ πρῶτα διαστήτην ἐρίσαντε Ἀτρεΐδης τε ἄναξ ἀνδρῶν καὶ δῖος Ἀχιλλεύς. τίς τ᾽ ἄρ σφωε θεῶν ἔριδι ξυνέηκε μάχεσθαι;


People that don't need right to left support for languages like Arabic and Hebrew and don't want to use a font like Cardo that has a lot of the Unicode ranges covered (e.g., extended Greek, Hebrew, Cyrillic, etc.) can set up transparent font-switching with the XeLaTeX package ucharclass. The documentation is pretty good, but if you want an example, here is a blog post about one possible setup with CJK, Greek, and regular Latin text.

I decided not to use this since I needed right to left support, and ucharclass doesn't play nice with polyglossia. However, since ucharclass automatically handles script switching (without any wrapping needed), it will work well for everyone that doesn't need RTL. You can choose custom fonts for many different Unicode blocks.

• I’ve found that this works (for Greek characters, at least) with just your first two header lines, so long as org-latex-compiler is set to "lualatex" (and the Cardo font is installed, of course). But is there any way to make this just work, without adding special header lines to every Org document? (I feel like “change the default font for PDF export” should be a matter of changing an option somewhere, but I can’t flaming find such a thing…) Feb 27, 2021 at 1:38

With respect to getting "a handle on how to include Unicode symbols in general"... one approach that might be of value to anyone stumbling upon this question:

• use Unicode characters directly (C-x 8 [Enter] if necessary) in the source (org) file

• ensure font(s) which have the characters of interest are installed (fc-list can be helpful)

• in the document header, explicitly specify the font(s) that actually have the characters of interest; for example:

#+LaTeX_HEADER: \usepackage{xltxtra} \usepackage{fontspec} \setmainfont{Linux Libertine O} \setsansfont{DejaVu Sans} \setmonofont{DejaVu Sans Mono}

• generate the corresponding tex file (org-latex-export-to-latex)

• compile it with xelatex (XeTeX is designed to handle Unicode)

One minimalist set of directive to get greek unicode text properly exported to pdf :

#+latex_compiler: xelatex