latex

LaTeX document class files for Chulalongkorn University's Thesis

I have posted updated LaTeX class files for theses and dissertation of Chulalongkorn University. However, I have not written a manual for it yet. Instead, I provide my own dissertation as an example. The files can be used for both master and doctoral degree and also for either Thai or English language.

Click here for the file.

MiKTeX update

I have updated Thai font installation on MiKTeX 2.6 and 2.7. Please check the original article.

Thai LaTeX on MikTeX 2.7

I haven't write any paper since about last 6 months. That covers the period when I changed my PC. That's a good time to update my MikTeX installation. Now, with MikTeX 2.7 in hand, I can review again the process of installing Thai language support.

-- side note --
You can look at my detailed previous entry here. There contains the information to install Thai language in MikTeX 2.6 and 2.5. The process is very similar to that of 2.7
-- end side note --

The process to install thai language in 2.6 and 2.7 are practically the same. The step are listed there

  1. Modify babel to recognize thai language
  2. Installing the font.

Font installing is complex. I have laid out the detail in the previous entry. However, this image should provide a rough idea of what to be done.

Finally, MikTeX 2.7 comes with XeTeX which allow you to use truetype font immediately. This solution is very promising. I will have more update on this very soon.(only partially) what to have Thai language available on miktex.

MikTeX Thai Font Installation GuideMikTeX Thai Font Installation Guide

Mini-HOWTO: Thai Language Support for LaTeX in Windows, using MiKTeX 2.5 (and 2.6 and 2.7)

--- 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.

MikTeX Thai Font Installation GuideMikTeX Thai Font Installation Guide

--- 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.
1. Enable Thai support by patching the babel package.
2. 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\ and c:\thailatex-0.4.0\babel\ 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\ 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\, 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\.

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.

Latex DocClose applet

LaTeX is a de facto standard for most academic publications. Just like an html, a LaTeX document is a plain text file which could be edited by any text editor of our choice. Some editors stand out for being tailored specifically for LaTeX. One nice free (as in a free beer, but not quite as in Free Speech) is LEd (LaTeX Editor). However, LEd lacks one tiny feature that I need most. It is very irritating when I compile a LaTeX document using pdfLaTeX to know that I didn't close the last revision pdf in the acrobat first. This would make pdfLaTeX complain to me that it could not write to the pdf file because Acrobat wouldn't allow so.

The obvious solution is to close the document in the Acrobat first and it would be really nice if LEd could do this for me. Other editor can do this, for example, WinEdt. However, as I stated in my previous post, Acrobat already allow us to close the opened document using DDE. So I modified the example from the acrobat SDK to get this little applet that can open and close pdf file.

To use the program, just run it with one parameter, the file name of the pdf file and the document will be closed. For example,

acroddeclose c:\test.pdf

would close the file (if it has been opened). If we put any other argument following the file name, it will open the file (if it has not been opened yet). For example,

acroddeclose c:\test.pdf 1

will open the file.

The application and the source code could be d/l here.

Now, to integrate this into LEd, we need to modify the script of LEd. Luckily, LEd makes it very easy to do so. Everything is stored in a text-based script file. First, we need LEd to supply us with the full file name. We have to look for the main script file, located at Definitions\tex_cmd.gd. This file controls the shortcut, bitmap image, label, hint, etc., of the script that appears on the toolbar of LEd. Most importantly, it controls the parameters that are passed to each script file. Locating the following line in the file.

11007=11007=F7=PDFLaTeX=/l53007/l=exec:pdflatex.bat <MAINFILEDIR> <MAINFILENAMEEXT> <MAINFILEDISK>

This line controls how pdfLaTeX.bat should be run. Be noted that your actual text might be different from me but what we have to look for is the line containing the word exec:pdflatex.bat. Now, as you could see, file directory, file name and the drive is already supplied to the pdflatex.bat. However, what we need is the full file name with path, which LEd kindly provides us already. Simply append the code to the line so that the forth parameter given to pdflatex.bat would be the full path. The line should be something like this now.

11007=11007=F7=PDFLaTeX=/l53007/l=exec:pdflatex.bat <MAINFILEDIR> <MAINFILENAMEEXT> <MAINFILEDISK> <MAINFILE>

Next, we have to modify the batch file script for pdfLaTeX. Locating the file Batches\PdfLaTeX.bat inside the LEd directory and add our program so that it closes the pdf file before compiling the document and opens the file after the compilation is done.

The new pdflatex.bat should look like this.

rem @echo off
AcroDdeClose.exe %4
%3
cd %1
pdflatex.exe %2
pdflatex.exe %2
AcroDdeClose.exe %4 1

That's all.

Another embedded subset problem

In my latex installation, \bigcup produces pdf using F73 fonts!!!, it is Type 3 and I don't know how to make it become embedded subset.

-- UPDATED --

The way to fix this problem is to use the option [cmex10] for the amsmath package. It is stated in the new version (1.7) of the IEEE transaction template by Michael Shell.

In short, just use

\usepackage[cmex10]{amsmath}

Acrobat Inter Application Communication

Writing a latex document differs much from any other word processing program. It is just like writing a program. I feel much better when there is an IDE for a particular language I am using. Agreed, many can go without IDE. Take Mr. Wood, for example, he always babbling teases me and said that emacs or vi is the best. Well, not for me. Those editors are nice but that is not enough. Though emacs is easily extensible, I don't want to spend my time there. EditPlus is also nice, I used it to write latex for my master thesis but that is also not enough.

So, I search amongst readily available latex editor. WinEdt is my long time favorite since I started my Ph.D. but it is not gratis (finger crossed). And there come many others. Latex Editor (LEd) is a good one, not open source but a freeware. However, the big problem is that, when you use pdflatex and the document is already open, it always complain, when you are compiling, that the document cannot be written. The problem is caused by Acrobat, since it lock the file. WinEdt solves this problem by closing the document in Acrobat before compile. WinEdt do so by a mean of DDE. but LEd can't do the same.

However, LEd support user command (just like edit plus), so, I have to write a program to close a specific document in Acrobat.

Adobe provides SDK for Acrobat and there is a very very easy way to communicate with Acrobat, via DDE.

Just send [DocClose("filename")], to the DDE server of acroview, and the document is closed... However, the document must be manipulable by DDE. If you simply open the document, the document is immanipulable. To rectify this problem, simply send [DocOpen("filename")] and the document will be added to the DDE manipulable list.

That's all.

Figure in pdfLaTeX finally

ในที่สุดก็หาเจอตัวเนียน ๆ ...
นี่เลย IPE interface หน้าตา่แปลก ๆ หน่อย แต่จะคล้าย ๆ กับ xfig, jfig, winfig. ตัว concept จะเหมือน ๆ กัน ที่เด่นสุด ๆ คือ มัน export ออกมาเป็น pdf ได้อย่าง perfect, font นี่เป็น type 1 แถมขนาดก็ crop ให้เท่ากับขนาดของ drawing และเป็น vector ด้วย ไม่ใช่ rasterize

format input ที่รับมันบอกว่าเปิด eps,ps,pdf ได้ แต่ว่าลองเอามาเปิดกลับไม่ได้สักอัน ต้องใช้อันที่ ipe เป็นคน save มาถึงจะใช้ได้... แต่.. แต่.. นี่เลย มันให้ figtoipe มาให้ โห.. เนียนสุด ๆ แปลง fig เป็น format ของมันไ้ด้ (เสียดายไม่มี ipetofig)

ความเนียนสุด ๆ คือยัด latex ลงไปได้เลย เขียนอะไรลงไปก็ได้ แล้วสุดท้ายมันจะใช้ latex compile ให้อีกที เพราะงั้นจะเนียนกว่า jfig

ipe มีระบบ plugin ด้วย เรียกว่า ipelet ตัว default ที่ให้มาก็มีสร้าง n-gon , rotate in arbitrary degree, delaunay triangulation, voronoi diagram, อ้อ ๆ มี convex clipping ด้วย โอวแย้ดดดด...

ข้อเสียที่หาเจอมีอย่างเีดียว มันไม่ support pattern คือจะระบายเส้นทะแยง เส้นแนวตั้งงี้ไม่ได้ ต้องใส่สีเอาอย่างเดียว

ส่วนเรื่อง epstopdf... พึ่งจะรู้ตัวว่า miktex มันมี epstopdf.exe มาให้ใช้ไ้ด้เลย โง่จริง ๆ เรา เวลาใช้ gnuplot ก็ set term เป็น postscript eps แล้วเอามาผ่าน epstopdf ก็จะเอาไปใช้ใน pdflatex ได้เลย.. หึม ๆ เนียน ๆ

ปั่น icra ต่อ....

Latex

อึม ๆ หันมาใช้ pdflatex กันเถอะ

ปัญหามีแค่ตอน includegraphics

อ่านซะ
http://www.2pi.info/latex/Includingeps.html

อึม ๆ โดยรวม ๆ แล้วก็มันใช้ได้เหมือนกับ latex ทุก ๆ อย่าง
ต่างกันหน่อยตรงเวลา includegraphics ให้ใช้ practice ใหม่ ไม่ต้องใส่ extension ของไฟล์
และ file ที่ include ต้องเป็น pdf ไฟล์ (eps ใช้ไม่ได้)

ถ้าไม่ใส่ extension pdflatex มันจะหา .pdf เป็น default อยู่แล้ว อ้อ ๆ เห็นว่าใช้ .jpg ได้ด้วยเลยทันที

หัดใช้ \usepackage{hyperref} ด้วย มันจะทำ link ใน pdf file ให้อัตโนมัติ

เวลาใช้รูปต้องเป็นรูปแบบ pdf
photoshop กะ illust มันแปลงเป็น pdf ให้ได้อยู่แล้ว หัดใช้ซะ

trick อื่น ๆ ให้ไปลองอ่านใน FAQ ของ pdflatex http://www.tug.org/applications/pdftex/

ICRA, finally.. (fighting with jfig, eps, gs, etc.)

ICRA is almost finished and so is the deadline. We still doing a last proofreading. However, there are a lots of problem in preparing a PDF. First, IEEE requires that all font is embedded. There are some problem in my Distiller, I can not make the .joboptions file from IEEE to work with my Distiller. It keep s saying that the font "Times-Roman" can not be found in the system. I change to GSView to convert my ps to pdf but still, the result pdf does not have "Times-Roman" embedded in. Okey, the problem might be my machine but no other machine in our lab has MikTex or GSView. I change to linux and use ps2pdf to convert. The correct option is

ps2pdf -dCompatibilityLevel=1.3 -dMAxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sPAPERSIZE=a4 <span class="caps">DRAFT1</span>.ps

However, we still have more problem. JFIG has some bug when rendering the EPS. (Or that is what I think)

Syndicate content