Tuesday, March 30, 2010

Graphics in LaTeX

In today's post I will say something about the graphics capabilities that one can access from within LaTeX.

Two distinct approaches are possible:

  • the diagram to be inserted may be prepared using some external application (this includes the case when the diagram is a photograph, so it is very useful when we have to insert photographs into the document); 
  • or the commands needed to generate the diagram may be included in the LaTeX file itself, in which case the diagram is generated in real time ("on the fly"), as the document is being processed.

LaTeX allows both these approaches. The former option is used when the graphic to be inserted is available as a graphics file (a jpeg or gif or png or eps file). The command used is something like:

\includegraphics[various options, including desired size of diagram]{name of file with path and extension}

The options allow resizing in various ways, cropping, etc. Details on how this is done can be found in any of the help documents listed in the earlier post. (Note. In LaTeX, options are generally placed within square brackets.)

Here I propose to say something about the other situation - when the diagram is drawn in real time.

LaTeX itself has an inbuilt picture editor whose usage is as shown below:

\begin{picture}
... various commands to draw lines, polygons, dots, circles, etc ...
\end{picture}

This is adequate for simple pictures; but it is really very rudimentary in its scope. (I myself never use it, having gotten hooked onto PSTricks early in my LaTeX days.)

That brings me to PSTricks, which in contrast is highly sophisticated and customizable. Precisely because it has been found to be so good by so many users, the community of people working on PSTricks is vast, and new modules (packages) are constantly being released; the basic package itself is constantly undergoing improvements by its authors (Timothy Van Zandt, Denis Girou, Sebastian Rahtz and Herbert Voss).

A typical environment within which a diagram is drawn using PSTricks looks like this:


\begin{pspicture}
... various commands to draw lines, polygons, dots, circles, etc ...
\end{pspicture}


Here are some links for finding out more about PSTricks:


This list should suffice to get you started. Please examine these links - you will find PSTricks to be a really marvelous device for drawing complex diagrams. 

The best thing is that the package is still growing in usability and versatility. There is a very useful mailing list to which a serious user should certainly subscribe; here is its URL:
If you post queries there, you will find answers coming in from all parts of the world.

Do try it out!

1 comment:

  1. \documentclass{article}
    \usepacakage{pstricks}
    \begin{document}
    \begin{figure}
    \begin{pspicture}(4,5)
    \psframe(0.7,3)(3,3,3)
    \rput(2,2.5){Mathematics}
    \end{pspicture}
    \end{figure}
    \end{document}

    ReplyDelete