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

2
votes
2answers
202 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
2k 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
306 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
115 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}} ...
6
votes
1answer
1k 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
420 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
211 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
49 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
601 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
167 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
409 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
545 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
119 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
186 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 ...
7
votes
1answer
1k 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
256 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
287 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
173 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
265 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
142 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
896 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
186 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
198 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
4k 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
377 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
273 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
329 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 ...
10
votes
2answers
536 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
454 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
397 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
148 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
1k 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 ...
6
votes
1answer
481 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
294 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
3k 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
160 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 % ...
12
votes
5answers
2k 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
345 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
147 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
257 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
242 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
331 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
557 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
183 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
996 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
665 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 ...
13
votes
5answers
5k 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
458 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
272 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
297 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 ...