--- updated ---
- MikTeX 2.6 I have tried this also on MiKTeX 2.6 and everything works just fine, except that some files have to be put on different directory, see the bottom of the article
- MikTeX 2.7 I also tried this on MikTeX 2.7 and the step is still the same as 2.6.
- I also added a figure roughly showing what you have to do, exclude the modification to the existing miktex file.
[img_assist|nid=2044|title=MikTeX Thai Font Installation Guide|desc=|link=node|align=left|width=640|height=415]
--- end of update ---
There are several pressing requests given to me to describe the process needed to enable Thai support on LaTeX for Windows (in MiKTeX), a topic I wish to cover in the upcoming LaTeX guide series. I will publish a quick and dirty method on the blog first and it will be refined and included in the series later.
Please note that if you are running MiKTeX version 2.4, which is now out-of-date and no longer available in the MiKTeX site, the easiest way is to use the MiKTeX Thai Extension which is extremely easy to setup. The package cannot be used in MiKTeX 2.5 nor 2.6.
For those who just want to get the thing done, I recommend you to consult this page (in Thai) at the school of physics, Suranaree University. You will find everything you need to start using Thai in TeX, described in an easy step-by-step manner.
However, if you wish to do things manually, starting from a minimal set of input and work your way to the actual installation of the font file, please read along.
These step is generic and should works on all distribution of LaTeX, providing that the file is put to there respective folder (which, sadly, differs from distro to distro).
Basically, you have to do two things.
- Enable Thai support by patching the
babel
package. - Install Thai font to MikTeX.
First, you will need thailatex package. Please download the source package. As of May 2007, the latest version of the package is 0.4.0-1. This package includes Thai Font and babel package patching.
Optionally, you will also need sed
, a stream editor. With sed, the installation process becomes much more easier.
This guide is tested against MiKTeX version 2.5 on Windows XP.
The first thing to do after obtaining the thailatex source package is to extract it somewhere, says c:\thailatex-0.4.0
. After that, you have to follow these steps.
#1. Enable Thai Support in Babel Babel is a package for multilingual support in LaTeX. Sadly, the standard distribution of babel does not include Thai. Dr. Surapant Meknavin, then a researcher at NECTEC, created the first version of Thai Language Definition File to be used as a part of babel package. After that, the file is maintained by Theppitak, Poonlap and Chanop, subsequently.
To enable Thai in babel you will need the following files.
thai.sty
thswitch.sty
lthenc.def
thai.ldf
The style files (.sty) and encoding file (.def) come already with the thailatex
. They should be located in c:\thailatex-0.4.0\babel
. The Language Definition File (.ldf) is to be generated from the source file, thai.dtx
by executing this command, in the same folder as the thai.dtx
.
c:\thailatex-0.4.0\babel\>latex thai.ins
Now, you should put these files into the babel folder of your MikTex installation, presumably to be at C:\Program Files\MiKTeX 2.5\tex\generic\babel
.
c:\thailatex-0.4.0\babel\>copy *.sty "C:\Program Files\MiKTeX 2.5\tex\generic\babel"
c:\thailatex-0.4.0\babel\>copy lthenc.def "C:\Program Files\MiKTeX 2.5\tex\generic\babel"
c:\thailatex-0.4.0\babel\>copy thai.ldf "C:\Program Files\MiKTeX 2.5\tex\generic\babel"
Next, we have to patch the original babel package to recognize Thai language. Edit C:\Program Files\MiKTeX 2.5\tex\generic\babel\babel.sty
by your favorite text editor. Add the following line to the file.
\DeclareOption{thai}{\input{thai.ldf}}
The line should be added in the "declare option" part, i.e., it should be inserted beside the other \DeclareOption
lines. Since the options in the file are originally sorted by language, it is nice to put our line next to Turkish option. Simply add the line after this line.
\DeclareOption{turkish}{\input{turkish.ldf}}.
Now, babel package knows Thai language. The next step is to install Thai font to MikTeX.
#2. Font Installation
Font installation in TeX is quite a pain. There is no one-click step that just put the font up and running like installing font in Windows. I would recommend you to read the documentation of FONTINST
for an insight on the font mechanism of TeX. Let us proceed to the installation of font.
Font comes in various format, most notably, Type 1 Font and True Type font. For Windows users, True Type is ubiquitous. However, TeX was created in *nix platform where Type 1 is more common. Type 1 is usually distributed into two files, .pfb
file (sometime disguised as .pfa
) and .afm
file. The .pfb
is the actual Type 1 font containing the description of a font in terms of a Bezier curve, while .afm
is an Adobe Font Matric which contain information about size, ligature, of each curve.
Starting from these two files, we will construct .tfm
(TeX Font Metrics) which is used by TeX and .vf
(virtual font) which is used by DVI driver to actually render the font. To create a .vf
file, we need immediate format .vpl
(virtual property list). The .vpl
is not need by TeX and can be deleted afterward.
Apart from the font itself, we still requires more information about the font. We need LaTeX encoding file and font encoding file. The first one maps TeX character into a slot, or a numbered representation of a glyph and the latter maps slot into an actual glyph in the font. Both type of files come already with thailatex
package. The LaTeX encoding file is available in c:\thailatex-0.4.0\fonts</code> and
c:\thailatex-0.4.0\babel</code> as
lthenc.def
while font encoding files are available at c:\thailatex-0.4.0\fonts*.fd
.
At this stage, we know what we need and what we have. We then proceed to produce what we need from what we have and then put everything required into its proper place in the MiKTeX distribution. Here is the procedure for doing so.
2.1 Create a .vpl file and .tfm file 2.2 Create a .vf file 2.3 Put the generated font files into the appropriate directories 2.4 Put the encoding file into the appropriate directory 2.5 Put the font definition file for babel package 2.6 Create a font mapping file and put it into appropriate directory 2.7 Update MiKTeX database.
For our illustrative purpose, we will assume that our type 1 font file is norasi.afm
. Be noted that we must do all of these on every type 1 font file.
2.1 Create a .vpl file and .tfm file
First, we construct a "raw" TeX font metrics file and a virtual property list from Type 1 file. Then, we construct a mapped TeX font metrics file and a property list file from a virtual property list file. We will use norasi
font for our example. Run the following command in c:\thailatex-0.4.0\fonts</code> folder.
afm2tfm norasi.afm -v norasi.vpl -T lthuni.enc rnorasi.tfm
The -T
argument indicates the font encoding file used to create the output file. Be noted that the raw .tfm
file begins with letter r. The font encoding file lthuni.enc
is already available with the thailatex
at c:\thailatex-0.4.0\fonts</code>, for your convenience.
2.2 Create a .vf file
Next, we construct the virtual font file and a mapped TeX font metrics file. Execute the following command in the same folder.
vptovf norasi.vpl norasi.vf norasi.tfm
2.3 Put the generated font files into the appropriate directories
Now, we have all font files we need. Let put them into the appropriate place. First, put all font files in their respective folder.
copy norasi.afm "C:\Program Files\MiKTeX 2.5\fonts\afm\public\thai"
copy norasi.vf "C:\Program Files\MiKTeX 2.5\fonts\vf\public\thai"
copy norasi.tfm "C:\Program Files\MiKTeX 2.5\fonts\tfm\public\thai"
copy rnorasi.tfm "C:\Program Files\MiKTeX 2.5\fonts\tfm\public\thai"
copy norasi.pfb "C:\Program Files\MiKTeX 2.5\fonts\type1\public\thai"
2.4 Put the encoding file into the appropriate directory
Next, we put an encoding file to their respective folder also.
copy lthuni.enc "C:\Program Files\MiKTeX 2.5\fonts\map\dvips\thai"
2.5 Put the font definition file for babel package
We also need to put the font definition file to the babel package folder. The font definition which involves in LaTeX encoding is already given in the thailatex
package and is located in c:\thailatex-0.4.0\babel</code>.
cd c:\thailatex-0.4.0\babel\
copy lthnorasi.fd "C:\Program Files\MiKTeX 2.5\tex\generic\babel"
2.6 Create a font mapping file and put it into appropriate directory
The last thing is to tell dvips that we have the font for it and it is mapped with the specific TeX font. This involves several step. To do this, we create a text file using any text editor and name it as Thai.map
. The file should have this line.
rnorasi Norasi " LTHEncoding ReEncodeFont " <lthuni.enc <norasi.pfb
Now, a vigilant reader might notice that the screen output of afm2tfm
is almost the same as the above line, except that it does not have the last part, "<norasi.pfb". So, if we manage to append this string to the output file it would be very convenient. I would recommend two options to produce Thai.map file. The first option is for a user having "sed" tools. This is a little bit faster. However, if you don't have sed, that is still alright. Please use the second option instead.
OPTION_1: for sed user (if you don't have sed or have no idea what it is, please use OPTION_2)
This is where the optional sed
comes in handy. When we create the virtual property list using afm2tfm
, we pipe the screen output to for immediate concatination, using this command instead.
afm2tfm norasi.afm -v norasi.vpl -T lthuni.enc rnorasi.tfm | sed "s/$/ <norasi.pfb/" >> thai.map
This line will create a file thai.map
which contain the line we need.
WARNING!!!! be noted that sed
that is built natively for windows might produce *nix style end of line which render the line to be incorrect. I recommend using sed
that comes with cygwin
. A quick work around would be using the last words in the line instead of end-of-line symbol.
The generating of each required file is necessary for every font. Please make sure that all font files have undergo
ne this step, so that thai.map
includes all information. The following batch file would run the script on all font files and utilize sed. You still need to copy each font file to the appropriate location.
del thai.map
FOR %%I IN (*.afm) DO afm2tfm %%I -v %%~nI.vpl -T lthuni.enc r%%~nI.tfm | sed -e "s/enc/enc <%%~nI.pfb/" >> thai.map
FOR %%I IN (*.vpl) DO vptovf %%I %%~nI.vf %%~nI.tfm
OPTION2: for non-sed user
Even without sed, we could do that by running a batch file containing these lines.
del thai.map
FOR %%I IN (*.afm) DO afm2tfm %%I -v %%~nI.vpl -T lthuni.enc r%%~nI.tfm >> thai.map
FOR %%I IN (*.vpl) DO vptovf %%I %%~nI.vf %%~nI.tfm
This is almost the same as in the OPTION_1 except that the "sed" part is omitted. So, we have to do this manually. For every line in the Thai.map generated from the above batch file, you have to append xxx.tfm where xxx is the name of the original font file. If you happen to have any text editor that supports regex you could do find&replace using the following regex command.
FIND strings
(r(.+)\ .+\ \"\ .+<lthuni.enc)
REPLACE strings
\1 <\2.pfb
No matter which option we take, we have to put this "mapping" file to MiKTeX distribution.
copy thai.map "C:\Program Files\MiKTeX 2.5\fonts\map\dvips\thai"
DON'T FORGET THAT the directory is not the same for MiKTeX 2.6 and 2.7, please check the bottom of this article.
2.7 Update MiKTeX database.
This going to be our real final step. Now, make sure that all font related files (*.afm, *.vf, *.tfm, *.pfb, *.fd, lthuni.enc) are put in the appropriated place. Finally, we let dvips know that we have this mapping file. This step is different from distribution to distribution. For MiKTeX 2.5 and 2.6, you can edit the respective updmap.cfg file using this command.
initexmf --edit-config-file updmap
And put this line into the file.
Map thai.map
Finally, let the MiKTeX refersh its file database and making the map file using the following command.
updmap
initexmf -v --mkmaps -u
Now, MiKTeX understands thai font and can use thai. You can test the system by compiling the teststd.tex
file available at c:\thailatex-0.4.0\doc
. You can also delete the entire c:\thailatex-0.4.0
folder since we no longer need it.
The only remaining problem is that LaTeX cannot break thai words since Thai sentence does not have space between each word. This problem can be solved by using seperate Thai word breaking utilies such as swath
by Paisarn or older cttex
by Hui.
Happy TeXing.
-------- updated --------
I have tried this on MikTeX 2.6 and MikTeX 2.7 and it seems like that I have to put lthuni.enc
and thai.map
at C:\Program Files\MiKTeX 2.*\dvips\base
instead of C:\Program Files\MiKTeX 2.x\fonts\map\dvips\thai
.
- Log in to post comments
I have a question about the
please be sure that latex is
Sawatdee Khrap, I was trying
To my surprise I seem to
Any suggestions anyone?
The solution to my query a