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.

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

4 Answers 4

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:

\documentclass{article}
\usepackage{pstricks,pst-plot,pstricks-add}
\begin{document}
\begin{pspicture}(5,5)
\psaxes{->}(0,0)(0,-5)(5,5)
\multido{\iA=-3+1}{7}{%
\psplot[algebraic,linecolor=red,yMaxValue=4]{0}{4}{\iA*x}
}
\end{pspicture}
\end{document}
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

 
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.