Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loop/iteration in LaTeX

137 views
Skip to first unread message

ogheo...@gmail.com

unread,
Apr 30, 2006, 6:43:47 AM4/30/06
to
Hi,

I MetaUML's manual, I'd like to replace sequences like:

\metaumltest{picture_stack}{1}
\metaumltest{picture_stack}{2}
\metaumltest{picture_stack}{3}

or

\metaumltest{state}{1}
\metaumltest{state}{2}
\metaumltest{state}{3}
\metaumltest{state}{4}

with a for or loop. What is the best way of doing this in LaTeX?

Thanks in advance,
Ovidiu

Gianluca Pignalberi

unread,
Apr 30, 2006, 7:47:46 AM4/30/06
to
Hi,

I think the simplest way is using the commands provided by the package
ifthen. But, if you prefer the hard way, and doing it in TeX, you can
use the \loop ... \repeat.
For instance:
\newcount\qq
\qq=1
\loop
\metaumltest{state}{\qq}
\ifnum\qq < 4 \repeat
Gianluca

Herbert Voss

unread,
Apr 30, 2006, 8:30:15 AM4/30/06
to

Ted Pavlic

unread,
Apr 30, 2006, 10:41:58 AM4/30/06
to
> I think the simplest way is using the commands provided by the package
> ifthen. ...

Documentation for the package ifthen can be found here:

http://www-control.eng.cam.ac.uk/~pcr20/latex/ifthen.pdf

There is a \whiledo that may be what you're looking for.

(though it sounds like the multido suggestion is nicer)

Michele Dondi

unread,
Apr 30, 2006, 11:35:29 AM4/30/06
to
On 30 Apr 2006 03:43:47 -0700, "ogheo...@gmail.com"
<ogheo...@gmail.com> wrote:

You may also be interested in perlTeX.


Michele
--
>It's because the universe was programmed in C++.
No, no, it was programmed in Forth. See Genesis 1:12:
"And the earth brought Forth ..."
- Robert Israel in sci.math, thread "Why numbers?"

ogheo...@gmail.com

unread,
May 1, 2006, 2:04:43 AM5/1/06
to
Thanks for the answer, but I'm having trouble with the code:

\newcount\qq
\qq=1
\loop
\metaumltest{font}{\qq}
\ifnum\qq < 3 \repeat

pdfLaTeX sais:

! Missing number, treated as zero.
<to be read again>
\protect
l.32 \ifnum\qq < 3 \repeat

Any ideas why?

Herbert Voss

unread,
May 1, 2006, 2:21:32 AM5/1/06
to

\newcount\qq
\qq=1
\loop
metaumltest{state}{\the\qq}
\advance\qq by 1
\ifnum\qq < 5
\repeat

ogheo...@gmail.com

unread,
May 1, 2006, 2:22:54 AM5/1/06
to
This works just fine, here's my final code --- in case someone else
needs something similar:

\usepackage{multido}

\newcommand{\metaumltest}[2]{Test #2 --- \\
\includegraphics{fig/test_#1.#2} \\ }
\newcommand{\metaumltests}[2]{\multido{\iA=1+1}{#2}{\metaumltest{#1}{\iA}}}


\subsubsection{Class tests}
\metaumltests{class}{14}

Thanks,
Ovidiu

Gianluca Pignalberi

unread,
May 1, 2006, 8:40:07 AM5/1/06
to
Hi,

Herbert Voss wrote:
> ogheo...@gmail.com wrote:
>
>> Thanks for the answer, but I'm having trouble with the code:
>>
>> \newcount\qq
>> \qq=1
>> \loop
>> \metaumltest{font}{\qq}
>> \ifnum\qq < 3 \repeat
>>
>> pdfLaTeX sais:
>>
>> ! Missing number, treated as zero.
>> <to be read again>
>> \protect
>> l.32 \ifnum\qq < 3 \repeat
>
>
> \newcount\qq
> \qq=1
> \loop
> metaumltest{state}{\the\qq}
> \advance\qq by 1

aaaaaaaaaargh! Yes, of course.

> \ifnum\qq < 5
> \repeat
>
>
> Herbert

thank you, Herbert!
Gianluca

0 new messages