18

Hello Good people of Emacs!

I'm having trouble exporting unicode math symbols from buffer (org-mode) to pdf file.

1. Problem Description:

Symbols are inserted to the buffer as unicode characters (via TEX input method or company-math)

Here is source code demonstration:

#+TITLE: Unicode characters export test 
#+AUThor: 
#+date:
Unicode characters:

ℝ ℤ ℕ ⇒ ∈ ∀ 

Same symbols in latex format:

$$\Bbb{R} \Bbb{Z} \Bbb{N} \Rightarrow \in \forall$$

Produced .tex file includes unicode symbols:

% Created 2016-03-04 Pá 21:01
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\date{}
\title{Unicode characters export test}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs 24.4.1 (Org mode 8.2.10)}}
\begin{document}

\maketitle
\tableofcontents

Unicode characters:

ℝ ℤ ℕ ⇒ ∈ ∀ 

Same symbols in latex format:

$$\Bbb{R} \Bbb{Z} \Bbb{N} \Rightarrow \in \forall$$
% Emacs 24.4.1 (Org mode 8.2.10)
\end{document}

Pdf file does not :

enter image description here

2. Things I have tried so far:

Xelatex and unicode-math: This is included in answer from Rasmus. Here I have to admit: I'm not using development version of org-mode he's mentioning. (failed to install it) I've tried xelatex adn unicode-math anyway. My version of Org mode is 8.2.10.

#+latex_compiler: xelatex
#+latex_header: \usepackage{libertine}
#+latex_header: \usepackage{unicode-math}

Including this in file introduces not so lovely message instead pdf file.

org-latex-compile: PDF file ./unicode_export_test.pdf wasn't produced: [package error]

I have checked for correct unicode-math installation:

~ $ kpsewhich unicode-math.sty
/usr/share/texlive/texmf-dist/tex/latex/unicode-math/unicode-math.sty

Installation of Xelatex is the newest version:

~ $ sudo apt-get install texlive-xetex
Reading package lists... Done
Building dependency tree       
Reading state information... Done
texlive-xetex is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 16 not upgraded.

install development version of org-mode: (failed) Following How do I keep current with bleeding edge development? - tutorial I have been able (I think) download it and compile it. Since I have no idea how to tell to Emacs run this version, Emacs runs Org-mode version 8.2.10 (release_8.2.10 @ /usr/local/share/emacs/24.4/lisp/org/). I have tried to add following lines to my config.

(add-to-list 'load-path (expand-file-name "~/elisp/org-mode/lisp"))
(remove 'load-path (expand-file-name "/usr/local/share/emacs/24.4/lisp/org/"))
(add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
(require 'org)

Without pleasing result.

Searching internet: Solution was not found.

Beating my self for being stupid: Didn't help.

3. Question: How to export unicode characters from org-mode to pdf?

  • Do I have to configure some org-mode variable?
  • Compile with different Latex interpreter?
  • Any other ideas?
  • If development version fixes this.... How can I install it?
1
  • could you please provide an example in plaintext in addition to images...
    – rasmus
    Commented Feb 7, 2016 at 12:48

3 Answers 3

13
+50

You need the latex file to use \usepackage[utf8x]{inputenc} rather than the default \usepackage[utf8]{inputenc}. This works with standard (pdf)latex.

For org export to generate this you have to set the variable org-latex-inputenc-alist accordingly. For example:

(setq org-latex-inputenc-alist '(("utf8" . "utf8x")))

For the variable to be defined, you may need to (require 'ox-latex) first.

Unfortunately, this does support only a limited set of math letters. Much more can be supported by including \usepackage[mathletters]{ucs}. This has to appear before the inputenc stuff, so you can't just use a #+latex_header:. A way to do that is to add it at head of org-latex-default-packages-alist.

(setq org-latex-default-packages-alist (cons '("mathletters" "ucs" nil) org-latex-default-packages-alist))

Note that ucs documentation (usually available through texdoc ucs) warns about the mathletters option:

This option is disabled by default, because using math greek in a normal text does not look good.

If you want those settings to apply only to the current file rather than globally, you can define them as file local variables. Add the following near the end of the file:

# Local Variables:
# org-latex-inputenc-alist: (("utf8" . "utf8x"))
# eval: (setq org-latex-default-packages-alist (cons '("mathletters" "ucs" nil) org-latex-default-packages-alist))
# End:

eval is a pseudo variable allowing to execute lisp code when the file is loaded.

7
  • Symbols Ω Θ Γ ω are not exported. Guessing there will be more symbols that will not be exported.
    – Empty_Mind
    Commented Mar 7, 2016 at 12:31
  • @Empty_Mind Oh my. Probably this was too simple to really work (though it's ok on the provided example). Needs more investigation on the latex side.
    – JeanPierre
    Commented Mar 7, 2016 at 12:36
  • @Empty_Mind Just edited my post. Tried just omega and theta, hope other work as well.
    – JeanPierre
    Commented Mar 7, 2016 at 16:58
  • Since I was not able do this my self: How did you find necessary infromation? What were you searching for?
    – Empty_Mind
    Commented Mar 7, 2016 at 20:05
  • 2
    @Empty_Mind First step was to get the latex part work. I searched for unicode at tex.stackexchange and then used local tex documentation (inputenc, ucs). It's convenient to directly edit the tex file exported by org and compile it to try things out. Once you get a working latex file, second step is to make org export the needed stuff. I found about the variables in file ox-latex.el where the "LaTeX Back-End for Org Export Engine" is defined. Should I mention I first used latex in 1995 and am slowly moving to unicode?
    – JeanPierre
    Commented Mar 7, 2016 at 21:04
5

You'd just need to load proper unicode support in LaTeX via unicode-math and fontspec. Then you'd need to compile with xelatex or lualatex.

See the docstring of the following variables: org-latex-packages-alist, org-latex-pdf-process and org-latex-compiler (the latter is introduced in Org 9).

In the development version of Org you could do something like this:

#+latex_compiler: xelatex
#+latex_header: \usepackage{libertine}
#+latex_header: \usepackage{unicode-math}

* Unicode symbols
 $z$ ∈ ℝ ∖ ℤ
\begin{equation}
\label{eq:1}
X ≔ \left\{ z\colon z ∈ ℝ ∖ ℤ \right\}
\end{equation}

org-mode compiling latex documents with unicode symbols

2
  • This looks promissing. But I'm getting Process completed with errors: [package error] Any ideas how to fix this, or get more specific error description?
    – Empty_Mind
    Commented Feb 21, 2016 at 12:17
  • How can I install development version?
    – Empty_Mind
    Commented Mar 4, 2016 at 22:24
2

Two ways to go:

1) Either write proper TeX expressions (instead of unicode) and let org just display them as utf-8 characters (with C-c C-x \) . http://orgmode.org/manual/Special-symbols.html

Or 2) Load a TeX package which translates your utf-8 characters into the proper math expressions. For example https://www.ctan.org/pkg/unicode-math?lang=en.

2
  • 1
    ad 2) how do I load that TeX package?
    – Empty_Mind
    Commented Feb 5, 2016 at 9:59
  • @Empty_Mind #+latex_header: \usepackage{unicode-math}. But this package does not work for me.
    – JeanPierre
    Commented Mar 7, 2016 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.