[Tex/LaTex] Fundamental differences : PSTricks, TikZ/PGF and others

graphicsmetapostpstrickstikz-pgf

OK, since this is a pretty vague and subjective question. I need to set up some borders around the discussion that I intend to benefit from. But before anything, I certainly do NOT want to excite the comparison frenzy and other … I bet you can't do this with that… or …Mac vs. PC… or …vanilla vs. chocolate … type of answers which can be carried over to What are the advantages of TikZ/PGF over PSTricks? (But best omitted).

I would like to ask for a lower level explanation of the differences that answers questions such as:

  • Why is PostScript instruction access seemingly under the monopoly of PSTricks and others just envy it? Is it only the compilation engine that can interpret them? Is there any hope to get a natural hook to PS (MetaPost too for that matter)? For example, in TikZ there is a command \pgfdeclarefunctionalshading which evaluates a limited collection of PS commands. (An example : How to draw a shaded sphere? ) Why not more?
  • If .pdf <=> .ps file conversion is possible, why can't it be done at the renderer level?
  • Why can't PSTricks simply work with the pdflatex engine but rendering much of the goodies such as 3D capabilities etc. obsolete for the standard user via requiring an externalization? See also How to use PSTricks in pdfLaTeX?
  • Are there any .pdf and .ps file format standards conflicts both protocol- and copyright-wise, that is beyond compatibility again at the renderer level?

This question was briefly mentioned in the interview with Andrew Stacey and Ryan Reich implicitly proposed a soft question to be asked. After wondering a bit, I found out that I have some big potholes in the story, though I vaguely know some of the answers to the questions above. It would be great if Herbert, cjorssen (as directly taking part in the development of these tools) and other experts can shed some light.

Depending on the users' opinions, I can remove this question which might be too subjective. There were even more questions but removed later (see the edits).

Mandatory Disclaimer I use TikZ a lot. Also I sometimes include pictures created with PSTricks (as long as I understand how to use the Klingon syntax). I really enjoy the convenience of these tools and don't want to choose one for the other. Why can't we just talk ?

An insider story complements the answers below towards the end on this video;

http://www.youtube.com/watch?v=1rCNnMZrFUQ&t=9m52s

Best Answer

PostScript is a complete programming language, and as such is very powerful. To convert PostScript into output, you need an appropriate interpreter: the most common one in use today is GhostScript. The PDF format is related to PostScript, but via the more limited subset provided by the EPS (Encapsulated PostScript) format. As such, PDF viewers do not have the ability to directly render PostScript: it must be converted into the correct PDF directives. (PDFs are not programs in that sense: one of the reasons for the creation of the PDF format is that it is a 'known quantity'. A PostScript document may require arbitrary amounts of complex calculations to display, which may be an issue for some devices and workflows.)

TeX does not include a PostScript interpreter. In the dvips route to creating a PDF from a .tex source, TeX writes the PostScript instructions to the .dvi file as \special instructions, which are then interpreted by GhostScript in the ps2pdf step.

The same is true for newer TeX engines: a PostScript interpreter is a large overhead, and integrating directly into say pdfTeX would not therefore be particularly sensible. In direct PDF mode, pdfTeX creates the appropriate PDF instructions for creating 'special effects', while in .dvi mode it acts in the same way as Knuth's TeX. Some of the issues here are covered in Why doesn't pdfTeX support PStricks directly? and How to use PSTricks in pdfLaTeX?. (Note that XeTeX does take a somewhat hybrid route, which allows PSTricks use with direct PDF production. It's important to note also that XeTeX works via an extended .dvi format, and so this is in some ways more like dvips than direct PDF production.)

Turning to PSTricks and TikZ, the differences here are pretty fundamental. PSTricks always uses the same driver back-end, and that back-end is a powerful programming language in its own right. As such, PSTricks can leave a lot of work to the driver level, and also can in principal include an interface for anything that PostScript can do. On the other hand, TikZ is a 'driver independent' system, and as such leaves the driver-dependent code to the lowest 'layer'. TikZ therefore cannot use any special features of PostScript: all of the programming is done in TeX macros, and only the raw 'draw X' instructions are written to the output file.

The fact that TikZ supports multiple drivers also means that there are limitations on what can be implemented. Each driver has a certain range of capabilities, and supporting all drivers is not necessarily easy. (For example, transparencies are difficult with XeTeX due to the way xdvipdfmx works.) As such, it tends toward a common subset of features which work with most or all of the drivers, rather than having lots of 'this only works with X' comments.

A similar consideration applies to interfaces: PSTricks can rely on the way PostScript handles input, while TikZ has to abstract any features to a generic interface that works for PostScript, PDF and other output formats. (Remember TikZ works to some extend with SVG and so on.)