A feature of latex is that you can "program your document". You can do this by using TeX/LaTeX directly (remember that it is Turing complete) or by other languages like lua or python (especially sage) or other languages where a package exists to use that code to program in latex. In particular TeX or lua is heavily used when developing a new package.
However I want examples which show this "paradigm" from the point of view of a user.
The examples should be at best real use cases. For example if you have made use of this paradigm to set up a nice document using loops and other programming features in the past and you are (a bit) proud of it, please post it. It is also welcome if you come up with new examples just for this question.
Please post the source code and the result. It would be nice if you could pay attention to commented, clean (perhaps elegant) source code.
I think great answers to this would be both educational and inspiring and would also provide further arguments why to prefer LaTeX over other software for example some text-processors…
Best Answer
I'm not sure if this is appropriate, but in the distant past, before I was aware of packages like Tikz, I wrote some routines for performing arithmetic operations in plain TeX using dimensions (plain TeX can do this also, but discards remainders).
I apologize for the, most likely, horrendous code.
Here are some utility macros (these are used for other routines I've made. Some of these may not be used in what follows):
Here are the (very much unoptimized) math routines:
(Incidentally, I was particularly proud of using a "seven
\expandafter
" in the\DivDim
routine. I wonder if it's needed...)One application of these routines is to produce graphs. Here are some macros I made to produce polar curves:
Here is some sample output (which looks much better than the screen capture would indicate)
The command
\SinPolarGraph{8}{.5}{-2}{3}{0}{6.28}{2}
, for example, produced the "nested rose" in the "Other" box (TeX needs to be in horizontal mode when\SinPolarGraph
is called). Here is a close up:All done using only plain TeX!