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

8
votes
3answers
177 views

More complicated key definitions in loops/for each statements

While writing a package with a key-value interface, I had a lot of repetitive key definitions. Naturally, one would like to express these definitions with a loop. When the definition contains ...
5
votes
3answers
145 views

pgfplotsinvokeforeach is invoked only twice

I would like to plot the family of curves with equation xy=c for several values of c. I also want each curve to be labeled with the value of c it corresponds to. Here is my MWE: ...
11
votes
2answers
2k views

New command with variable number of parameters

I would like to create new command with functionality like this (pseudo code): \newcommand{\myCommand}[numOfParameters] { for (i = 0; i < numOfParameters / 3; i++) { \somecommand1{#(i*3 + ...
6
votes
1answer
268 views

How to define macros in a foreach loop with effects between iterations and after the loop without using global?

Without using \global, the following code: \documentclass{minimal} \usepackage[T1]{fontenc} \usepackage{tikz} \usepackage{etextools} \newcommand\appendbyforeach[2]{% ...
5
votes
1answer
243 views

loop and input@path

I'm trying to have recursive path in the command \input@path, but it seems to be impossible (as I read, I'm with the TexLive 2012 and Linux). So I had the following idea, make a loop in \input@path, ...
7
votes
1answer
270 views

LaTeX's \@tfor loop

Here is an interesting case. Please why is case 1 failing? \def\expandsecond#1#2{\begingroup\edef\x{\endgroup\unexpanded{#1}#2}\x} \def\maybe@ic@{% \ifdim\fontdimen\@ne\font>\z@\else ...
8
votes
2answers
337 views

Getting last value in tikz foreach

I tried this, but it doesn't work as intended: \foreach \x/\index in {4/0,5/1,19/2} { \ifnum \index > 0 % use lastx \fi \pgfmathsetmacro\lastx{\x} } How do I set \lastx properly?
3
votes
1answer
318 views

CV/resume entry

I would like to create a "command" that does this for me: \cventry{jobtitle}{organisation}{date}{description}{bulletpoint...} such as: \cventry{Potato peeler}{TESCO}{1999 -- to date}{ Responsible ...
9
votes
4answers
372 views

Simplifying Manual Recursion

The following is literally copied/pasted out of a *.tex file: \newcommand{\bA}{\mathbf{A}} \newcommand{\bB}{\mathbf{B}} \newcommand{\bC}{\mathbf{C}} \newcommand{\bD}{\mathbf{D}} ...
2
votes
1answer
128 views

dynamic for loop

I'm trying to create a dynamic for loop: \def\forinmacro{{a,b,c,d}} \iftb{SomeBool}{\def\forinmacro{{a}}} \foreach \m in \forinmacro {...} Note if I change the last line to \foreach \m in ...
4
votes
1answer
675 views

Creating variables with index (using counters)

Is there a way to add an index to a command? For example: \newcounter{count} \loop<condition> \def\var\Roman{count}{some data} \repeat The \var\Roman{count} should become the variable ...
5
votes
1answer
338 views

Is there something like \renewcounter or \providecounter?

Is there a command that creates a counter or, if it already exists, redefines it? Thing is that I'm working with nested loops. The second loop is however in a command. This means if I want to use a ...
12
votes
3answers
265 views

Why does the package babel[french] destroy \@for loops?

Why does this minimal example code: \documentclass{article} \usepackage[francais]{babel} \begin{document} \def\names{Toto,Titi,Tete,Tutu} \makeatletter \@for\next:=\names\do{\textbf{\next} } ...
5
votes
1answer
1k views

Using \end in internal vertical mode

Please how do I stop at all cost in the following? Note: \leavevmode is no rescue. \documentclass[crop]{standalone} \def\z#1#2{% \ifnum#1<\numexpr#2+1\relax \noindent\hfill#1% ...
5
votes
4answers
157 views

Is there a trick to reduce the number of counters in the following case?

I want to avoid using \tmp. Is it possible to remove it while keeping the same output? % Declare counters. \newcount\pages% \pages is given so you cannot remove it! \newcount\x \newcount\tmp % ...
10
votes
5answers
774 views

Teach me how to use \loop…\repeat constructs, etc

The following code snippet is a part of the solution given here: \def\IncludeOutput#1{ \parskip=2mm \def\examplename{#1} \pdfximage{\Directory/\examplename.pdf}% ...
2
votes
2answers
278 views

What makes a loop inside \IfFileExists fail?

The following MWE is the simplified version of my project. But it is complete enough to produce the problem. If you disable (comment) the looping parts, compilation succeed. Otherwise you will get ...
3
votes
1answer
112 views

forarray's \ForEach isn't robust

\ForEach and related commands of forarray package aren't robust. They can't deal with lists whose separators are active (e.g., active comma). Also any trailing space after the list item is retained ...
2
votes
3answers
187 views

Process Last Item in \ForEach (forarray package)

The following command of the forarray package \ForEach{,}{\thislevelitem(\the\thislevelcount) : }}{x,y,z} produces the output x(1) : y(2) : z(3) : I want to have the same output without the last ...
4
votes
2answers
229 views

l3prop property stores and etoolbox loops: weird results

I'm writing a class for handling multi-language jargon formulas. My idea is to use l3prop to store, for each formula, its language variations -- i.e., a sort of hash table. Building on one of the ...
5
votes
1answer
261 views

Auto generating table

In the following scheme, why do I have to hide & in a macro (\samp) before it works? \documentclass{article} \usepackage{catoptions} \makeatletter \cptnewcounts{rowcnt,colcnt,maxrow,maxcol} ...
7
votes
3answers
456 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
159 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
728 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
432 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
438 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
212 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
247 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
654 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
162 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
221 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 ...
11
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
478 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
166 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{% ...
3
votes
2answers
551 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
933 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
561 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
748 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
532 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) & ...
8
votes
2answers
833 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
430 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
305 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
851 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
823 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
170 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 ...
11
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. ...