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.
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.
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.
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}
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.
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…).