http://wiki.lyx.org/LyX/XeTeX

(Edit Section ↓)

What is XeTeX?

XeTeX (pronounced /ˈziːtɛx/) is a TeX typesetting engine using Unicode and supporting modern font technologies such as OpenType. Initially developed for Mac OS X, it is now available for all major platforms.

XeTeX natively supports Unicode while its input file is assumed to be in UTF-8 encoding. XeTeX can use all fonts of the operating system without additional configuring and access font features such as special ligatures and variable font weights.

XeTeX works well with both LaTeX and ConTeXt. Its LaTeX counterpart is invoked as XeLaTeX.

Homepage: http://scripts.sil.org/xetex

 

(Edit Section ↓)

Setting up LyX to work with Xetex

This assumes you have Xetex installed. On my texlive installation, it was installed automatically. Try running ‘xetex’ or ‘xelatex’ to check if its there. If not, install it (depends on your LaTeX distribution).

First of all, you need to add a PDF (xetex) File Format and LyX->Xetex conversion:

Under Tools->Preferences->File handling->File formats, click “New” and

[x] check “Document Format”
[x] check “Vector Graphic Format”
Short Name: pdf4
Extension: pdf
Viewer: xdg-open
(Windows users should use pdfview. Alternatively, use any viewer that worked for you under File Format PDF (pdflatex).)

Under “Converters” (just above the “File formats” you just clicked on), click on add and set

From format: LaTeX (pdflatex)
To format: PDF (xelatex)
Converter: xelatex $$i
Extra flag: latex
[x] check “Enabled”

 

(Edit Section ↓)

Using XeTex in a LyX document

Xetex is a program that is invoked instead of LaTeX, so if you set up your LyX document to use Xetex, it seems you cannot export to pdflatex anymore, just Xetex. Dont worry though, there wont be any problems (except the one just below).

Go to Document->Settings->LaTeX Preamble and add the following entries:

 

\usepackage{fontspec}

\usepackage{xunicode}

\usepackage{xltxtra}

also, set the encoding in “Language” to Unicode (XeTeX) (utf8).

From now on, exporting to PDF (pdflatex) will show errors, but PDF (xelatex) will work.

 

(Edit Section ↓)

Actually using foreign characters

You can just go ahead and e.g. type a chinese character like 猫 into your document (this one means ‘cat’). However, chances are the font you’re using doesnt have that character, so Xetex will just display nothing. To fix that, you need to install a font that has chinese characters (a list of such fonts and how they look can be found here). Suppose your font is called ‘Sazanami Mincho’. Just add a TeX (ERT) block to the document (by clicking that TeX symbol) and write

 

{\fontspec{Sazanami Mincho}

after that TeX thingy, you can just go ahead and write your chinese characters. However, if you mix english, you’ll see that it uses the english characters from Sazanami Mincho, which arent exactly beatiful. The solution is to add another TeX block after you’re done writing chinese containg

 

}

This closes the trailing { from before and reverts back to ‘normal’ text mode. Now you can write your english.

 

(Edit Section ↓)

Actually using foreign characters (the easy way, without TeX blocks)

If you follow the instructions below you can just go ahead and use CJK characters in your document. Only CJK characters will use a CJK font and everything else will remain untouched. Finally no ugly TeX blocks.

Download the xeCJK macro from CTAN:macros/xetex/latex/xecjk/, should be included in texlive 2009.

Add the following lines to your Latex Preamble (see above)

 

\usepackage{xeCJK}

\CJKlanguage{Japanese}

\setCJKmainfont{Sazanami Mincho}

 

(Edit Section ↓)

Declaring Font Families

If you intermix e.g. english and chinese a lot, this might be useful to you. Instead of always explicitly declaring the font family, just declare it once as a family and use that family. This is handy in case you want to change that font later.

Declare it like this:

\newfontfamily\Chinese{Sazanami Mincho}

And now use

{\Chinese

instead of

{\fontspec{Sazanami Mincho}

 

(Edit Section ↓)

Examples

Here is a LyX-document showing you how to use XeTeX’s unicode features: xetex.lyx
and its PDF-output: xetex.pdf

Hints on using XeTeX with LyX 1.5.x are on the Mac.XeTeX page.

 

(Edit Section ↓)

Problems

  • Broken Preview Button

As you cannot use LaTeX anymore, the handy preview button is broken. You need to View->PDF (xelatex) which is one more click than you’re probably used to. A Workaround will be posted here soon.

 

  • Quotes

If the quote signs do not work the way you expect, look here.

 

(Edit Section ↓)

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

用户登录