Thursday, September 07, 2006

A nice tool - PSfrag for Eps file

We need to translate the English in .eps files into Chinese. I find a nice tool to tackle this problem, called PSfrag. In the following, I will present the steps:

1. In the preamble of latex file, add the following:

\usepackage{psfrag}

2. Wherever there is a \DBfigure (I have redefined it in the cjkpre.tex to support Chinese), specify the substitution in the following forms before \DBfigure:

\psfrag{declared}{\tiny{\bf 声明的}}
\psfrag{named}{\tiny{\bf 命名}}
\psfrag{variable}{\tiny{\bf 变量}}
\psfrag{Four dynamically allocated records: }{\tiny{\bf 四个动态分配的记
录:}}
\DBfigure{../volI/1ch20/\pt{}{L}1ch20-nyref-fig}% F:60, B:40
{动态分配的数据结构}%
{ch7.ny.ref}

Trick: a. Use any text editor to open the xxx.eps file, locate the string in the ps command. Note that only those strings that are enclosed by "(...)" can be substituted. Even the space char after "A sentinel variable named:" must be specified and thus we have "A sentinel variable named: "(note the space after ":").

/Helvetica-Bold ff 270.00 scf sf
6375 6975 m
gs 1 -1 sc (A sentinel variable named: ) dup sw pop neg 0 rm col0 sh gr
/Helvetica-Narrow-Bold ff 270.00 scf sf
5000 6975 m
gs 1 -1 sc (pv) col0 sh gr
/Helvetica-Bold ff 240.00 scf sf
5850 4275 m
gs 1 -1 sc (dynamically allocated) col0 sh gr
/Helvetica-Bold ff 240.00 scf sf
5850 4575 m
gs 1 -1 sc (unnamed, but) col0 sh gr
/Helvetica-Bold ff 240.00 scf sf

b. The pair like 5850 4575 means the x and y coordinates. You can freely change them to adjust the position in the picture to get a nice result.

3. Enclose the above code fragment into the environment psfrags:

\begin{psfrags}
\psfrag{declared}{\tiny{\bf 声明的}}
\psfrag{named}{\tiny{\bf 命名}}
\psfrag{variable}{\tiny{\bf 变量}}
\DBfigure{../volI/1ch20/\pt{}{L}1ch20-nyref-fig}% F:60, B:40
{动态分配的数据结构}%
{ch7.ny.ref}
\end{psfrags}

The intention is to make the global effective commnd \psfrag into local effective ones inside the environment psfrags.

4. Compile file and see the result.
a. latex xxx.tex.
b. dvips xxx.dvi
c. see the result in .ps version.

1 Comments:

At 12:18 AM , Blogger Jianwen Xiang said...

This method is too "complicated", I thus strongly recommend not using it. As an alternative, I recommend to use some vector graphicial tools (software), such as Adobe Illustrator.

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home