Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any good postscript drawing libraries?

I need to draw some pictures for my LaTeX documents, and I've found that hand-made PostScript seems to be a good fit (I want to do stuff programatically, need math functions, etc.). I've also tried TikZ but that just seemed overcomplicated and hard to use.

However, using plain standard PostScript is a bit painful since there aren't really any standard functions for drawing shapes (e.g. not even rectangles).

Is there any PostScript library that would include functions for common shapes and make life a bit easier? Seems to me this problem should be fairly common.

Or should I skip PostScript and move on to some superior system? Which one?

like image 807
pafcu Avatar asked Sep 09 '09 08:09

pafcu


3 Answers

A few people and many PostScript drivers define their own set of procedures for drawing shapes. A PostScript driver may output the following shortcuts:

/bd{bind def} bind def
/cp{closepath}bd
/gs{gsave}bd
/gr{grestore}bd
/m{moveto}bd
/rm{rmoveto}bd
/l{lineto}bd
/rl(rlineto}bd
/s{stroke}bd
/f{fill}bd
/sf{gs s gr f}bd
/xx{exch}bd

/rect {4 2 roll m 1 index 0 rl 0 xx rl neg 0 rl cp} bd

Then, a rectangle would be drawn like this:

0 0 100 100 rect sf

The cumbersomeness of this does make PostScript particularly hard to deal with. MetaPost may be a better fit if you your drawings are programmatically/mathematically generated. MetaPost generates encapsulated PostScript (which you can include in your LaTeX document) but it is more suitable for drawing images with algebraic definitions.

like image 175
dreamlax Avatar answered Sep 27 '22 22:09

dreamlax


I like using matplotlib. It can generate both postscript and PDF directly, it's in python, and it can also do pretty sophisticated plots (hence its name). If you want to hack PostScript directly you'll be able to use psticks in LaTeX, but you'll need to run-trip everything through dvi2ps and then ps2pdf to make PDFs. Do you really want PostScript or PDFs? I think that you want PDFs, right?

like image 37
vy32 Avatar answered Sep 27 '22 22:09

vy32


OK, I've decided that Asymptote is the best thing since sliced bread. Handles drawing both graphs and arbitrary figures really well, and has a vast number of extension modules (including MetaPost compatibility if you care about that). Additionally it typesets text using LaTeX which is just incredibly cool. As an added bonus it even outputs directly to PDF (or EPS).

I still think it's a bit sad there's no good libraries of routines for good ol' PostScript though.

like image 25
pafcu Avatar answered Sep 27 '22 21:09

pafcu