Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My apologies if this is not the right place to ask this question. If so, I would appreciate it if it could be told to me where I should post it instead.

Recently I came across a question which I thought could be answered quite easily if I were able to use a regular computer programming language (e.g. Java, Python) which supported writing graphics through an API.

While I am aware that programming can be done in TeX, most notably TikZ supports this, I always get the feeling that things are much more complicated to program in TeX.

Even though I know other programming languages (Java, Python, C) to program with TikZ or TeX still feels quite daunting. For example, to answer the above question, I could go through a for loop for each row, a second for loop for each column, then at each coordinate, draw a rectangle with the color which is returned by a function ValueToColor(value) where value is the value of that particular cell. However, I don't quite know how to do these things in TikZ or Tex!

Are there other programming languages with APIs that support generating nice graphics? The R programming language with the ggplot2 library comes to mind, as well as D3.js.

share|improve this question

migrated from meta.tex.stackexchange.com Feb 8 at 8:53

This question came from our discussion, support, and feature requests site for users of TeX, LaTeX, ConTeXt, and related typesetting systems.

    
I guess Asymptote and Sketch would be at least two... –  Werner Feb 7 at 21:33
    
Check out metapost! –  morbusg Feb 8 at 10:10
2  
I'm not sure this is on-topic here actually. Anyway, other programming languages has libraries for generating graphics, e.g. stackoverflow.com/questions/326300/… –  Torbjørn T. Feb 8 at 11:00
1  
There are a number of ways to use other languages in your documents, so that your TeX document contains non-TeX code that generates external figures for inclusion: Sweave and knitr for R, PythonTeX for Python (and Ruby and Julia), SageTeX for Sage, etc. –  G. Poore Feb 8 at 14:26

2 Answers 2

up vote 14 down vote accepted

As said before, MetaPost and Asymptote are the most forthcoming answers to your questions.

MetaPost is directly derived from Metafont, the language created by Knuth for font designing, and my favorite. Same syntax as Metafont, but to the contrary of MetaFont which produces bitmap fonts, it outputs PostScript pictures by default (possibility to produce them in SVG and PNG formats), which can be directly included in PDF files. I have found it quite easy to learn and very efficient. It has been recently turned into a C-library (mplib), and as such, sort of incorporated into the LuaTeX engine. As a consequence it can be very easily used with Context-MkiV, and with LuaLaTeX via the luamplib package. Its biggest drawback up to now is that it is not designed for 3D drawing (some packages exist, but have not convinced me).

MetaPost in its turn directly inspired another language, namely Asymptote. It has however a different syntax, C++-like, which is much more familiar to those who are used to the C-family programming languages (which is not my case). Most importantly, it supports 3D-drawing VERY efficiently. So I turn to Asymptote each time I need a 3D-drawing.

Both languages are actively supported and evolving rapidly.

To know more about MetaPost, its manual from the authors is a good read: https://www.tug.org/docs/metapost/mpman.pdf

A very good tutorial: Learning MetaPost by doing, by André Heck, and its answers to the exercises .

Also the Metafun Manual is pretty good. Metafun is the MetaPost format used in Context, but most of it is also useful for LaTeX users.

For Asymptote, the manual from its creators is a must-read. But to learn it, I find much more useful to pick up among the many great examples of these two sites:

http://www.piprime.fr/asymptote/ (from Philippe Ivaldi, now one of the developers); http://marris.org/asymptote/index.html (from Gaétan Marris, in French).

share|improve this answer

For specialized drawing tasks, you might find other "languages" than the ones mentioned in fpast's answer useful. For example, gnuplot for doing plots (but asymptote has a powerful package for this too), and for all sorts of graphs graphviz is nice. Both can be convinced to use LaTeX fonts with a bit of arm-twisting.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.