TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I want to draw a simple graph in LaTeX.

I'm interested to know if you can write a for loop or something to create things like lines or squares programmatically in LaTeX.

share|improve this question
up vote 21 down vote accepted

TikZ is a powerful graphic package. It's a front end for the pgf package and can be used for programming drawings such as graphs. for loops a easy with TikZ.

Have a look at

If you would like to program more in general, you may consider to use LuaTeX, which allows using Lua as scripting language.

share|improve this answer

You can can also use the bundle pstricks:

share|improve this answer

LaTeX running on top of TeX or pdfTeX or XeTeX is a Turing complete programming language, but you are probably more interested in LuaLaTeX, as that offers Lua, a "modern" scripting language.

share|improve this answer

In fact TeX is itself a kind of scripting language (and it is a Turing complete programming language cf. Wikipedia article). There are packages that wraps in a neat way bare-bones TeX to supply basic imperative constructs like loops and conditionals: forloop, ifthen (concerning the later see also this discussion). I used to use these packages, one example of mine could be found in this directory, basically it includes bodies of CardBodyN.tex many times in for-loop, the loop itself is located in the document.tex, you're welcome to ask further questions…).

share|improve this answer

Your Answer


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.