The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [loops]

{loops} is about looping constructs which allow a programmer to apply the same operation multiple times, each time with possibly different parameters.

Filter by
Sorted by
Tagged with
2
votes
2answers
74 views

Missing number, treated as zero for a \loop … \repeat

I'm trying to write simple macros, which functional is to print every n = n + k-th letter from the alphabet, where k and n are counters. So I need a \loop-\repeat construction. I use it, but it works ...
1
vote
1answer
44 views

Why does `settowidth` not work inside `foreach`?

I would expect the first two a to be wide apart on the first line.. \documentclass{report} \usepackage{tikz} \begin{document} \newlength{\mylength} \foreach \i in {dum,iteration} {% \...
0
votes
0answers
31 views

Arara rule for automatic compilation of all files in a directory tree

I am currently using arara to give compilation rules for my .tex files. I have a lot of tikz/pgfplots made files which share common settings hosted in a header file, so that I can easily modify a ...
2
votes
2answers
190 views

TiKz - Draw a recursive plot with matches

I would like to produce the following draws and more. Can someone gives me some clues to achieve this easily ? I have found the following post to draw one single match : Draw a match using TikZ ...
6
votes
2answers
92 views

Is there a `for each` loop in primitive (La)TeX? [duplicate]

I am trying to iterate over the list of all basic colours: \def\thecolors{black, blue, brown, cyan, darkgray, gray, green, lightgray, lime, magenta, olive, orange, pink, purple, red, teal, violet, ...
7
votes
1answer
142 views

Plotting curves within a foreach loop and attributing colors from a colormap

I'm trying to plot curves inside a \foreach loop and at the same time define their color through a colormap. The color is given accordingly to a parameter of the curve:(\T/\Tmax*1000), where \T is the ...
4
votes
1answer
85 views

How to use dynamically generated filenames in \IfFileExists?

I have a file 0012 in the directory of the following tex file. I want to check the existence or non-existence of files inside the \forloop from 11 to 13. \documentclass{article} \usepackage{...
3
votes
4answers
88 views

Is there an `\edef` version of `\NewDocumentCommand` or `\newcommand` with optional arguments?

In a \foreach loop I want to define a bunch of macros with an optional argument (not shown in my example code). For this I use \NewDocumentCommand, but \newcommand would work, too. But how do I get ...
6
votes
3answers
231 views

How do I get a decreased-by-one \x in a foreach loop?

My problem is pretty much complicated than this one, but the point is pretty similar. \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \coordinate (A1) at (0,0); \...
3
votes
1answer
38 views

Exercise Package compilation error

I have a series of Questions saved as separate tex files and want to loop over them to place them in the document using the exercise package. If I loop over the Questions I get a compile error. ...
4
votes
2answers
186 views

Missing number while using loops

I've been trying to read a number of tex files into a tabular. I have two sets of files numbered t_1.tex ... t_10.tex and a_1.tex ... a_10.tex. This is the code I have so far: \newcount\ii \ii=0 \...
0
votes
0answers
36 views

Way to automate how many weeks are in a given month and year

I am writing a short piece of code that, among other things, generates a customized calendar with some specialized formatting and content. I have everything working fine, except there is one ...
10
votes
3answers
588 views

Plotting Autoregressive Functions / Linear Difference Equations

Assume there to be some function $k_{t+1} = f(k_t)$. Is there any smarter way to plot a path starting from $k_0$, doing $n$ steps? Thanks in advance. \documentclass[ paper=A4, fontsize=...
6
votes
1answer
92 views

How to write a loop to reflect a path (Asymptote)?

I am trying to shorten a code that contains a lot of reflections by writing a loop: [asy] unitsize(1.5 cm); pair A,B,C; real alpha=(20); real beta=(10); real gamma=(180-alpha-beta); real rad=(pi/180)...
1
vote
0answers
24 views

Looping through `readarray` inside a TikZ environment

In Tikz, how can I loop through a readarray object? \documentclass[tikz, border=0mm]{standalone} \usetikzlibrary{calc} \usepackage{array} \usepackage{readarray} \readarraysepchar{,} \usepackage{...
3
votes
1answer
60 views

Programmatically Illustrating an Expansion Permutation

Based on the discussion over here, I drew this: With this code: \documentclass[tikz,border=3.14mm]{standalone} \usepackage{tikz} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%...
4
votes
1answer
48 views

Print range of many group rows in datatools

I use this code from this answer: \documentclass{article} \usepackage{filecontents} \begin{filecontents*}{product.tex} %Type =1,2...10 No,Type,Name,Description 1,1,A1,D1 2,1,A1,D2 3,1,A1,D3 30,1,A1,...
2
votes
2answers
90 views

using '\foreach' loops to draw tikz figures

I am using \usepackage{tikz} to draw something using xyz coordinates. I have a bunch of coordinates named (xyt) such as (000) (001) (020)...(001)(011) etc, they are created by: \coordinate (ijk) at (...
9
votes
2answers
914 views

Programmatically Illustrating Permutations

Here's an illustration of what's known as an expansion permutation (the top half). It just means that instead of going straight through (like the bottom half aka. the identity permutation), the signal ...
1
vote
2answers
60 views

doubling up on edges in a tikz graph

I made the following diagram based on an excellent, very interesting answer to an earlier question. %%% Preamble %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \documentclass[border=9,...
1
vote
1answer
52 views

Multiple loops position in Tikz state diagram

I am trying to make a state diagram with Tikz, my code is below. The problem is I can't figure out how to make the position of the self-loops in a state not 'crowded'. I tried changing the values in ...
5
votes
2answers
139 views

Fast membership test for integer lists/sets

Say we have big list of integer numbers, stored as comma-separated values in a macro or token register. Now we want to test in a loop for every integer n = 1, 2, ..., N if n occurs in the list of ...
6
votes
3answers
146 views

Basic calculations in PGF/TikZ for loop

I've seen a bunch of similar questions and answers relating to the same kind of problem, but they either weren't particularly well explained or something got lost in translation somewhere. So I ...
0
votes
1answer
103 views

Read file using LaTeX

Problem I am planning to read source code of a open-source project. With a (perhaps weird) habit, I often print all the source codes according to the way they are organized (in particular, the ...
1
vote
1answer
66 views

Evenly distributed random non-stops

I am trying again to recreate some strange images. I am trying to generate hexagons of nonstop with three colors. The distribution of these three should be Color 1 = (N-1)^2 Color 2 = (N-1)*N Color 3 ...
3
votes
0answers
53 views

Doing iterative arithmetic inside of an iterative tabularx

I'm trying to create a matrix table that will iteratively fill in the cells based on inputs that I can change. I originally tried the solution shown here, but I wasn't able to get Latex to properly ...
4
votes
1answer
64 views

Drawing colored sticks

I am trying to draw some "matrices" that looks like this So above the diagonal the sticks should be blue and below they should be red. Using some help from the answer by marmot in my previous ...
1
vote
1answer
42 views

LaTeX code with input dependent on some integer parameters

Suppose that I have a large number of .tex files with names 1.tex, 2.tex, ..., N.tex (with N = some integer). I would like to write a LaTeX document, where I set some parameters for example: howMany ...
10
votes
3answers
233 views

Smart-expansion of a range to a list of numbers

I am wondering if there is a simple way to expand some input text such as "3-7" as "3,4,5,6,7"? For context, I am using \foreach and want to be able to write \foreach \x in {3-7, 9, 14, 52} and ...
5
votes
3answers
113 views

Looping over charts and names simultaneously

I want to use a common index to loop over two separate comma-separated lists at once, one which is a list of abbreviations and one a list of names. I want to use the abbreviations to import charts as ...
0
votes
0answers
27 views

why this loop generate different output when inside tikzpicture vs. outside? [duplicate]

I wanted to debug some tikz code by printing some values inside a loop when I noticed the output is not coming out as expected. If the loop is inside a tikzpicture with nothing else added, the output ...
1
vote
1answer
76 views

Loop incompatible with animateinline newframe?

EDIT: Marmot has provided me with alternative solution, for which I'm very grateful. Question however remains because I'd like to learn what was wrong with my approach. I want to make a presentation ...
1
vote
1answer
86 views

loops on columns inside tabular environment

What is the proper way to use loops inside the tabular environment? The context of my question is generating tables using the datatool package. I need the following features: In each row, I want to ...
2
votes
1answer
623 views

How to loop over the JSON object / list?

I want to loop over section in the following JSON and print name the number of times it appears under section. How could I do this? { "ID": "23", "section": [ { "name": "A", ...
2
votes
2answers
46 views

If clause within a loop

I have a similar issue as the one discussed here If condition controlled with a loop variable. To summarize my case: when looping through a continous range of numbers, from 1 to 24, I'd like do ...
1
vote
1answer
45 views

Creating a unique list from two tables read from filecontents

I have two tables.. one contains attributes with values e.g. Name percentage Atr1 80 Atr2 20 Atr3 50 and the other one contains tools for that attribute Attribute Tool Atr1 SK Atr1 SL ...
6
votes
5answers
316 views

Nested loops to process groups of pictures

The following MWE processes groups of pictures, placing them on a slide with a caption below the picture. The slides are made using the pdfscreen package, and the picture and caption placement is done ...
0
votes
1answer
141 views

tikz: Label number of edges

In the following picture there are multiple edges between two vertices. But I am able to draw single edge. So I want to label the number of edges. How can I do it? For example there are $3$ edges ...
0
votes
0answers
83 views

probsoln error: “undefined control sequence \repeat” in a loop

For context, I am using the probsoln package to create a list of problems and solutions. The problems and their solutions come from files in the same directory titled bank_lesson1.tex, bank_lesson2....
5
votes
3answers
597 views

How to draw/optimize this graph with tikz

I would like to know if is there a way to optimize the code that I use to draw the next graph: I do it using this: \documentclass[11pt]{article} \usepackage{tikz} \begin{document} \begin{figure}[h]...
4
votes
2answers
212 views

Problem when applying foreach loop

I'm trying to find the minimum x coordinate in a set of TikZ coordinates. Consider this code \documentclass[tikz]{standalone} \usetikzlibrary{positioning} \newdimen\x \newdimen\xmin \xmin=10000pt \...
1
vote
1answer
31 views

What is wrong with my \foreach statement

The code below works fine \begin{tikzpicture} \begin{axis} [ ticks = none, axis lines = middle, xmin = -5, xmax = 5, ymin = -5, ymax = 5, ] \foreach \p in {1,2}{ \...
1
vote
1answer
52 views

Adding additional text to some elements of a loop?

The following question stinks a bit of crazed micro-optimization. But I had written it, and I was a bit curious, so I thought I might as well post it. The following loop iterates over inserting some ...
6
votes
1answer
220 views

Using for loop in tikz to draw repeated shapes

I am trying to create a lenticular pattern like the one in the picture. I believe the repeated shape can be drawn using a for loop in tikz, but I wasn't able to get it done properly. Appreciate any ...
0
votes
1answer
38 views

Looping for Two-column Signature Blocks

I'm trying to create a two-column area for signatures, so folks signing the document are listed in the left column or right column, and there are enough rows to accommodate everyone's signature. Under ...
1
vote
1answer
52 views

Generalising a second-order macro with loops

I'd like to construct a macro that can be used to define commands. Those commands behave like variables or structs of variables, such that they can contain multiple values. The "member" is passed via ...
16
votes
4answers
770 views

Using loops to create tables

The goal is to create the following table without having to typeset all the rows one after another but using some kind of loops like the \foreach command provided by the pgffor package MWE \...
2
votes
2answers
89 views

Loop over greek letters with pgffor

I am currently combining solutions proposed here for the loop definition of commands and here for the upper case letter forcing to define mathematical notations in a loop. The goal is to have a ...
3
votes
1answer
93 views

what is a better way to generate iching 64 hexagrams?

If I have list for iching (bagua) trigrams as follows, what is the best way to generate 64 hexagrams as in shown in the image attached? I can use the use the binary code (e.g.{1,1,1}) for either color ...
6
votes
2answers
193 views

Removing a number of tokens from the input stream

I need a command which removes all following tokens which are digits, comma, spaces or newlines and stops if it encounters something else. I can do it by nesting a lot of \...