%%!TEX TS-program = xelatex
%%!TEX encoding = UTF-8 Unicode

\documentclass[11pt, oneside]{amsart}
\usepackage{multicol}
\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                   % ... or a4paper or a5paper or ... 
%\geometry{landscape}                % Activate for for rotated page geometry
\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{url}

\usepackage{fontspec}
\usepackage{xunicode,xltxtra}
\defaultfontfeatures{Mapping=tex-text}

\newcommand{\TS}{TeXShop}

\title{Short Introduction to XeTeX }
\author{Richard Koch}
%\date{}                                           % Activate to display a given date or no date


\begin{document}
\maketitle
\begin{multicols}{2}
\thispagestyle{empty}


\section{Some \TeX\ History}

\TeX\ was invented before several of the important computing developments of the twentieth century. In 1978 there was no Macintosh and no generally available computer with a graphical interface. Personal computers printed output using a single bitmapped font in which all characters had the same width; some computers only printed upper case letters.

Consequently, Knuth had to invent outline fonts at the same time that he invented \TeX. In his documentation, Knuth always talks about \emph{two} programs, the typesetting program \TeX\ and the outline font program \textsc{Metafont}.

Later in the decade, other players introduced their own outline fonts using different formats: Adobe's Type 1 Postscript fonts, Apple's Truetype fonts, and Microsoft's OpenType fonts. The history of these fonts is rather complicated; suffice it to say that each is now supported on the Mac and available on other operating systems as well. A vast number of beautiful fonts are available in these new formats.

Adapting these fonts for use in \TeX\ is a complicated task, which has only been successfully completed in a small number of cases. One of the most important complaints about \TeX\ is the limited number of available fonts. 

\section{\XeLaTeX\ and Fonts}

\XeLaTeX\ completely solves the font problem. It can use Knuth's fonts, of course, but it can mix these with system fonts in Adobe Type 1, Truetype, and OpenType formats. These fonts need not be adapted for use in \TeX; instead they are immediately available.

\section{More History: Unicode}

\TeX\ source manuscripts contain standard characters available on any typewriter. Indeed, originally \TeX\ could only accept the 128 standard ASCII input characters. Later this was expanded to 256 characters. This is enough for standard English and for Western European Languages, but it is certainly not enough for Japanese, Chinese, and a multitude of other languages. Over the years, many projects have attempted to adopt \TeX\ so it can typeset these other languages.

Later the same problem arose in the entire computer industry, since a large number of sales occur in countries which do not use Western scripts. The solution invented by the industry is Unicode, an open standard which can theoretically encode the characters of all languages on earth. Most computer manufacturers have adopted this standard. For example, the edit class in Cocoa (and consequently \TS's editor) accepts arbitrary Unicode characters.

\section{\XeLaTeX\ and Unicode}

\XeLaTeX\ modifies \TeX\ to accept any Unicode character; source documents are saved in UTF-8 Unicode format. In conjunction with full support for OpenType fonts, this makes it possible to write \TeX\ documents in virtually any language on earth.

\section{How Do I Use \XeLaTeX?}

Simple. Take any standard \LaTeX\ document. Somewhere close to the top, say within the first ten lines, include the lines
\begin{verbatim}
     %!TEX TS-program = xelatex
     %!TEX encoding = UTF-8 Unicode
\end{verbatim}
These lines begin with the \TeX\ comment character, so \TeX\ will ignore them. However, \TS\ and TeXworks recognize the lines and do something special when you open, save, or typeset the file. The first line tells these programs to call {\tt xelatex} rather than {\tt pdflatex} when you ask it to typeset the document. The second line tells the programs  to load and save the file with {\tt UTF-8 Unicode} encoding, rather than the standard {\tt Mac OS Roman} encoding.

Since \XeLaTeX\ supports standard \TeX\ fonts and standard \TeX\ commands, typesetting will proceed without change.

\section{How Do I Switch To Alternate Fonts in \XeLaTeX?}

A style package written by Will Robertson makes this task simple. Add the following lines to the \TeX\ preamble:
\begin{verbatim}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont{Hoefler Text}
\setsansfont[Scale=MatchLowercase]
          {Gill Sans}
\setmonofont[Scale=MatchLowercase]
          {Andale Mono}
\end{verbatim}
Change the three font names to any system fonts you'd like to use. The first font is the default serif font, the second is the default sans serif font, and the third is the default monospaced font for typewriter-like output. If your entire document is in a serif font, it is enough to change the first font.

To find appropriate font names, open Apple's Font Book application, look at the font samples, and choose one of the font names listed by the application.

\section{How Do I Insert Unicode in the Source Manuscript?}

Go to Apple's System Preferences and choose the International panel. Select the Input Menu tab. A large number of keyboards layouts are provided, as well as more complicated input methods for Chinese and Japanese. 

Choose, for example, Arabic, Nepali, and Russian. A flag icon will appear at the right side of the menu bar. Open a blank \TS\ or TeXworks document. Start with a US or Western European flag and type some standard text.

Then select the Russian flag and type some more. Notice that you are inputting Cyrillic characters. Select Nepali and type another line, noticing the distinct characters. 

Finally select Arabic and type again. Arabic is written from right to left; notice that the characters you type in the editor appear from right to left. In Arabic, character shapes change when the character ends a word, Notice that previous characters tend to change shape as you add additional characters.

None of this is very useful unless you know one of these languages!

\section{How Do I See These Characters in the \TeX\ Output?}

Ah, that is the tricky step. Some Macintosh fonts appear to contain only standard Roman characters, but have been extended to contain additional Unicode characters.
You must typeset in a font which contains characters for the language you have selected.

For example, the Geeza Pro font contains Arabic characters, the Lucida Grande font contains Hebrew characters, and the Osaka font contains Japanese characters. Some experimentation may be needed to find a font which contains characters for the language you want to use. 

Suppose, for example, that you want to output Arabic. The following line defines a font family which contains Arabic characters:
\begin{verbatim}
      \newfontfamily{\A}{Geeza Pro}
\end{verbatim}

\newfontfamily{\A}{Geeza Pro}
To insert Arabic, type the following and insert Arabic characters in the spot currently containing dots:
\begin{verbatim}
     This is Arabic text: {\A ....}
\end{verbatim}
as in \{$\backslash$A {\A السلام عليكم}\}.

Incidentally, this document was typeset with \XeLaTeX. In ordinary \LaTeX, the last clause of the previous paragraph would have been difficult to typeset.


\section{Sample \XeLaTeX\ Documents}

The remaining pages show sample Xe\TeX\ source manuscripts, and the resulting \XeLaTeX\ output. This gives some feel for the advantages of \XeLaTeX\ in the general community. 
\end{multicols}
\end{document}
