{loops} is about looping constructs which allow a programmer to apply the same operation multiple times, each time with possibly different parameters.
12
votes
2answers
843 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
...
11
votes
1answer
1k 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:
...
16
votes
3answers
1k views
Comma delimited lists
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 ...
5
votes
1answer
293 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: ...
21
votes
6answers
1k 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 ...
24
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 ...
6
votes
2answers
608 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 ...
1
vote
1answer
569 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. ...
19
votes
2answers
987 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}
...
8
votes
5answers
1k 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 ...
8
votes
3answers
354 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
...
6
votes
2answers
412 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.
...
14
votes
4answers
694 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 ...
9
votes
4answers
2k 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:
...
8
votes
5answers
306 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}%
...
8
votes
2answers
959 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 ...
3
votes
1answer
1k 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 ...
2
votes
2answers
283 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.
...
9
votes
2answers
1k 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. ...
7
votes
3answers
178 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 ...
7
votes
2answers
217 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 ...
6
votes
1answer
188 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
231 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
461 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
240 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}
...
9
votes
4answers
338 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}}
...
8
votes
5answers
294 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):
...
8
votes
3answers
163 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 ...
8
votes
6answers
520 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}}
...
7
votes
3answers
108 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
2answers
208 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?
7
votes
7answers
688 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
3answers
109 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 ...
5
votes
3answers
580 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 ...
4
votes
2answers
2k 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 ...
3
votes
1answer
117 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 ...
3
votes
2answers
469 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" ...
3
votes
2answers
163 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 ...
2
votes
2answers
636 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} ...
