Search:   Help



LyX documentation


Shared groups


LyX /


Categories: XeTeX, Unicode, TeX engine
<< | Page list | >>

How to use LyX with XeTeX

1.  What is XeTeX?

XeTeX is a TeX typesetting engine. Its main difference compared to the standard pdfTeX engine that

  • it natively supports Unicode (while its input file is assumed to be in UTF-8 encoding, which is automatically assured by LyX)
  • it allows to use any OpenType and TrueType font for your documents.

Its strength is that is supports many writing systems and scripts (this is actually what it was developed for specifically). It is thus the preferred engine for most languages that use non-alphabetic or right-to-left scripts. (Here is a nice explanation of different scripts.)


2.  Comparison to LuaTeX

Both XeTeX and LuaTeX allow to use any OpenType and TrueType font for your documents, and both support Unicode natively. However, there are pros and cons for either engine, which will be sketched in what follows.

XeTeX only supports PDF while LuaTeX supports DVI and PostScript output additionally.

Furthermore, LuaTeX has a scripting interface which allows for some fancy processing tricks (see the LuaTeX page for some examples).

Also, XeTeX supports less microtypographic features than LuaTeX (in particular, it does not yet support font expansion).

LuaTeX, however, does not yet support as many scripts as XeTeX does. As opposed to LuaTeX, XeTeX supports to typeset documents in

  • Arabic
  • Bengali
  • Divehi
  • Farsi
  • Hebrew
  • Hindi
  • Kannada
  • Lao
  • Malayalam
  • Syriac
  • Tamil
  • Telugu
  • Thai
  • Urdu

Also, XeTeX exists and has been productively used for some longer time. So it can be considered more "mature" and "stable" than LuaTeX, which still undergoes heavy development.

3.  Setting up LyX to work with XeTeX

Since LyX 2.0 you only need to check in the menu Document→Settings→Fonts the option Use non-TeX fonts (via XeTeX/LuaTeX). Then you can immediately use the menu View→PDF (XeTeX).

Note: If the option Use non-TeX fonts (via XeTeX/LuaTeX) is grayed out (you cannot activate it), make sure that the fontspec package is installed (and you need to reconfigure LyX after installing this package).

4.  Using OpenType fonts (otf) in XeTeX math mode (LyX 2.1)

Go to


and click "Use non-TeX fonts (via XeTeX/LuaTeX)".

In the "Maths" font combo, select "Non-TeX Fonts Default". This set a default OpenType font (usually LatinModern Math) for math (internally, LyX loads the unicode-math package).

If you want a different font, enter something like the following to Document→Settings→LaTeX Preamble:


Please consult the documentation of the package unicode-math for details and for what math fonts are at disposal currently.

5.  Using true type fonts (ttf) in XeTeX math mode (LyX 2.0)

See also for unicode and maths:

Go to


but do not click "Use non-TeX fonts (via XeTeX/LuaTeX)". Set all fonts (default family, LaTeX font encoding, roman, sans serif, typewriter) to default, and add the following to the preamble:

Document→Settings→LaTeX Preamble

\usepackage{mathspec}%main package to select fonts in mathmode, includes the fontspec package
\setmainfont{...} set font used in non-math mode, i.e. font for main paragraphs, headings, foot/margin notes etc,
\setmathsfont(Digits,Latin)[Numbers={Lining,Proportional}]{...}%choose font for Latin and Arabic numerals, needed to match mainfont,
\setmathsfont(Greek){...}%choose a font with Greek characters, or leave this out for the default computer modern Greek letters,
\setmathrm{...}%choose roman (upright) font, needed for mathbf to appear in same font as set mathfont, 
default is computer modern roman in upright ("\mathrm") and upright bold ("\mathbf"),

where in the curly brackets any true type font can be used, provided it can supply those characters (for Greek alphabet choose a font which includes Greek, etc). You can also declare the remaining font alphabets, or leave them out for the default computer modern;

\setmathsf{...}%(sans serif) 
\setmathbb{...}%(blackboard bold)

See this link also: [].

Beware that multiple fonts selected can cause the error message:

LaTeX error: too many fonts used in version normal

while in equation mode. One simple solution is to use normal text mode "\textrm{...}" instead of "\mathrm{...}" for upright characters (it works out the same).

Also, one can insert ttf characters supplied from any ttf font (or it could match the mainfont) in an equation, for example Russian Cyrillic, Arabic, or extended Latin including "hbar" ħ, although these will be upright ("roman"). A math macro that makes them italic can be defined in the preamble;

\def\anysymb[#1]{\fontspec{(font name here)...}\textit{#1}} 

where in the curly brackets the font is inserted. Here the command is "\anysymb[...]" (you could define another name instead of "anysymb" of course), in the square brackets the ttf character is inserted, for example:


would generate ħЖ in the font chosen in the macro definition.

See also: math.

6.  Setting up XeTeX for CJK scripts

If you follow the instructions below you can just go ahead and use CJK characters like 猫 into your document (this one means 'cat'). Only CJK characters will use a CJK font and everything else will remain untouched.

Download the xeCJK package from CTAN:macros/xetex/latex/xecjk/, if it is not yet installed (it should be included in TeXLive and MikTeX).

Add the following lines to Document→Settings→LaTeX Preamble:

\setCJKmainfont{Sazanami Mincho}

7.  References

Lyx Mailing List Thread: Want to write Chinese in LyX? Please give me some feedback on this HOWTO
Xetex Mailing List Thread: Xetex doesnt display chinese characters in fonts that should have them

Categories: XeTeX Unicode TeX engine

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2013-06-02 10:21 UTC