Re: LaTeX and loops
On Monday 11 November 2002 10:42, Rupert wrote:
> On 11 Nov 2002 03:34:32 +0100
>
> Paul M Foster <paulf@quillandmouse.com> wrote:
> > Anyone who knows how to do loops (like for loops) in LaTeX, could you
> > please contact me offlist? (This is way too esoteric for anyone else to
> > be interested.)
>
> I'm not sure this is _so_ esoteric... there was thread on this on
> comp.text.tex:
>
> How to define a loop "for..." with TeX/LaTeX
> http://groups.google.com/groups?th=e3878cb337b93c95
>
> Rupert
You have to be familir with the test construction of TeX. Here is an example
which print the number from 100 downto 0
\newcount\a
\a=100
\loop \ifnum\a>0 \number\a \ \advance \a by -1 \repeat
\bye
It loops until the condition become false and then it stop; the condition can
be anywhere between \loop and \repeat.
You can find more details in the TeXbook (p. 218) available at ctan
(texbook.tex):
http://ftp.agh.edu.pl/pub/tex/systems/knuth/tex/texbook.tex.gz
Remark: The file itself begin with an infinite loop telling you that you
cannot compile it because it is copyrighted. To compile it anyway:
remove the first two lines (after the comments):
\loop ...
\errmessage ...
Then just below replace \pausing1 by \pausing0 and add "\proofmodefalse" just
after "\input manmac"
LaTeX has a package "ifthen" which redefine the loops but you can use the TeX
construction also.
This subject is not esotheric. LaTeX itself (which is programmed in TeX,
iniTeX to be more precize) contains a lot of \loops. The \begin{enumerate}
environment is and example.
If something is unclear, please reply to this e-mail,
Olivier Esser
Reply to: