{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)

7
votes
3answers
481 views

Nested \loop macro

Please are there 'nestable' variants of Knuth's favourite looping macro \loop without the brace-scope introduced in the answer at nested loops. I am developing a package called loops, where I am ...
3
votes
1answer
170 views

How do I add a for loop to a class file function?

I'm using this XeLaTeX class file to write my resume. One of the features is for section headings it colors the first 3 letters: \section{experience} This is hardcoded to the first 3 letters, and ...
9
votes
6answers
820 views

Defining new commands inside a for loop

I would like to define a number of related commands by using the counter in a for-loop. For example, I want to define 26 commands like this: \newcommand{\calA}{{\cal A}} \newcommand{\calB}{{\cal B}} ...
2
votes
1answer
488 views

conditional inside a pgfplotsinvokeforeach loop

I'm using \pgfplotsinvokeforeach to do mathematical computations inside the \addplot options. Now I need a conditional to decide whether to plot a line or not depending on the current index of the ...
8
votes
5answers
3k views

Inserting figures using loops

I have a set of pictures in my working directory and I want to make a PDF report using these images. I want to include all of them, but the number of the pictures changes in each case. I would like to ...
1
vote
0answers
442 views

Generate trees based on number of nodes and children allowed [closed]

I am doing an experiment, and would like to generate images of Binary Trees and Exponential Trees using LaTeX. The difference between these two structures is the number of children allowed per node ...
3
votes
2answers
225 views

\DTLdeletedb (from datatool package) has no effect within \foreach

This question led to a new feature in a package: datatool \DTLgdeletedb is available in (v2.13) and later. I am trying to use a \foreach loop to iterate over a few items. For each iteration ...
6
votes
1answer
263 views

\foreach with indexed names of curves

I am constructing several curves, which are all constructed differently, but they have path name=lambda1, ..., lambda4. Later, I intersect each of them with one path. Attached is a working minimal ...
9
votes
5answers
768 views

problem with using loop inside the tabular environment

I am having trouble with using a loop inside a tabular environment: \newcounter{it} \setcounter{it}{0} \begin{tabular}{ll} \loop\ifnum\theit<4 \addtocounter{it}{1} Q & A\\ \repeat ...
3
votes
1answer
182 views

How can I create copies of a document with a running number?

I am making a questionnaire, to be filled out with pen and paper. I need 40 copies of it, with around 13 pages each. I expect that some participants might take the questionnaire apart, so I have to be ...
3
votes
4answers
230 views

How can I write a nested loop if the inner loop doesn't always have the same number of repetitions?

I am writing a questionnaire. It lists 16 software features, and the participants should answer things like "I find this feature: Very important - Somewhat important - Not at all important" once for ...
6
votes
2answers
1k views

Less than or equal comparison within a whiledo

I am in the process of cleaning up the code for Sieve of Eratosthenes in tikz, but saw that when I initially did the code, I could not figure out how to do a <= comparison within the \whiledo, and ...
12
votes
4answers
3k views

PGF/TikZ: How to store strings in array?

I'm trying to generate a lot of name badges. I'm wondering, is it possible to store the names as strings in one array, according to the PGF manual: ...
6
votes
1answer
527 views

Problem setting a flag inside a TikZ `\foreach` loop

I'm pulling my hair out trying to understand why the following doesn't work. The intention is to calculate whether a given number #1 is prime, and to set \isprime to either 1 (true) or 0 (false). The ...
5
votes
1answer
169 views

Infinite loop on a non-macro token

The following document infinite-loops: \documentclass{article} \usepackage{breqn} \begin{document} \newcommand{\allowbreaks}[2][,]{\begingroup \catcode`#1=\active \scantokens{% \edef#1{% ...
4
votes
2answers
611 views

For loop print out array contents sequentially

I have already some experience getting \forloop to work in LaTeX but I can't figure out how to get it to print off each item sequentially in a given "array"... Like this pseudo-code would do: ...
18
votes
2answers
1k views

Repeated slides in beamer

I have about 200 JPEG files that I need to include in a PDF document, one JPEG per page (i.e. 200 pages + intro slide). The following code successfully does this with one JPEG. ...
7
votes
1answer
609 views

Using \Alph on \foreach loop argument

Here's basically what I try to do: \begin{tikzpicture} \foreach \x in {1,2,3,4,5} { \draw (\x,1) node{\Alph{\x}}; } \end{tikzpicture} However if I do that, I get ERROR: Missing number, ...
12
votes
5answers
810 views

A grid of images to fill A4 -paper for economic printing with some space for scissors

I want to print a A4 paper full of the same QR image. I want more elegant way to this answer here, yes I can get it working like that but I want to leave just enough space for scissors and no space ...
6
votes
1answer
553 views

Pgffor and the alignment character (&)

I need to construct a table that looks like: \begin{tabular}{ccc} a(1,1) & a(1,2) & a(1,3)\\ % <--- a(2,1) & a(2,2) & a(2,3)\\ % <--- I need this a(3,1) & a(3,2) & ...
9
votes
2answers
877 views

While loops in TikZ?

Is it possible to have while loops in TikZ, or some equivalent loop which only terminates after a certain condition?
5
votes
1answer
464 views

Use a loop to generate a list for another (foreach) loop

Is it possible to use a loop to generate a list for a foreach loop? More specifically I want the following: Consider the following answer to a question I asked some time ago: ...
5
votes
1answer
2k views

Including all files within a directory [duplicate]

Possible Duplicate: How to iterate through the name of files in a folder Using \input{filename}, I can input a file canned "filename.tex". I have a directory containing all of the files I ...
16
votes
1answer
2k views

Want to fill line with repeating string

Similar to the \dotfill command, but with your own text, rather than dots. If the string was: kitty! The entire line would look like the following: ...
2
votes
1answer
333 views

looping in tabular

I am curious to know why the following failed. A similar thread is on comp.text.tex unanswered. Of course, other manipulations of \whileexpr work, but why does this fail? \documentclass{article} ...
11
votes
1answer
935 views

Possible to combine “…” and “x/y” in TikZ's foreach?

I'll start with a simple, minimal non-working example: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \x/\y in {1/20,2/18,...,10/2} \node at (\x,0) {\y}; ...
16
votes
4answers
866 views

Understanding a \@for loop

I'm having trouble with a \@for loop. I've got a macro that takes a comma delimited list and puts each element into a row of an array. When I do this using a \@for loop, I get an extra row that I ...
7
votes
1answer
179 views

expansion of loop macro

I have a macro that contains a loop using \@for and it works until I try to write its output to a file. The following document shows the problem. \documentclass{article} \makeatletter ...
12
votes
2answers
2k views

Variables in TikZ

I use TikZ to draw graphics in LaTeX. I'd like to do arithmetic on variables. For example I haves nodes named after N-1 and N-2 and I'd like to create the N-3 and N-4 nodes as +2 from the first nodes. ...
5
votes
2answers
415 views

Special handling of first and/or last item in an etoolbox list

Is there a simple way of handling the first and/or the last item in an etoolbox-based list in a special way? Here’s a simple example: \documentclass{article} \usepackage{etoolbox} \begin{document} ...
4
votes
1answer
2k views

LaTeX algorithmic package: Undefined Control Sequence in for-Loop

I'm trying to specify an algorithm in pseudocode in a LaTeX document, but I'm having trouble with the for-Loop. My statement: \for{$bin=0 to binCount$} \item blablabla \endfor keeps on generating ...
5
votes
1answer
572 views

How to generate named nodes from the counter used in `foreach` in TikZ?

I'm trying to generate multiple nodes in TikZ using the foreach operator, but whatever I try I get compilation errors. I need all nodes to be named in order to draw edges between them. Having read ...
1
vote
1answer
200 views

Looping and linking with TikZ

How would you build a grid using a nested foreach, defining one node for each iteration? If I were coding in Python, I would write: nodes = {} for i in range(10): for j in range(5): ...
0
votes
2answers
309 views

Environment with customizable number of table columns

I want to make macros for drawing group of questions with same answers with customizable text, number of answers and design (column widths, alignment, etc.), like this: ...
3
votes
1answer
750 views

How to create lists in tikz

I would like to create lists and use them in tikz \foreach loops. Example: \newcommand{\createSquareList}[1]{ this is the part I do not know } \foreach \n in \createSquareList{5} { % do ...
2
votes
3answers
292 views

How to simulate 2 dimensional loop using 1 dimensional loop?

animate package does not allow nested loops. Only a single loop is allowed. However, we often need to simulate 2 dimensional space in a single loop. Please see the following C# code that I want to ...
2
votes
2answers
401 views

How to detect a blank line inserted by TeX when reading an external file line by line?

I want to make a macro to import all TeX input files in a directory in which the input file containing the macro exists. When reading an external file, TeX appends a blank line to the last iteration. ...
2
votes
1answer
413 views

Place symbols/nodes at intersection between an arc and some horizontal lines with \foreach in TikZ

I'd like to place an symbol I've defined at all the intersection point between an arc and some horizontal lines: I know how to use \foreach for other cases, but I'm really not sure how to setup the ...
2
votes
3answers
809 views

TeX Nested Loops With \iftoggle

This forum has helped me understand how to use nested loops in TeX, but now I am having trouble using \iftoggle (from the etoolbox package) with loops. My goal is to have a toggle that can keep track ...
7
votes
3answers
1k views

How to get the list of predefined colors in xcolor such that the list can be used in foreach looping?

I need to get the list of predefined colors in xcolor. Hard-coding as follows is not a good coding practice. \documentclass[dvipsnames,cmyk]{minimal} \parindent=0pt \usepackage{pstricks} ...
3
votes
4answers
271 views

What is the TeX equivalent for the following C# nested loop?

I need a nested loop to animate PSTricks diagrams. In C# or C or C++, I usually write as follows. int N=6; for(int x=0; x<N; x++) for(int y=x+1; y<N; y++) Console.WriteLine("({0}, ...
8
votes
2answers
266 views

Preparing macro content in a loop (calling \foreach from \edef)

I need to do something like \def\MyArray{{1, 2, 3, 4}} but with a dynamical number of elements. The following command makes the string: \newcommand{\MakeArray}[1]{\{ 1 \foreach \x in {2, ..., #1}{ , ...
3
votes
1answer
258 views

How to translate this scenario to LaTeX looping macro?

I want to slice an image into 8 parts, i.e., 2 rows by 4 columns. Each part is on a single page as follows. The gray frame is the Acrobat Reader background, so don't think it is a part of the output I ...
5
votes
3answers
867 views

Tex Nested Loops

I am trying to write a simple nested loop in LaTex, without using any special packages, using only the \loop...\if... \repeat syntax. I think I may be lacking a basic understanding of the rules for ...
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
506 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
696 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 ...