# XeLaTeX with Polyglossia and Thai

The following example displays the English text alright, but not the Thai text. It is simply left blank in the PDF result.

\documentclass{report}

\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}
\newfontfamily\thaifont{Norasi}
\newfontfamily\thaifontsf{Loma}

\usepackage{polyglossia}
\setdefaultlanguage{english}

\begin{document}
Here comes some Thai: สารบัญ

{\sffamily Here comes some Thai: สารบัญ}
\end{document}


If I change the \setdefaultlanguage to thai, it works, but that's not the idea as this is an English document.

Any suggestions?

-

You are nowhere telling xelatex that you wish to switch to thai. Use either \setotherlanguage{thai} and \selectlanguage{thai}, or at least use the \thaifont command.

-
I thought the whole idea of Unicode input in XeLaTeX was that XeLaTeX "just works" with that. In any case, I've added the \setotherlanguage{thai} line but that has no effect. Your other suggestions require that I know in advance that the following text actually will be in Thai. In my case, that's not practical as I process unknown text automatically. – kongo09 Aug 3 '11 at 14:11
Sorry, I misunderstood you. \setotherlanguage{thai} obviously only works together with \selectlanguage{thai}. Yes, that works. But unfortunately leaves me with the problem that I would have to know where in the text the Thai script is sitting. I guess the solution would be to find a rather complete unicode font that has the scripts like Thai covered and use that as main font. – kongo09 Aug 3 '11 at 14:17
It is possible (with \XeTeXintercharclass/\XeTeXinterchartoks) to setup things so that XeTeX automatically switch to another font. – Ulrike Fischer Aug 3 '11 at 14:27
That's interesting! This lead me to the ucharclasses package, which doesn't seem to be part of the large standard distributions. A simple \setTransitionTo{Thai}{\fontspec{Norasi}} does the trick. Unfortunately, the package seems to be very computationally intensive as it makes the whole process quite slow. – kongo09 Aug 3 '11 at 15:18

Thanks for this! It helped me a lot, but it still required some experiments to get it working. Hence, I would like to contribute a functional example here:

File letter-preamble-th.tex

%%% IMPORTANT --- must be compiled with XeLaTeX!!! %%%

\documentclass[a4paper,
footsepline,
pagenumber=botcenter,
fromalign=left,
fromrule=below,
fromemail=true,
subject=untitled,
locfield=narrow,
foldmarks=true,
11pt
]{scrlttr2}
\usepackage{fontspec}
\usepackage{polyglossia}

\setmainlanguage{english}
\setotherlanguage{thai}

\setmainfont{Times New Roman}
\setsansfont{Arial}
\newfontfamily\thaifont{Norasi}
\newfontfamily\thaifontsf{Loma}

\usepackage{graphicx}

\usepackage{tabularx}
\usepackage{booktabs}

\usepackage{color}
\definecolor{darkblue}{rgb}{0,0,.5}
\definecolor{darkgrey}{rgb}{0.3,0.3,0.3}

\setlength{\oddsidemargin}{-.53cm}
\setlength{\textwidth}{363pt}
\setlength{\textheight}{690pt}

% Zum Testen
\usepackage{layout}
\usepackage{blindtext}

%\usepackage[ngerman]{isodate}
%\isodate

\color{darkgrey}
\hfill
\parbox[t]{0.25\textwidth}{
\raggedright{
\vspace*{0.46cm} % offset for align the top border with the head of the wizard
\footnotesize
\usekomavar{fromname}\\
\usekomavar{fromemail}\\\smallskip

\scriptsize
PGP-Fingerprint\\
\texttt{1CB2 35C8 F3B0 236A C46D}\\
\texttt{38FB 289F 1C57 2BA1 020C}\\
}%
}
}%

% Header for all other pages
\parbox[t]{.2\textwidth}{
\scriptsize\usekomavar{fromname}
}\hfill
\parbox[t]{.4\textwidth}{
\scriptsize\usekomavar{subject}
}\hfill
\parbox[t]{.4\textwidth}{
\hfill\scriptsize\usekomavar{toname}
}
}

\firstfoot{%
\color{darkgrey}
\parbox[t]{\textwidth}{\scriptsize
%\centering
%\parbox[t]{.2\textwidth}
Example footer | {\selectlanguage{thai}ติดต่อ ประชาสัมพันธ์มหาวิทยาลัยเชียงใหม่} \\
And some more Thai: {\selectlanguage{thai}มหาวิทยาลัยเชียงใหม่} |  More nonsense: TH 245\,111\,222\\
Some people or companies put their bank coordinates here in the footer -- hence this example\\
}%
}%

% Sender

\setkomavar{fromemail}{\href{mailto:marco@domain.tld}{marco@domain.tld}}
%   \hspace{-1.1cm} % Offset for align the center of the wizard with the text
%   \includegraphics[height=2.5cm]{img/logo.png}}}
\setkomavar{fromname}{Marco {\selectlanguage{thai}หงุ่ยตระกูล}}


File example-letter-th.tex

%%% IMPORTANT --- must be compiled with XeLaTeX!!! %%%

\input{letter-preamble-th.tex}

\setkomavar{date}{ 2015-04-27 }

\setkomavar{subject}{Example letter English/{\selectlanguage{thai}ไทย} (Thai)}

\newcommand{\closingText}{Yours sincerely,}
\setkomavar{signature}{Marco {\selectlanguage{thai}หงุ่ยตระกูล}-Schulze}

\begin{letter}{#2 #1\\#3}
\opening{\openingText}

this is an example letter using English and Thai -- mixed {\selectlanguage{thai}พสกนิกรสุดปลื้มปีติ} like this.

Unfortunately, it is necessary to switch explicitly to Thai using:
\{\textbackslash{}selectlanguage\{thai\}XXX\}'' where XXX''
are Thai letters. I read some hints that XeLaTeX is able to switch the language (and thus the font!) automatically,
but I didn't want to invest more time into this topic -- and this solution works fine (at least for now).

\closing{\closingText}
\end{letter}
}

\begin{document}
%\layout