{loops} is about looping constructs which allow a programmer to apply the same operation multiple times, each time with possibly different parameters.

learn more… | top users | synonyms (1)

15
votes
1answer
3k views

Using double for-loop in tikz

In the manual one can find the ... option to obtain a range in the for-loop. For example: \foreach \x in {0,0.1,...,6} {\x, } On the other hand, one can have a for-loop which runs over two ...
2
votes
3answers
520 views

How to get rid of these excessive rules?

\documentclass{article}%cannot be minimal \usepackage{longtable} \usepackage{ifthen, xspace} \newcounter{xyz} \setcounter{xyz}{1} \def\and{&\xspace} \begin{document} ...
21
votes
6answers
2k views

“For loop” in newcommand

I have this command \newcommand{\pdfappendix}[1]{ \includegraphics[scale=0.6]{pdf/#1.pdf} } It works well when I have 1 page pdf but is not including the other pages. Now I decided to change ...
1
vote
1answer
1k views

How do I add parfor in algorithmic environment?

I want to have a parfor loop in my algorithm listing (it should work exactly as standard for loop works). How to either change the displayed name of for loop or add my own loop which will keep the ...
2
votes
1answer
704 views

using foreach to draw a chain with a branch

This is an extension to How to draw the border of a node using late options I'm drawing a chain of nodes with different colors using foreach from tikz. Now I want to add a branch, also using foreach. ...
10
votes
5answers
1k views

How to define a parshape command with LaTeX?

I want to typeset a book with some \parshape command, for example: \documentclass{article} \usepackage{lipsum} \begin{document} \parshape=4 0.2\textwidth 0.8\textwidth 0.2\textwidth 0.8\textwidth ...
3
votes
1answer
508 views

How to include multiple images inside a TikZ loop

I have a case, where my files are named images_001.png .... images_011.png. I tried to put them like this: \def\filelists{1/{"t0_01"},2/{"038"}, 3/{"050"},4/{"060"}} \foreach \i\element in ...
7
votes
1answer
824 views

Generating tables with \@for command

I'm making a report template that requires the list of authors to be presented in several different ways, one of which is a table that lists each author and provides a space for them to sign the ...
2
votes
2answers
806 views

pgfplots: setlength inside foreach

I have the following code, where the size of the cube marks is set to \x inside a foreach loop: \begin{tikzpicture} \begin{axis}[axis lines=none] \newlength{\mylen} \foreach \x in {1,2,...,10} ...
10
votes
2answers
1k views

How to break out of a loop

I have been trying to automate the production of stepped tables that contain conversion factors of all sorts. (See Protrusion of fractions in tabulars). As part of this I have a rather convoluted ...
10
votes
7answers
1k views

Iterating through two lists

I have two comma delimited lists: ListA(a,b,c,d,e,f,g) and ListB(name1,name2,name3,name4,name5) I would like to iterate through both lists at the same time, something like: loop readvalue ...
6
votes
2answers
4k views

How to use parameter numbers and \foreach

Is there a way to use the TikZ \foreach command to do operations with parameters? E.g. I would like to be able to write (just a silly example): \newcommand{\foo}[9]{ \foreach \x in{1,2,...,9}{ ...
9
votes
2answers
554 views

Why is this loop so much faster under Windows?

In a recent question, Yiannis Lazarides was asking about benchmarking loops. Strangely his results were about 800 times faster than mine. I couldn't quite accept that my computer is that outdated (as ...
6
votes
2answers
485 views

How to determine the run time of a loop?

pdfTeX, provides two macros that can be used to determine the time elapsed from a run start. The first one determines the elapsed time in "scaled seconds", that means seconds divided by 65536. ...
4
votes
1answer
343 views

Are there list building macros in PGF/Tikz?

In Mathematica, C# linq, or other languages, we can use auxiliary functions to produce list of certain pattern. For example: In Mathematica, we can use Table[] or Range[] to produce a list of ...
15
votes
2answers
1k views

How to programmatically make tabular rows using `\whiledo` ?

The following code snippet does not work: \documentclass{minimal} \usepackage{longtable} \usepackage{ifthen} \newcounter{xyz} \setcounter{xyz}{0} \begin{document} \begin{longtable}{|*2{c|}} \hline ...
4
votes
1answer
226 views

Why does the following code run in an infinite loop?

\def\hcAuxText{} \newread\hcInputStream \immediate\openin\hcInputStream=myfile.tmp \loop\unless\ifeof\hcInputStream \read\hcInputStream to \hcAuxLine \let\hcAuxAcumm\hcAuxText ...
6
votes
2answers
849 views

Repeating a block of text until it fills a page

Might I please have some help with writing a loop that repeats a block of text as many times as there is remaining space for it on the page? I would like to produce an notebook in TeX which is ...
3
votes
2answers
491 views

Unexpected tikz/counter behaviour

What I've been trying to do, futilely, is to use the foreach[counter=\xi] x in {1,2,3} statement in tikz/pgf with LaTeX. This fails, every time. Whatever. So I moved on to trying to use a counter, ...
4
votes
1answer
1k views

Tikz array as argument

Problem I'm drawing flow diagrams in Tikz, and they basically include a header, followed by a list of flow components set below an arrow. I've written functions to take arguments in Tikz before, but ...
19
votes
3answers
2k views

Delete an element from a comma delimited list

LaTeX's low-level programming is poorly documented and the section on what is called control commands is even more so. LaTeX provides the \@for macro. This works by repeatedly assigning list items ...
22
votes
2answers
1k views

naming paths inside a TikZ foreach loop

Is it possible to create named paths inside a foreach loop with the name depending on the counter? I want to write something like \documentclass{article} \usepackage{tikz} ...
7
votes
3answers
473 views

Strange recursive macro output

Strange recursive macro output The code that follows describes a macro that can iterate recursively (i.e, a forloop) and uses e-TeX numexpr. It is based on an example found in the e-TeX manual (page ...
5
votes
2answers
3k views

algorithm package: Comment on “for” loop does not work?

It seems that \COMMENT in the algorithm package is broken. It gives an error when used in a FOR or FORALL line, so the first comment gives a compilation error: \begin{algorithm}[ht] \caption{My ...
17
votes
7answers
2k views

What is the canonical way to write a for-loop macro?

At a basic level TeX does not provide a for-loop construct, but allows tail-end recursion, however Knuth defined \loop in the plain macros. Coders have been coming with variations of their own ever ...