Using Unicode Character in LyX or LaTeX: XeTeX
Now and then I get asked about how to use some TrueType or OpenType font with LaTeX, so I figured I would take the time to write up some simple tutorials on how to do so. The first part will focus on the easiest route to making use of TrueType and OpenType fonts in LaTeX: XeTeX and XeLaTeX.
XeLaTeX also has the advantage of not only giving easy access to modern fonts, but also accepting Unicode input files.
The first thing you need to do is find out if you have XeLaTeX installed, and if it is a sufficiently up to date version. This is easiest to do from the command-line:
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”
Set the LaTeX Preamble in LyX
Go to Document->Settings->LaTeX Preamble and add the following entries:
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\setmainfont[Mapping=tex-text]{SimSun}
also, set the encoding in “Language” to Unicode (XeTeX) (utf8).
Export to PDF file
From now on, exporting to PDF (pdflatex) will show errors, but PDF (xelatex) will work. Select Export –> PDF (xetex)
This example file can be downloaded here:
Example of the outcome is here:
Using the zhspacing Package
I also find zhspacing package works well too. It fine-tunes several details in typesetting Chinese using XeTeX and XeLaTeX, such as automatic font switch between Chinese and Western characters, skip adjustment of fullwidth punctuations, punctuation prohibitions, automatic skip insertion between Chinese and Western characters or math formulas, etc.
The basic usage is like this:
\documentclass{article}
\usepackage{zhspacing}
\zhspacing
\begin{document}
这是中文测 试。中文和English的混排。中
文和$E=mc^2$的混排。
\end{document}
Typesetting Chinese document using XeLaTeX + zhspacing is much like using LaTeX + CJK + CJKpunct, except that you don’t need to add the annoying ~ between Chinese and English for spacing adjustment, and opening punctuations (line-end prohibition) can occur at the beginning of the line, which is forbid in CJKpunct. The amount of adjusted space can be easily customized to your own taste.
The following is my TexMakerX seetings and outcome
This file and output can be downloaded from here:
References
http://existentialtype.net/2008/07/12/fonts-in-latex-part-one-xelatex/
http://code.google.com/p/zhspacing/
http://edin1.wordpress.com/2009/03/16/typesetting-professional-islamic-articlesbooks-with-xetex/

