Sci­en­tific Graph­ics Visu­al­i­sa­tion: An In­tro­duc­tion to PSTricks

To con­clude the se­ries of three ar­ti­cles on Sci­en­tific Graph­ics Visu­al­i­sa­tion, let us ex­plore PSTricks, a set of macros that al­lows the in­clu­sion of PostScript draw­ings di­rectly in Tex or La­TeX.

OpenSource For You - - Contents - By: Deepu Ben­son The au­thor is a free soft­ware en­thu­si­ast and his area of in­ter­est is the­o­ret­i­cal com­puter sci­ence. He main­tains a tech­ni­cal blog at www.com­put­ing­for­be­gin­ners.blogspot.in and can be reached at deep­umb@hot­mail.com.

In this ar­ti­cle, we will dis­cuss PSTricks, a tool used for em­bed­ding PostScript graph­ics di­rectly into La­TeX doc­u­ments. PSTricks has cer­tain draw­backs like lim­ited out­put for­mats and in­com­pat­i­bil­ity with cer­tain La­TeX tools. The im­mense power of­fered by PostScript, how­ever, makes it ab­so­lutely nec­es­sary for us to ex­plore PSTricks. But be­fore that, we need to dis­cuss PostScript a bit.

What is PostScript?

PostScript (PS) is a page de­scrip­tion lan­guage de­vel­oped by Adobe Sys­tems. Be­fore the de­vel­op­ment of PostScript, plot­ters were used to print vec­tor graph­ics, and prin­ters were used to print raster graph­ics. PostScript rev­o­lu­tionised both elec­tronic pub­lish­ing and desk­top pub­lish­ing by al­low­ing a sin­gle ma­chine to han­dle both vec­tor graph­ics and raster graph­ics, thus al­low­ing high qual­ity text and images to be for­mat­ted in a sin­gle page. Con­sider the file post1.ps with the code shown be­low:

new­path

200 200 moveto 300 200 lineto 300 300 lineto 200 300 lineto 200 200 lineto 2 set­linewidth stroke

The ex­act mean­ing of this PostScript code is not im­por­tant, but learn­ing how this code works will help us un­der­stand and ap­pre­ci­ate the ad­van­tages of PostScript and sim­i­lar lan­guages. Open the file post1.ps with a doc­u­ment viewer ca­pa­ble of dis­play­ing PostScript. You will see the im­age of a square. Later in the ar­ti­cle, when we ob­tain more PostScript files as out­put of La­TeX scripts, you can open those PostScript files to see hu­man-read­able code sim­i­lar to what we have seen now, but much more com­pli­cated. So, this is the phi­los­o­phy of PostScript — a pro­gram­ming lan­guage is used to de­scribe the im­age and a doc­u­ment viewer in­ter­prets that code to dis­play the im­age. So, even if a PostScript file might ap­pear like a page con­tain­ing text and images, it ac­tu­ally is a file con­tain­ing pro­gram code.

This ap­proach has led to the huge suc­cess of PostScript and sim­i­lar page de­scrip­tion lan­guages. Due to the im­mense pop­u­lar­ity of PostScript, PSTricks was de­vel­oped as a layer on top of it. Even though the most pop­u­lar im­ple­men­ta­tion of PostScript is Adobe PostScript, there is also an open source im­ple­men­ta­tion of PostScript called Ghostscript, li­censed un­der the GNU Af­fero Gen­eral Pub­lic Li­cense.

An in­tro­duc­tion to PSTricks

PSTricks al­lows us to in­clude PostScript images di­rectly into La­TeX and TeX doc­u­ments. Un­like PGF/TikZ, which is a pro­gram­ming lan­guage in it­self, PSTricks is a set of macros built over the lan­guage PostScript. PSTricks was orig­i­nally de­vel­oped by Ti­mothy Van Zandt. High qual­ity vec­tor graph­ics images can be pro­duced by us­ing PSTricks. Vec­tor graph­ics clearly out­per­form raster graph­ics as far as tech­ni­cal di­a­grams are con­cerned.

Both the ad­van­tage and dis­ad­van­tage of PSTricks is its de­pen­dence on PostScript. PSTricks is very pow­er­ful and ca­pa­ble of pro­duc­ing even com­plex di­a­grams due to the power of the un­der­ly­ing PostScript lan­guage and be­cause of this, PSTricks is more pow­er­ful in com­par­i­son to PGF/TikZ. But then, this over-de­pen­dence on PostScript re­sults in a re­stricted set of out­put for­mats for PSTricks.

In most im­ple­men­ta­tions, the only out­put for­mat avail­able with PSTricks is PostScript. This again leads to fur­ther disad­van­tages in PSTricks like the in­abil­ity to work with cer­tain soft­ware as­so­ci­ated with La­TeX like pdfLaTeX, pdfTeX, etc. So, it is a bit dif­fi­cult to ob­tain PDF out­put files di­rectly from La­TeX files con­tain­ing PSTricks code. There are ways to work around this and hacks to overcome this prob­lem also. For ex­am­ple, pdfLaTeX can be used to process La­TeX files con­tain­ing PSTricks with the help of a pack­age called auto-pst-pdf. But this is an ugly so­lu­tion and a bet­ter op­tion is to use XeLaTeX in­stead of pdfLaTeX.

XeLaTeX is a re­place­ment for pdfLaTeX, de­vel­oped to overcome cer­tain prob­lems as­so­ci­ated with pdfLaTeX. Even though such so­lu­tions are avail­able, we will be dis­cussing two easy meth­ods to process La­TeX files con­tain­ing

PSTricks code, one in­volv­ing the Linux ter­mi­nal and the other in­volv­ing Tex­maker, a La­TeX editor. In both these tech­niques, we di­rectly pro­duce out­put files in a for­mat other than PDF (Por­ta­ble Doc­u­ment For­mat) and then use some sim­ple tools to con­vert those files into PDF for­mat. Whether you use the ter­mi­nal or Tex­maker, the for­mat­ted text in the out­put doc­u­ment will be the same. As a side note, XeLaTeX is avail­able in Tex­maker.

A sim­ple PSTricks ex­am­ple

Be­fore mov­ing on to our first PSTricks ex­am­ple, con­sider the sim­ple La­TeX tem­plate shown be­low, which was in­tro­duced in the pre­vi­ous ar­ti­cle that dis­cussed PGF/TikZ.

\doc­u­ment­class{ar­ti­cle}

\be­gin{doc­u­ment}

% Here you can em­bed your PSTricks code \end{doc­u­ment}

Just like PGF/TikZ code, all our PSTricks code will also be em­bed­ded in­side this min­i­mal La­TeX code for fur­ther pro­cess­ing. The PSTricks code in­side the doc­u­ment en­vi­ron­ment of La­TeX is marked by the lines of code ‘\be­gin{doc­u­ment}’ and ‘\end{doc­u­ment}’. In the given La­TeX tem­plate, we only have a com­ment shown by the fol­low­ing line of code:

% Here you can em­bed your PSTricks code

…in­side the doc­u­ment en­vi­ron­ment. Please note that La­TeX com­ments be­gin with a per­cent­age sym­bol and will not be dis­played in the fi­nal out­put doc­u­ment.

Some­times, it is bet­ter to study a new tool by com­par­ing its func­tion­al­i­ties with a tool with which we are fa­mil­iar. The ex­am­ples pro­vided in this ar­ti­cle are some­what sim­i­lar to the ones we have dis­cussed in the pre­vi­ous ar­ti­cle about PGF/TikZ. But re­mem­ber, even if you have missed our dis­cus­sion about PGF/TikZ, it will in no way af­fect your learn­ing of PSTricks. Now con­sider the sim­ple La­TeX file pstricks1.tex shown be­low con­tain­ing PSTricks code, which draws two rec­tan­gles—just like our PGF/TikZ ex­am­ple. This and all the other scripts dis­cussed in this ar­ti­cle are avail­able for down­load from open­source­foru.com/ar­ti­cle_­source_­code/June18PSTricks.zip.

\doc­u­ment­class{ar­ti­cle}

\usep­a­ck­age{pstricks}

\be­gin{doc­u­ment}

\be­gin{pspic­ture}(15,15)

\psline[line­color=blue,linewidth=1pt](1,1)(5,1)(5,7) (1,7)(1,1) \pspoly­gon[line­color=red,linewidth=8pt](6,1)(10,1) (10,7)(6,7)

\end{pspic­ture}

\end{doc­u­ment}

The Carte­sian co­or­di­nate sys­tem of PSTricks is sim­i­lar to that of PGF/TikZ. The ori­gin de­noted by (0,0) can be con­sid­ered to be lo­cated at the bot­tom-left cor­ner of the plane when dis­played on the screen, which is sim­i­lar to PGF/TikZ. The dis­tance of any com­po­nent can be mea­sured in the num­ber of pix­els called points or in SI units of dis­tance, say a me­tre or cen­time­tre.

Now let us try to un­der­stand the work­ing of the file pstricks1.tex. The sec­ond line of code ‘\usep­a­ck­age{pstricks}’ makes sure that the func­tion­al­i­ties of PSTricks can be used in this La­TeX script. As men­tioned ear­lier, all the PSTricks code in a La­TeX script should be em­bed­ded in­side the doc­u­ment en­vi­ron­ment of La­TeX marked by the com­mands ‘\be­gin{doc­u­ment}’ and ‘\end{doc­u­ment}’. All the PSTricks code to draw spe­cific images in your La­TeX doc­u­ment should be em­bed­ded in­side the pspic­ture en­vi­ron­ment marked by the com­mands ‘\be­gin{pspic­ture}(15,15)’ and ‘\end{pspic­ture}’.

The code frag­ment (15,15) de­notes the top-right cor­ner of the rec­tan­gle in which the PSTricks im­age will be drawn. The bot­tom-left cor­ner can also be spec­i­fied but, in this case, the de­fault value of (0,0) is taken as this pa­ram­e­ter. It is pos­si­ble to have any num­ber of pspic­ture en­vi­ron­ments in­side the doc­u­ment en­vi­ron­ment of La­TeX — mean­ing a La­TeX doc­u­ment can con­tain any num­ber of PSTricks images. The fol­low­ing line of code:

\psline[line­color=blue,linewidth=1pt](1,1)(5,1)(5,7)(1,7) (1,1)

…draws five lines. The first line is drawn from point (1,1) to point (5,1), fol­lowed by a line from point (5,1) to point (5,7), fol­lowed by a line from point (5,7) to point (1,7) and, fi­nally, a line from point (1,7) to the start­ing point (1,1) so that a rec­tan­gle is drawn. The code frag­ment:

[line­color=blue,linewidth=1pt]

…sets the colour of the line to blue, and sets the line width to one point.

The line of code:

\pspoly­gon[line­color=red,linewidth=8pt](6,1)(10,1)(10,7) (6,7)

…draws a poly­gon with five sides. The first line is drawn from point (6,1) to point (10,1), fol­lowed by a line from point (10,1) to point (10,7), fol­lowed by a line from point (10,7) to point (6,7) and since a poly­gon is closed, fi­nally a line is drawn from point (6,7) to point (6,1) to com­plete the

rec­tan­gle. You can use the func­tion pspoly­gon to draw poly­gons with any num­ber of sides. The code frag­ment:

[line­color=red,linewidth=8pt]

…sets the colour of the line to red and sets the line width to eight points. As a re­sult, the red rec­tan­gle will be drawn with thick lines, whereas the blue rec­tan­gle will be drawn with thin lines.

Now that we are fa­mil­iar with the code, it is time to ex­e­cute and view the out­put doc­u­ment. As men­tioned ear­lier, we will dis­cuss two meth­ods to ob­tain out­put from a La­TeX file con­tain­ing PSTricks code. The first method uses a La­TeX editor called Tex­maker — or any other La­TeX editor for that mat­ter. Open the La­TeX file pstricks1.tex in Tex­maker and from the menu, choose Tools>La­TeX to ex­e­cute pstricks1.tex to ob­tain the out­put file pstricks1.dvi. Even if you are us­ing an­other La­TeX editor, you will still be able to use the tool La­TeX to process the La­TeX file — the rea­son is sim­ple: any La­TeX editor will at least of­fer La­TeX as a tool if noth­ing more.

We have al­ready dis­cussed files with ex­ten­sion dvi (de­vice in­de­pen­dent file for­mat) in the pre­vi­ous ar­ti­cle on PGF/TikZ. We are all in need of PDF out­puts but con­vert­ing a DVI file con­tain­ing PostScript di­rectly to PDF will lead to er­rors. So, the trick is to con­vert the DVI file first to a PostScript file with ex­ten­sion ps — for which we use a tool called dvips — and then con­vert this PostScript file to a PDF file — for which we use a tool called ps2pdf. All you need is Tex­maker.

To con­vert the DVI out­put file to PS for­mat, choose and ex­e­cute Tools>Dvi->PS. Now, to con­vert this out­put file in PS for­mat to PDF for­mat, choose and ex­e­cute Tools>PS->PDF. For the re­main­ing part of this ar­ti­cle, we will only pro­duce DVI out­puts but, if nec­es­sary, the above two steps can be re­peated to ob­tain an out­put file in PDF for­mat. Af­ter the ex­e­cu­tion of these three steps, if you check the di­rec­tory con­tain­ing the La­TeX script pstricks1. tex, you will find three dif­fer­ent out­put files, all of which con­tain the im­age shown in Fig­ure 1. The out­put files are pstricks1.dvi, pstricks1.ps and pstricks1.pdf. But make sure that you have a doc­u­ment viewer ca­pa­ble of dis­play­ing all these for­mats and for this pur­pose, I rec­om­mend Oku­lar.

The other method to ob­tain the out­put file is to use the com­mands la­tex, dvips and ps2pdf di­rectly on the ter­mi­nal. Open a ter­mi­nal in the di­rec­tory con­tain­ing the file pstricks1. tex and ex­e­cute the com­mand ‘la­tex pstricks2.tex’ to ob­tain the out­put file pstricks1.dvi. Ex­e­cute the com­mand ‘dvips pstricks2.dvi’ to con­vert the file pstricks1.dvi to the out­put file pstricks1.ps in PostScript for­mat. Ex­e­cute the com­mand ‘ps2pdf pstricks2.ps’ to con­vert the file pstricks1.ps to the out­put file pstricks1.pdf in PDF for­mat.

Now let us un­der­stand the func­tion pspoly­gon bet­ter by mak­ing some slight mod­i­fi­ca­tions in the code of pstricks1.tex. What will be the out­put if the line of code:

\pspoly­gon[line­color=red, linewidth=8pt](6,1) (10,1)(10,7)(6,7)

in pstricks1.tex is re­placed with the line of code:

\pspoly­gon[line­color=red,linewidth=8pt](6,1) (10,7)(10,1)(6,7)

On ex­e­cu­tion with Tex­maker or in the ter­mi­nal us­ing com­mands, this mod­i­fied file called pstricks2.tex will pro­duce the out­put shown in Fig­ure 2. But why? Well, PSTricks has just fol­lowed your in­struc­tions — that’s all. A line is drawn from point (6,1) to point (10,7) – the for­ward slant­ing line go­ing up­ward; fol­lowed by a line from point (10,7) to point (10,1) — a ver­ti­cal line go­ing down­ward; fol­lowed by a line from point (10,1) to point (6,7) — the back­ward slant­ing line go­ing up­ward. And fi­nally, a line from point (6,7) to point (6,1) — a ver­ti­cal line go­ing down­ward. So, the script pstricks2.tex re­sults in the im­age shown in Fig­ure 2.

Draw­ing cir­cles with PSTricks

Let us try to draw a cir­cle us­ing PSTricks. Con­sider the La­TeX script pstricks3.tex shown be­low which draws a cir­cle and a square.

\doc­u­ment­class{ar­ti­cle}

\usep­a­ck­age{pstricks}

\be­gin{doc­u­ment}

\be­gin{pspic­ture}(15,15)

\pspoly­gon[line­color=red,fill­style=solid,fill­color=yell ow](1,1)(3,1)(3,3)(1,3)

\pscir­cle[line­color=blue,fill­style=solid,fill­color=gre en](2,2){1}

\end{pspic­ture}

\end{doc­u­ment}

Now let us go through the code in de­tail. In this script, all the lines of code are fa­mil­iar to us ex­cept for two lines which have been newly in­tro­duced. The line of code to draw the square is:

\pspoly­gon[line­color=red,fill­style=solid,fill­color=yel­low](1,1) (3,1)(3,3)(1,3)

This line draws a square that has sides of two units. The code frag­ment:

[line­color=red,fill­style=solid,fill­color=yel­low]

…sets the line colour to red and fills the in­side of the square with yel­low colour. We will dis­cuss fill­style and the other re­lated pa­ram­e­ters later. The line of code to draw the cir­cle is:

\pscir­cle[line­color=blue,fill­style=solid,fil lcolor=green](2,2){1} This line draws a cir­cle of ra­dius of one unit with the cen­tre at point (2,2). The code frag­ment:

[line­color=blue,fill­style=solid,fill­color=green]

…draws the cir­cle in blue colour and fills its in­te­rior with green colour. Since the di­am­e­ter of the cir­cle is two units and the sides of the square are also two units, the cir­cle is in­scribed in­side the square. On ex­e­cu­tion with Tex­maker or in ter­mi­nal us­ing com­mands, the file called pstricks3.tex will pro­duce the out­put shown in Fig­ure 3.

Now it is time for a sim­ple chal­lenge. Can you mod­ify the file pstricks3.tex to ob­tain the im­age shown in Fig­ure 4? All you need to do is make one or two mi­nor changes in the file pstricks3.tex. The first thing to do is in­crease the ra­dius of the green cir­cle. What is the re­quired ra­dius? Well, here we have a small math­e­mat­i­cal prob­lem. The di­am­e­ter of the re­quired cir­cle is √2 units be­cause the sides of the square are of size two units. Since √2 is an ir­ra­tional num­ber, we can’t get its ex­act value.

But we have all en­coun­tered this prob­lem dur­ing our school days — ‘in­scribe a square in­side a cir­cle’. How did we do it back then? Well, there are some Eu­clidean con­structs that give a good ap­prox­i­ma­tion for the value of √2. Let us also pro­ceed in the same man­ner; a good ap­prox­i­ma­tion for √2 is 1.414.

So, the ques­tion is this — if we re­place the line of code:

\pscir­cle[line­color=blue,fill­style=solid,fill­color=green](2,2){1} …in pstricks3.tex with the line of code:

\pscir­cle[line­color=blue,fill­style=solid,fill­color=green](2,2) {1.414}

…are we go­ing to get the re­quired im­age as out­put? The an­swer is, ‘No!’ If you do that mod­i­fi­ca­tion alone, you will see a cir­cle of ra­dius √2 drawn in blue colour filled with green colour. Why?

We en­coun­tered the same prob­lem when we dis­cussed PGF/TikZ. Both PGF/TikZ and PSTricks draw im­age com­po­nents in the or­der in which the cor­re­spond­ing code ap­pears in the script. Here, we have first drawn a square of sides 2cm and then we have drawn a cir­cle of ra­dius √2 over it; hence, the square is not vis­i­ble. So, the sec­ond change to make is to swap the or­der in which the square and the cir­cle are drawn. Then the re­quired im­age will be ob­tained in the out­put file. The mod­i­fied script pstricks4.tex is also avail­able for down­load.

Dif­fer­ent styles in PSTricks

So far, we have drawn images us­ing sim­ple lines alone. Now it is time for us to draw images in dif­fer­ent styles and pat­terns. Con­sider the La­TeX script pstricks5.tex shown be­low, which draws three cir­cles with dif­fer­ent fill styles, line styles and newly de­fined colours.

\doc­u­ment­class{ar­ti­cle}

\usep­a­ck­age{pstricks}

\be­gin{doc­u­ment}

\be­gin{pspic­ture}(15,15)

\ps­set{linewidth=0.05cm}

\newrg­b­color{col1}{1 1 0.7}

\newrg­b­color{col2}{0.7 1 1}

\newrg­b­color{col3}{1 0.7 1} \pscir­cle[linestyle=solid,line­color=red,fill­style=vline s*,fill­color=col1](2,2){1}

\pscir­cle[linestyle=dashed,line­color=green,fill­style=hl ines*,fill­color=col2](5,2){1}

\pscir­cle[linestyle=dot­ted,line­color=blue,fill­style=cro sshatch*,fill­color=col3](8,2){1}

\end{pspic­ture}

\end{doc­u­ment}

The line of code ‘\ps­set{linewidth=0.05cm}’ sets the line width to 0.05cm. The line of code ‘\newrg­b­color{col1}

{1 1 0.7}’ de­fines a new colour with name col1. A new colour is spec­i­fied by pro­vid­ing its RGB com­po­nents. The val­ues of the RGB com­po­nents should be be­tween 0 and 1. For ex­am­ple, {0, 0, 0} de­fines black colour and {1, 1, 1} de­fines white colour. The next two lines of code de­fine two more new colours named col2 and col3. The line of code ‘\pscir­cle[linestyle=soli d,line­color=red,fill­style=vlines*,fill­color=col1](2,2){1}’ draws a cir­cle with the bor­der in red solid line, filled with the colour de­fined by the vari­able col1 and with fill­style vlines* fill­ing the in­side of the cir­cle by draw­ing back­ward slant­ing lines.

The next line of code draws a cir­cle with a bor­der in a green dashed line, filled with the colour de­fined by the vari­able col2 and with fill­style hlines* fill­ing the in­side by draw­ing for­ward slant­ing lines. And the fol­low­ing line of code draws a cir­cle with the bor­der in a blue dot­ted line, filled with the colour de­fined by the vari­able col3 and with fill­style cross­hatch* fill­ing the in­side of the cir­cle by draw­ing a mesh. On ex­e­cut­ing the pro­gram, pstricks5.tex will pro­duce the im­age shown in Fig­ure 5 as out­put. Can you mod­ify the code in such a way that the filled colours of the cir­cles are yel­low, ma­genta and cyan? I will give you a hint. Adding red and green gives yel­low, adding red and blue gives ma­genta, and adding green and blue gives cyan. So, what should be the colour codes and where should we make the changes? If you

are un­able to get the an­swer to this prob­lem, please down­load and ex­e­cute the script pstricks6.tex.

Loops in PSTricks

You are tasked with de­vel­op­ing the net­work topol­ogy di­a­gram of your of­fice LAN. The di­a­gram uses a cir­cle to de­note a com­puter in your of­fice LAN and you are work­ing in a large com­pany with hun­dreds of com­put­ers. How will you draw the cir­cles in your di­a­gram? Well, you don’t have to draw each and every one of those cir­cles man­u­ally. PSTricks of­fers very pow­er­ful loop­ing and con­trol struc­tures to help you draw a large num­ber of sim­i­lar images very eas­ily. Con­sider the La­TeX file pstricks7.tex shown be­low:

\doc­u­ment­class{ar­ti­cle} \usep­a­ck­age{mul­tido} \usep­a­ck­age{pstricks} \be­gin{doc­u­ment} \be­gin{pspic­ture}(10,10) \mul­tido{\ia=0+1}{3}

{

\mul­tido{\ib=0+1}{3} { \rput(\ia,\ib){\pscir­cle[line­color=red,fill­style=sol id,fill­color=blue]{0.4}}

}

}

\end{pspic­ture}

\end{doc­u­ment}

Let us go through the code in de­tail to un­der­stand PSTricks loops bet­ter. There are dif­fer­ent ways to use loops in PSTricks, but we will dis­cuss only one such tech­nique which uses a macro called mul­tido. The line of code ‘\usep­a­ck­age{mul­tido}’ al­lows us to use the func­tion­al­i­ties of the macro mul­tido. The line of code ‘\mul­tido{\ia=0+1} {3}’ de­fines an outer loop that gets ex­e­cuted three times. Sim­i­larly, the line of code ‘\mul­tido{\ib=0+1}{3}’ de­fines an in­ner loop that gets ex­e­cuted three times. So the line of code ‘\rput(\ia,\ib){\pscir­cle[line­color=red,fill­style=solid, fill­color=blue]{0.4}}’ in­side the in­ner loop gets ex­e­cuted for a to­tal of nine times. The macro rput is used here to set the ref­er­ence point. In this case, the ref­er­ence points are spec­i­fied by the loop vari­ables ia and ib, both of which are ini­tialised to zero and get in­cre­mented by 1. Due to this rea­son, the cen­tres of the nine cir­cles with ra­dius of

0.4 units drawn by the code frag­ment ‘pscir­cle[line­color =red,fill­style=solid,fill­color=blue]{0.4}’ are dif­fer­ent. On ex­e­cut­ing the script, pstricks7.tex will pro­duce the im­age shown in Fig­ure 6 as out­put.

Now let us make a small mod­i­fi­ca­tion to the file pstricks7.tex to have a glimpse of the real power of PSTricks. The line of code:

\mul­tido{\ia=0+1}{3} …is re­placed with the line of code: \mul­tido{\ia=0+1}{10} …and the line of code: \mul­tido{\ib=0+1}{3} …is re­placed with the line of code: \mul­tido{\ib=0+1}{10}

… in pstricks7.tex to ob­tain the file pstricks8.tex. On ex­e­cu­tion, the script pstricks8.tex will pro­duce an im­age con­tain­ing 100 cir­cles, each with a ra­dius of 0.4 units.

All we did to change an im­age show­ing nine cir­cles to an im­age show­ing 100 cir­cles is mod­ify just two pa­ram­e­ters in maybe 30 sec­onds! Imag­ine how much time would have been taken by nor­mal im­age ma­nip­u­la­tion soft­ware to make a sim­i­lar change.

So, once you overcome the ini­tial dif­fi­cul­ties of learn­ing tools like PSTricks and PGF/TikZ, they will save you a lot of time and ef­fort when com­pared to con­ven­tional im­age ma­nip­u­la­tion tools. This is yet an­other ad­van­tage of PSTricks and PGF/TikZ.

One of the most pow­er­ful as­pects of PSTricks is its abil­ity to pro­duce 3D graph­ics. Due to the com­plex­ity in un­der­stand­ing the topic, it has not been dis­cussed in this ar­ti­cle. But to give you an idea about the 3D plot­ting ca­pa­bil­i­ties of PSTricks,

I have in­cluded a 3D plot gen­er­ated by PSTricks. To work with 3D plots in PSTricks, you need to have some ad­di­tional files in­stalled in your sys­tem or placed in the same di­rec­tory con­tain­ing your .tex file that gen­er­ates 3D plots. The files are pst-solides3d.pro, pst-solides3d.sty and pst-solides3d.tex. The plot in Fig­ure 7 is ob­tained from a slightly mod­i­fied ver­sion of a file called exa062.tex pro­vided by the of­fi­cial PSTricks web­site of the TeX Users Group.

If you are re­ally in­ter­ested in PSTricks, I sug­gest that you ex­plore the web­site https://tug.org/PSTricks/main.cgi/, which is full of PSTricks ex­am­ple files and tu­to­ri­als that will guide you through to mas­tery.

Fig­ure 7: A 3D plot with PSTricks

Fig­ure 5: Loops in PSTricks

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.