3

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 – wvxvw May 27 '18 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. – wvxvw May 27 '18 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? – Steven Tammen May 28 '18 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?" – Steven Tammen May 28 '18 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). – wvxvw May 29 '18 at 9:24
2

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}
#+LaTeX_HEADER: \setmainfont[BoldFont={Cardo Bold}, ItalicFont={Cardo Italic}]{Cardo}

#+LaTeX_HEADER: \usepackage{polyglossia}
#+LaTeX_HEADER: \setmainlanguage{english}
#+LaTeX_HEADER: \setotherlanguage{hebrew}
#+LaTeX_HEADER: \newfontfamily\hebrewfont{SBL Hebrew}

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.

0

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)

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.