具有多语和泰语功能的 XeLaTeX

具有多语和泰语功能的 XeLaTeX

以下示例可以正常显示英文文本,但无法显示泰文文本。它在 PDF 结果中只是留空。

\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}

如果我将其改为\setdefaultlanguage泰语,它可以起作用,但这不是我想要的,因为这是一份英文文档。

有什么建议么?

答案1

您没有告诉 xelatex 您希望切换到泰语。请使用 \setotherlanguage{thai}\selectlanguage{thai},或者至少使用\thaifont命令。

答案2

谢谢!它帮了我很多忙,但仍然需要一些实验才能让它发挥作用。因此,我想在这里贡献一个功能示例:

文件信函序言-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{adjustbox}
\usepackage{graphicx}

\usepackage{tabularx}
\usepackage{booktabs}

\usepackage{color}
\definecolor{darkblue}{rgb}{0,0,.5}
\definecolor{darkgrey}{rgb}{0.3,0.3,0.3}
\usepackage[breaklinks=true, linkcolor=darkblue, menucolor=darkblue, urlcolor=darkblue]{hyperref}

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

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

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


\firsthead{% 
  \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{fromaddress}\\\smallskip
      \usekomavar{fromemail}\\\smallskip

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

% Header for all other pages
\nexthead{
  \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{fromaddress}{{\selectlanguage{thai}239 ถนนห้วยแก้ว}\\{\selectlanguage{thai}ต.สุเทพ อ.เมือง}\\{\selectlanguage{thai}จ.เชียงใหม่ 50200}\\Thailand}


\setkomavar{fromemail}{\href{mailto:[email protected]}{[email protected]}}
% \setkomavar{fromlogo}{\adjustbox{valign=t}{
%   \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}หงุ่ยตระกูล}}

文件例如字母-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{\openingText}{Dear Ladies, dear Sirs,}

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





\renewcommand*{\adrentry}[8]{
  \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

\pagestyle{myheadings}

% Multiple entries can be used to easily create a serial letter
% Only last name, first name and address are currently used
\adrentry{{\selectlanguage{thai}รอยัล  ออร์คิด พลัส\\บริษัท การบินไทย จำกัด (มหาชน)}}{}{{\selectlanguage{thai}ตู้ปณ. 567 ไปรษณีย์ สามเสนใน\\กรุงเทพฯ 10400}}{Telefon}{F1}{F2}{Kommentar}{ADDR}
\end{document}

为了以防万一,上面的代码粘贴不正确,我为您上传了源代码和生成的 PDF:示例字母-th.zip

我希望这是有帮助的!

相关内容