XeTeX on LyX/Mac
XeTeX is "a typesetting system based on a merger of Donald Knuth's TeX system with Unicode and Mac OS X font technologies." (For details, see http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&item_id=xetex.) To get XeTeX to work with LyX/Mac, you need to do the following:
- Install XeTeX. There are three options: using the installer package provided here, using i-Installer, or using MacTex
- Install fontspec.sty, which can be found here (seems to have a new location). Place this file somewhere TeX can find it, such as ~/Library/texmf/tex/latex/. Make sure to run
sudo texhash
from the Terminal (providing an administrator password when it asks) to inform TeX of the addition.
Note: Don't forget to run Edit -> Reconfigure from within LyX/Mac, and then quit and restart LyX/Mac.
If you've installed TeX/XeTeX via MacTex, you probably already have this file. I found it on my drive via
$ find /usr/local/texlive/ -name fontspec.sty
/usr/local/texlive//2007/texmf-dist/tex/xelatex/fontspec/fontspec.sty
- In LyX/Mac, create a new File format (Preferences -> File formats). Fill in the fields at the bottom: First, in the "Format" field, give it a unique name (such as
pdf4). In the "GUI name" field, give it a name like pdf (XeTeX). The "Extension" field should be pdf, and the "Viewer" field should be open. In Lyx 1.5 check also the "Document format" tickbox. Click the "Add" button when you are done.
- In LyX/Mac, create a new Converter (Preferences -> Converters). First, select "LaTeX (plain)" from the "From" drop-down list. Then select the GUI name you provided before ("pdf (XeTeX)") from the "To" drop-down list. Click the "New" button. Then enter
xelatex $$i in the "Converter" field and latex in the "Extra flag" field. Click the "Modify" button, and then click the "Save" button.
Now you should find a new item under the View menu. However, XeTeX requires that you tell it explicitly what font you use, and if you want this done globally for your document, it will need to be done in the Preamble (Layout -> Document -> Preamble). Include something like the following:
\@ifundefined{XeTeXversion}{}{%
\usepackage{fontspec}%
\setromanfont[Mapping=tex-text]{Hoefler Text}%
\setsansfont[Mapping=tex-text]{Gill Sans}%
\setmonofont[Mapping=tex-text]{Courier New}%
}%
\usepackage{xunicode}
\usepackage{xltxtra}
Times is another valid font to use instead of Hoefler Text. You should be able to use any font which appears in the Font Book application.
XeTeX Problems:
- If you have graphics in your documents, you'll need to put
xetex in the "Options" field at Layout -> Document -> Layout. (This will load graphicx.sty with the needed xetex option.). In Lyx 1.5, the "Options" field is at Document Settings -> Document Class.
- To use hyperref, you'll need to pass
xetex as an option to the hyperref package.
- XeTeX is designed to accept Unicode encodings. LyX 1.5.x supports Unicode as well. You need to select the encoding
utf8-plain (in Document→Settings→Language→Encoding) for XeTeX. If you select utf8-plain, your documents will look ok with #XeTeX, but you have to use utf8 (or similar) if you want it to work with pdflatex (utf8-plain omits the \inputenc line, which pdflatex needs but which confuses xetex).
Greek Unicode text:
In order to use Babel's hyphenation patterns for greek you have include the following code in your Preamble:
\@ifundefined{XeTeXversion}{}{%
\usepackage{xltxtra}%
\setromanfont[Mapping=tex-text]{Minion Pro}%
\setsansfont[Mapping=tex-text]{Myriad Pro}%
\setmonofont[Mapping=tex-text]{Monaco}%
\usepackage[greek,german]{babel}
\let\greektext\relax
\newfontinstance\grfont[Script=Greek]{Minion Pro}
\newcommand{\gr}[1]{{\selectlanguage{greek}\grfont #1}}
}%
Now you can enter greek text as ERT:
\gr{αβγ..}
Mac XeTeX