How to set up Latex for Thai language on Windows

  1. First, download and install Miktex from the Miktex site. This will be your Latex engine. At this state, you can use a text editor to make english Latex documents (one good editor is WinEdt, but as far as I know, it does not support Thai fonts).

  2. Then set up the thai language (the following instructions are in thai, this was copied from http://khombkk.tripod.com/mikfiles/miktle.htm) ::

ภาษาไทยชุดนี้ ดัดแปลงมาจาก thailatex-0.25 ซึ่งมากับ Linux.TLE เพื่อให้ใช้ได้กับ MikTeX

การติดตั้งฟอนต์และมาโคร
1.) ดาวน์โหลดไฟล์ miktl025.zip และ unzip.exe (หรือจาก ที่นี่) ไว้สักที่นึงก่อน สมมติว่าเป็น c:\temp

2.) ไปที่ได้เรคตอรีของ MikTeX (\texmf) จากนั้น unzip ด้วยคำสั่ง
cd \texmf
c:\temp\unzip c:\temp\miktl025.zip

จริงๆ ใช้ unzip program อะไรก็ได้ แต่ให้แน่ใจว่า unzip ไปถูก directory

3.) ใช้ text editor หรือ notepad แก้ไขไฟล์ \texmf\dvips\config\psfonts.map
( ถ้าหาไฟล์ psfonts.map ไม่พบ ลองดูที่ \texmf\dvips\base\psfonts.map )
แล้วเพิ่มบรรทัดเหล่านี้ต่อท้ายเข้าไป
rdbtt DBThaiText " dbttEncoding ReEncodeFont " <dbtt.enc <dbtt.pfb
rdbttb DBThaiTextBold " dbttEncoding ReEncodeFont " <dbtt.enc <dbttb.pfb
rdbtti DBThaiTextItalic " dbttEncoding ReEncodeFont " <dbtt.enc <dbtti.pfb
rdbttz DBThaiTextBoldItalic " dbttEncoding ReEncodeFont " <dbtt.enc <dbttz.pfb
rnorasi Norasi " TeXTISEncoding ReEncodeFont " <TeXTIS.enc <norasi.pfb
rnorasib Norasi-Bold " TeXTISEncoding ReEncodeFont " <TeXTIS.enc <norasib.pfb
rnorasii Norasi-Italic " TeXTISEncoding ReEncodeFont " <TeXTIS.enc <norasii.pfb
rnorasiz Norasi-BoldItalic " TeXTISEncoding ReEncodeFont " <TeXTIS.enc <norasiz.pfb

4.) จากนั้นให้ MikTeX รับทราบว่าเราเพิ่มเติมฟอนต์และ อื่นๆเข้าไป ไปที่ start menu ของ Windows ( ควรจะปิด yap ทุกอันที่ทำงานอยู่เสียก่อน เพราะ yap จะล๊อคฐานข้อมูลชื่อฟอนต์ ไม่ให้เขียนได้ )
START --> Programs --> MikTeX --> Maintainance --> Refresh Filename Database

5.) ทดสอบโดยใช้คำสั่ง
tex testfont
จากนั้นโปรแกรมจะถามชื่อฟอนต์ที่จะทดสอบ ( Name of the font to test = )
norasi
แล้วจะขึ้น prompt ที่เป็น * ให้ใส่คำสั่ง
\table\bye

เมื่อกลับมาที่ dos prompt แล้ว ใช้คำสั่ง
yap testfont

เลื่อนลงมาด้านล่างๆ น่าจะเห็นตัวอักษรภาษาไทย แสดงว่าฟอนต์ติดตั้งเสร็จเรียบร้อย

วิธีใช้งาน
เพื่อให้ตัดคำออกมาสวยงาม ควรจะไปเอาโปรแกรม swath เพื่อตัดแยกคำพัฒนาขึ้นมาโดย NECTEC สำหรับ win32 จาก NECTEC-links ( หรือ NECTEC-ftp, [local copy] ) แล้วลงไว้สักที่นึง สมมติว่าเป็นที่ c:\swath
c:
mkdir \swath
c:\temp\unzip c:\temp\swath-win32

1.) สร้างไฟล์ชื่อ thaitest.ttx ตามตัวอย่างด้านล่าง
------------ cut here ----------------
%
% file: thaitest.ttx
%
\documentclass{article}
\usepackage{a4}
\usepackage[thai]{babel}
\usepackage{thswitch}

\begin{document}
ฟอนต์ norasi\\
ทดสอบภาษาไทย\\
ญ ญุ ญู ฐ ฐุ ฐู\\
วรรณยุกต์จะขยับซ้ายหลบอักษร ป ฝ\\
ปา ป่า ป้า ป๊า ป๋า\\
บา บ่า บ้า บ้า บ๋า\\
เมื่อมีสระใต้ ญ และ ฐ จะเอาฐานออกก่อน\\

\vskip 6pt
\usefont{LTH}{dbttx}{m}{n}
ฟอนต์ dbttx\\
ทดสอบภาษาไทย\\
ญ ญุ ญู ฐ ฐุ ฐู\\
วรรณยุกต์จะขยับซ้ายหลบอักษร ป ฝ\\
ปา ป่า ป้า ป๊า ป๋า\\
บา บ่า บ้า บ้า บ๋า\\
เมื่อมีสระใต้ ญ และ ฐ จะเอาฐานออกก่อน
\end{document}
%
------------ cut here ----------------

2.) ใช้โปรแกรมตัดคำและแปลงจาก .ttx เป็น .tex
c:\swath\swath -f latex -d c:\swath\data < thaitest.ttx > thaitest.tex

2.1) จากนั้นใช้ latex เพื่อสร้างไฟล์ .dvi แล้วใช้ yap เรียกดู
latex thaitest
yap thaitest

2.2) ถ้าต้องการทำต่อเป็นไฟล์ postscript (.ps) ใช้คำสั่ง dvips สามารถส่งออกเครื่องพิมพ์ที่มี postscript ได้ทันที หรือ จะเรียกดู โดยใช้ GhostScript/GhostView ก็ได้
dvips thaitest

2.3) หรือใช้ pdflatex เพื่อสร้างไฟล์ .pdf สามารถดูได้โดย acrobat reader
pdflatex thaitest

3) บางทีเพื่อความสะดวกในการเรียกใช้ swath พร้อมๆกับ latex โดยไม่ต้อง พิมพ์เยอะ เราอาจจะสร้าง batch file (swlatex.bat) แล้วเก็บไว้ใน PATH ที่ windows มองเห็น ตัวอย่างของไฟล์ swlatex ที่ใช้
--------------- cut here ----------------
@echo off
if NOT exist %1.ttx goto nottx
c:\swath\swath -f latex -d c:\swath\data < %1.ttx > %1.tex
goto latex

:nottx
echo No %1.ttx found!
goto exit

:latex
latex %1

:exit
--------------- cut here ----------------

เรียกใช้ตัวอย่างข้างต้นหลังจากสร้างไฟล์ thaitest.ttx เสร็จด้วยคำสั่ง
swlatex thaitest

ข้อควรระวัง
ไฟล์ .ttx และ .tex ที่สร้างขึ้นมาให้ใช้ text editor ธรรมดาเช่น notepad เป็นต้น ไม่ควรใช้ MS Word ในการสร้าง
ถ้าไม่แน่ใจไฟล์ unzip.exe ใช้โปรแกรม scan virus ตรวจดูก่อน