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

4
votes
1answer
130 views

How to change list options during a loop?

I currently have a beamer presentation, which, using the forloop package, looks basically like this: \documentclass{beamer} \usepackage{forloop} \begin{document} \newcounter{ctr} \newcounter{gulp} ...
6
votes
1answer
146 views

Macro to create new .tex files

I borrowed from Extracting the contents of text in a specified environment into a new file some code that extracts lines from a .tex file and puts it into a new file. The code works well, but I would ...
3
votes
1answer
336 views

Automated table for excercise points in tikz

I'm a computer science student. And I write most of my excercises in LaTeX. So I often have to create a table for excercise points, with different numbers of excercises and different amounts of points ...
7
votes
2answers
537 views

How to decrease the counter in tikz foreach loop

I have the following code: \documentclass[11pt]{article} \usepackage[a4paper]{geometry} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{tikz} \usetikzlibrary{positioning} ...
7
votes
2answers
410 views

creating a list of random numbers using a loop

I am trying to write a loop that will generate a set of random variables to be used in the probsoln package. I would like to make a loop to generate A, B, C, etc. This exam will have a lot of ...
2
votes
1answer
182 views

Compare two comma separated lists

Hi I would like to compare two comma separated lists. \documentclass[a4paper]{article} \usepackage{comment} \usepackage{ifthen} \usepackage{xargs} \usepackage{xkeyval} \usepackage{xfor} ...
7
votes
2answers
192 views

Repeating frame contents

Supposing that I'll use always two blocks on each frame. Then, I'd like to have a simple way to do the following, without copy/paste procedure: On each frame (except the first one), the first ...
8
votes
2answers
119 views

Getting \let definitions from inside a group, inside a loop

I have the following nested loop situation: \begingroup \def\do##1{% \begingroup \def\do####1{% \csletcs{somemacro@##1@####1}{someothermacro@##1@####1}}% ...
18
votes
4answers
478 views

Comma delimited list - how to obtain the length?

It's simple. I have a list like {0,1,54,1,3} as input argument to a command in making. How can I obtain the length of this list? Something like \length(#1) where #1 is the list.
12
votes
2answers
1k views

varioref: \vref or \vpageref at page boundary (may loop)

Sometimes a have situations, where I'm not able to compile a document, because the varioref package result in a loop. Here is a MWE, which result not in an endless loop, but it demonstrate the issue ...
3
votes
1answer
62 views

How do I create an expandable conditional with a loop inside?

I need to create an expandable conditional that uses a loop (that is, a ..._map_function:). It should either return true from inside the loop, or return false otherwise. In a 'normal' programming ...
3
votes
1answer
182 views

How to escape = in LaTeX's for loop

In user700902's answer to this post, there is the following for-loop: \@for\@tempa:=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z\do{% \expandafter\colorizemath\@tempa{green}} If I want to ...
9
votes
2answers
2k views

LaTeX for loop \@for

In user700902's answer to this thread, a for-loop with the syntax \@for is used. How does this syntax work? I tried searching about for-loops on other websites, but I could only find something like ...
4
votes
1answer
301 views

Continuing a TikZ animation with \onslide after a \foreach loop

I want to produce an animation in a tikzpicture environment in Beamer. The animation consists in a series of slides produced by combining \foreach and \onslide, which works fine. I then want to ...
7
votes
2answers
197 views

Why won't this Metapost while loop terminate?

The following loop fails to terminate and I have no idea why. I've either violated some syntax rule, there's an issue with the self reference in n:= floor (n/2);, or I've missed something ...
5
votes
1answer
108 views

Context - Error creating boxes in loop

The following code creates an array of boxes to represent an array. \startMPinclusions input boxes ; \stopMPinclusions \starttext \startluacode function createGraphic(k,c,indH) local i=1 ...
2
votes
2answers
167 views

What is the correct way to generate notation for a finite set using for loop in Latex?

I am trying to create a command that will take an index n as a parameter, and generate the the expanded form of this {a_1, a_2, a_3,...,a_n}. For my first attempt, I tried to use the syntax suggested ...
29
votes
3answers
1k views

Typesetting the entire Song That Never Ends

I've heard that LaTeX (and for that matter TeX) are Turing-complete, so it should be possible to produce an infinite loop. And indeed, a quick search reveals several questions in which users have ...
5
votes
2answers
278 views

Parallel loop [python-like zip] in Tikz

An easy way to write axis labels in Tikz is: \foreach \x/\xtext in {-1,-0.5,0.5,1} \draw[very thin,gray] (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\xtext$}; Is it possible to have something ...
3
votes
1answer
103 views

using \ForEach to input chapters in a document

I have several chapters in the folder /Chapters and I have the following LaTeX code: \newcommand\chapnames{Chap1, Chap2, Chap3, Chap4, Chap5, Chap6} \ForEach {,} {\input{./Chapters/\thislevelitem}} ...
5
votes
1answer
878 views

Loop for includegraphics

I try to make multiple slides in beamer with 3 figures on each slide and the title. I would like to loop through the list/array of figures and set the frame title. The name of the figure files and the ...
3
votes
1answer
327 views

how to use \loop … \repeat to generate an arbitrary number of rows in a table [duplicate]

Possible Duplicate: Copy table row n times The code below is intended to produce a table with 3 columns and 3 rows (one heading and two empty rows) but it can be seen that it doesn't work. ...
10
votes
2answers
198 views

Is there a better formatting option for an alternated enumerated/itemized list?

I'm making a questions/answers page where answer follows the question. The questions are enumerated while the answers are not. Questions are using one color while answers using another one. In order ...
1
vote
0answers
46 views

Loop to include multiple files [duplicate]

Possible Duplicate: How to iterate through the name of files in a folder I would like to include all the *.tex files from a directory in a document. To avoid me having to add manually the ...
4
votes
1answer
486 views

Adjusting font size for fake perspective

I'd like to add text on the paths on the left side with font size continuously adjusted from \Huge to \tiny to achieve a perspective like effect. The font size steps shouldn't be \Huge, \huge, \LARGE, ...
6
votes
3answers
155 views

Expansion issue when adding to CSV list from within a \foreach

Another expansion issue that I am unable to guess at the correct combination of \edef/\expandafters to get to work. Background: Below I have defined \AddToCommaSeparateList which uses \g@addto@macro ...
8
votes
5answers
376 views

Define a command (possibly recursively) to wrap text in a command n times

I'm trying to define a new command \multiboxed in LaTeX so that I can put n boxes around an equation without having to manually nest \boxed commands. So far I have (using the pgffor package): ...
7
votes
3answers
482 views

Function to define how many lines to be displayed

I have just made a command in my own document class wherein if I type: \mline it would automatically output 5 lines only. My problem would be producing lines by just defining how many lines I want to ...
4
votes
2answers
110 views

Using a previously defined command in a loop

I have the following defined: \newcommand{\pl}{\ensuremath{p^L}\xspace} \newcommand{\pr}{\ensuremath{p^R}\xspace} \newcommand{\xx}{\ensuremath{_{XX}}\xspace} ...
7
votes
3answers
173 views

Defining commands using two loops

I would like to define a series of command using two loops. For instance I want to create a series of variables that can have YY or NN as subscripts. I would like to define commands \yy and \nn that ...
6
votes
1answer
815 views

Passing a variable from TeX to R in Sweave

I know it is possible to use \Sexpr to pass information from an R chunk to LaTeX. For example, <<echo=F,results=hide>>= a = 7 @ 42 is the answer to 6 x \Sexpr{a} Is there an ...
4
votes
1answer
218 views

How to make tabularx columns using \whiledo?

My question is similar to that discussed in How to programmatically make tabular rows using `\whiledo` ?. The difference is that I want to produce columns rather than rows with using \whiledo. ...
3
votes
2answers
237 views

having problems using arrayjobx with tikz - how can i use arrays in tikz?

I need the help of some smart people ;) I want to draw a picture with TikZ, which is heavily based on randomization and I want to make it quite parametrized. It's actually a graph of n nodes where ...
3
votes
1answer
153 views

datatool repeat row

I intend to create a document where parts of the text are read from the entries of a .csv file using the package datatool (version 2012/09/25 v2.11., updated manually under debian). Everything works ...
3
votes
1answer
227 views

A macro for looping through a pgfplotstable set by cell

Hi following on from the following question on multi-line headers with pgfplotstable, the solution was to set each affected cell individually. I decided to throw together a command to do that but keep ...
9
votes
1answer
129 views

Create a document looping through images

I have about a hundred images named 001.png to 123.png. I want to create a document which includes each image in center of a page. i.e. a 123 page document with each image on a single page. I know ...
4
votes
2answers
785 views

TikZ: Drawing the same data with scatter plots and parallel coordinates

I am new to TikZ and trying to recreate the following image (which was created in R): (Translation: correlation = +1, correlation = -1, two clusters, circle, normal distribution) Each "column" ...
8
votes
3answers
182 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
171 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
3k 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
312 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
259 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
292 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
431 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
370 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
390 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
136 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
869 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
388 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
281 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} } ...