11 April 2010 1 Comment

PStricks vs. TikZ for Technical Diagrams

Norman Ramsey at StackOverflow once asked: My group uses Literate Programming for most of our source code—this means that internal documentation is written using LaTeX. We have been using PStricks for fancy technical diagrams of the system, but have recently been recommended to use TikZ. I’ve gathered this information:

  • TikZ/PGF is new and maintained; PStricks went a long time without a maintainer but has received some maintenance in the last couple of years.
  • TikZ works with many back ends, including (for those who care)
    1
    pdftex

    . PStricks works only with

    1
    dvips

    .

  • PStricks is more powerful and expressive than TikZ. In a dire emergency you even have the full power of PostScript.
  • PStricks has a significant ecology of extra packages that have been built on top of it; TikZ is too new to have many such things.
  • TikZ claims to have been designed “with the shortcomings of PStricks in mind.” The author does not specify which shortcomings.

I’m interested in the answers to two questions. If you wish, feel free to post one answer per question:

  • What is the learning curve like for the two tools? (I consider PStricks to have a steep learning curve; about TikZ I am uninformed.)
  • Considered as programming APIs, is one of these two packages significantly better designed than the other? If so, which is the better design, and why? (What properties does it have that make you consider it better?)

To make a compelling argument why one API is better than another, you may want to resort to examples.

Quick answer: I prefer TikZ to pstricks because I think TikZ

  • is better designed
  • is easier to learn
  • is compatible with pdftex
  • gives you more power and abstraction (you don’t have to specify as many coordinates by hand)
  • lets you create more beautiful graphics with the same effort
  • it is easier to extend using TeX programming (it was designed from the ground up with extensibility in mind)

For the users of pstricks, I’d recommend writing all new documents using TikZ in the future. For the users of METAPOST, if their graphics don’t use linear equation solving, I’d recommend TikZ. If the METAPOST graphics needs linear equation solving, I’d suggest trying Asymptote.

pstricks does indeed give you the power of PostScript, but it is not PostScript which makes your graphics authoring powerful, but it is abstraction: the use of automatic positioning, automatic intersection calculations, and display style templates. TikZ gives you powerful abstractions, even if you are not a programmer, or you are not willing to program this time.

I don’t have experience writing TikZ extensions, but from a quick glimpse of the TikZ source code, it seems to be easy to understand and extend, compared to other TeX macro packages I came across.

TikZ versus PSTricks Google trends

Kjell Magne Fauske wrote: For some time now I’ve had the feeling that TikZ is gaining popularity. In newsgroups and forums there is an increasing number of TikZ related questions and more and more TikZ related resources are available on the web. It is difficult to measure popularity. A tool that can give an indication is Google trends:

Google Trends analyzes a portion of Google web searches to compute how many searches have been done for the terms you enter, relative to the total number of searches done on Google over time.

As a former PSTricks user I was curious to find out how the search term

1
tikz

compares to

1
pstricks

. I fed the terms through Google trends and got this interesting graph:

tikzvspstricks

PSTricks has been around a lot longer than TikZ. The first version of PGF was released in 2003. In late 2005 the TikZ frontend layer was added. Interestingly the search term

1
tikz

does not gain enough volume to appear in the statistics until early 2007. To get a more correct picture I included

1
pgf

in the search term. PGF has several meanings so I had to include the

1
tex
1
latex

search terms as well:

tikzpgfvspstricks

Again TikZ and PGF gain enough momentum in early 2007. Interestingly this is a couple of months after the TikZ and PGF examples gallery went online. The Google trend is not an accurate measure of popularity, but they indicate that the popularity of TikZ is steadily increasing. A detailed view of the 2008 statistics looks very promising:

tikzpgfvspstricks2008

Summary

PSTricks doesn’t work in pdfLaTeX, and for some reason the PostScript output didn’t work as well for me as PDF output. I found the amazing PGF and TikZ packages with which you can make beautiful graphics for both PostScript and PDF output. The TikZ syntax is very clever and easy on the eyes, it’s inspired by PSTricks and MetaPost, another drawing program for (La)TeX.

With TikZ you get a very nice highlevel programming language for producing graphics in (La)TeX. For example:

\begin{tikzpicture}[line width=3pt]
  \draw[->] ( 0,-1) — ( 0,20) node[above] {Expenses};
  \draw[->] (-1, 0) — (20, 0) node[below] {Income};

  \draw[->, >=latex, blue!20!white, line width=72pt]
    (4, 16) — node [black,sloped] {Optimization} +(-45:17cm);

  \draw[draw=blue, loosely dashed]
    (1.5,1.5) coordinate (C1) node[below=3pt]       {$C_1$} –
    (10, 3)   coordinate (C2) node[below=3pt]       {$C_2$} –
    (13.5, 5) coordinate (C3) node[below right=3pt] {$C_3$} –
    (17, 10)  coordinate (C4) node[right=3pt]       {$C_4$} –
    (19, 18)  coordinate (C5) node[right=3pt]       {$C_5$};

  \fill (C1) circle (5pt) (C2) circle (5pt) (C3) circle (5pt)
    (C4) circle (5pt) (C5) circle (5pt);

  \path (9,16) coordinate (C0);

  \path (intersection of C3–C4 and C0– 19,6) coordinate (opt);
  \draw[|->, red, shorten >= 5pt] (C0) — (opt);

  \filldraw[red] (C0) node[above left] {$C_0$}
    (opt) node[below right, text width=4.5cm] {Optimization Target} circle (5pt);

\end{tikzpicture}

game06-benchmarking

Tags: , ,
  • beyo

    This is not exactly true…I use recently Pstrics with both pdflatex and Xelatex and its work like a charm thanks to new pstricks drivers and other workaround packages so now you may create pictures however you like and still produce good quality pdfs.

    I prefer PStricks because TIKZ syntax is not clean and many things can be written with several ways which can be very frustraiting to newbie to learn.