%
% Introduction to XeTeX
%
% This file is an addendum to lshort-english.
% You will need the lshort-english source version 4.31
% to process this file.
% Add \input{unicode} to typeset.tex just in front of the
% \section{The Space Between Words}.
%
% Need \usepackage{hologo} and
% \usepackage[...,greek,...]{babel}
%

\newpage
\subsection{The Unicode option}

\secby{Axel Kielhorn}{A.Kielhorn@web.de}
Unicode it the way to go if you want to include several languages in one document, especially when these 
languages are not using the latin script. There are two \hologo{TeX}-engines that are capable of processing Unicode input:

\begin{description}
\item[\hologo{XeTeX}] was developed for MacOS X but is now available for all architectures. It was first included into TexLive 2007.
\item[\hologo{LuaTeX}] is the successor of pdf\TeX. It was first included into TexLive 2009.
\end{description}

The following describes \hologo{XeLaTeX} as distributed with TexLive 2010.

\subsubsection{Quickstart}

To convert an existing \LaTeX\ file to \hologo{XeLaTeX} the following needs to be done:

\begin{enumerate}
\item Save the file as UTF-8
\item Remove
\begin{lscommand}
\verb|\usepackage{inputenc}|\\
\verb|\usepackage{fontenc}|
\end{lscommand}
from the preamble.
\item Change
\begin{lscommand}
\verb|\usepackage[|\emph{languageA}\verb|]{babel}|
\end{lscommand}
to
\begin{lscommand}
\verb|\usepackage{polyglossia}|\\
\verb|\setdefaultlanguage[babelshorthands]{|\emph{languageA}\verb|}|
\end{lscommand}
\item Add
\begin{lscommand}
\verb|\usepackage[Ligatures=TeX]{fontspec}|
\end{lscommand}
to the preamble.
\end{enumerate}

The package \pai{polyglossia} is a replacement for \pai{babel}. It takes care of the hyphenation patterns and automatically generated text strings. The option \verb|babelshorthands| enables \pai{babel} compatible shorthands for german and catalan.

The package \pai{fontspec} handles font loading for \hologo{XeLaTeX} and \hologo{LuaTeX}. The default font is Latin Modern. It is a little know fact that some \hologo{TeX} command are ligatures defined in the Computer Modern fonts. If you want to use them with a non-\hologo{TeX} font, you have to fake them. The option \texttt{Ligatures=TeX} defines the following ligatures:

\begin{tabular}{rr}
\verb|--|	& --\\
\verb|---|	& ---\\
\verb|''|	& ''\\
\verb|``|	& ``\\
\verb|!`|	& !`\\
\verb|?`|	& ?`\\
\verb|,,|	& ,,\\
\verb|<<|	& <<\\
\verb|>>|	& >>\\
\end{tabular}

%\subsubsection{It's all $\gamma\rho\eta\eta\kappa$ to me}
\subsubsection{It's all \textgreek{Ellhnik'a} to me}

So far there has been no advantage to using a Unicode \hologo{TeX} engine.
This changes when we leave the Latin script and move to a more interesting language like Greek, Russian or even Hebrew.
With a Unicode based system, you can simply\footnote{For small values of simple.} enter the characters in your editor and \hologo{TeX} will understand them.

Writing in different languages is easy, just specify the languages in the preamble:

\begin{lscommand}
\verb|\setdefaultlanguage{english}|\\
\verb|\setotherlanguage[babelshorthands]{german}|
\end{lscommand}
%
To write a paragraph in German, you can use the German environment:

\begin{lscommand}
Englisch text.\\
\verb|\begin{german}|\\
Deutscher Text.\\
\verb|\end{german}|\\
More English text.
\end{lscommand}

If you just need a word in a foreign language you can use the \verb|\text|\emph{language} command:

\begin{lscommand}
\verb|Englisch text. \textgerman{Gesundheit} is actually a German word.|
\end{lscommand}

This may look unnecessary since the only advantage is a correct hyphenation, but when the second language is a little bit more exotic it will be worth the effort.

Sometimes the font used in the main document does not contain glyphs that are required in the second language\footnote{Latin Modern does not contain Cyrillic letters}. The solution is to define a font that will be used for that language. Whenever a new language is activated, \pai{polyglossia} will first check whether a font has been defined for that language.

\begin{lscommand}
\verb|\newfontfamily\russianfont[Script=Cyrillic,(...)]{(font)}|
\end{lscommand}

Now you can write

\begin{lscommand}
\verb|\textrussian{Pravda} is a russian newspaper.|
\end{lscommand}
%
Since this document is written in Latin1-encoding, I cannot show the actual Cyrillic letters.

Some languages are written left to right, others are written right to left(RTL). \pai{polyglossia} needs the \pai{bidi} package\footnote{\texttt{bidi} does not support \hologo{LuaTeX}.} in order to support RTL languages. The \pai{bidi} package should be the last package you load, even after \pai{hyperref} which is usually the last package. (Since \pai{polyglossia} loads \pai{bidi} this means that \pai{polyglossia} should be the last package loaded.)



\newpage