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
60 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
770 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
votes
0answers
26 views

How to save files with same name in folder in python? [closed]

I have two folders with images. Let the two folder names A and B. A contains 100 files and B has only 80 files. Both the files have the same name. I want to save only the 80 files from A which has the ...
1
vote
2answers
51 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
44 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
96 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
132 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
61 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
63 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
52 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
57 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
37 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
204 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
101 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
24 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
48 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
81 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
309 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
40 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
36 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
309 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
61 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
41 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
576 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
200 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
30 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
35 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
184 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
29 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
47 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
693 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
74 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
81 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
183 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 \...
6
votes
7answers
793 views

Drawing concentric circles with alternating colors by means of \foreach in TikZ

I would like to draw concentric circles like these: by means of TikZ and \foreach command. The way I achieved it is very elementary (and burdensome): \documentclass[standalone] \usepackage{...
7
votes
5answers
189 views

Loop over an optional argument

I'd like to use the command \foo with an optional argument to step and print the counter value iterated according to the number passed. So, for example, \foo[5] should step the counter 5 times, one ...
1
vote
1answer
141 views

The construction of Rooty helix, code explanation

Could someone please explain some parts of this code? I'm newbie on LaTeX and could not understand some parts. What does this \foreach \y in {86,38,15} means? Could you explain with details what is ...
1
vote
1answer
66 views

Input variable as argument in metapost script?

I would like to pass input parameters into my .mp script. For example, instead of running: mpost script.mp I want to run something like: mpost script.mp 1 1 2 diamand Where "1 1 2 diamond" are 4 ...
2
votes
1answer
116 views

Creating automated equation list of symbols using glossary

I want to define a macro to add an automated symbol explanation under an equation. I have to use pre-defined glossary entries because the \glsentrycurrent does not allow to add new glossaries in the ...
5
votes
1answer
59 views

TikZ - Edges not positioned properly when using \foreach loop

I want to draw a graph like this: Which I can do well enough with the following code: \node[circle,draw] (v) at (0,0) {$v$}; \foreach \i in {1,...,6}{ \node[circle,draw] (u_\i) at (180 - 360/6 * ...
3
votes
1answer
40 views

Reusing of DeclarePairedDelimiter in a foreach manner

I'd like to reuse mathtools DeclarePairedDelimiter in a foreach loop manner, but I have never done any low-level (La)TeXing before. Here is my code: \documentclass{article} \usepackage{mathtools} \...
2
votes
1answer
75 views

\ForEach fails with underscores

For the automatic generation of reports I'm using the \ForEach loop of the forarray package. This is just great as it saves me lots of time. However, there is one issue: When the items I iterate ...
1
vote
1answer
67 views

Is it possible to provide alternative text to use when copying text from the PDF? Part 2

A follow up to this question. For this and quite a few other fonts, the small cap glyphs show as uppercase when copied, as in line 1 and 4 in the output below. I am trying to override each individual ...
2
votes
2answers
63 views

How to put multiple paragraphs in single \loop … \repeat

I wanted to create list of n Fibonaci numbers. This is my code so far: \newcount\n \n=5 \newcount\a \newcount\b \newcount\i \a = 1 \b = 1 \i = 0 $a = \the\a$ \par $b = \the\b$ \par $i = \the\i$ \...
1
vote
1answer
57 views

Define a pic with multiple argument and use them in for loop

I have drawn this: With this code: \documentclass{article} \usepackage{tikz} \tikzset{pics/message/.style={code={ \draw (0,0) rectangle (4,1); \draw foreach \X in {1,2,3} {(\X,0) -- (\X,1)}; }}} \...
2
votes
1answer
57 views

Outer loop terminating early

I'm trying to implement the Euclidean Algorithm in LaTeX. Yes, I know I could do it more easily in python, but that's not the point. I have an inner loop (extracted to a macro) to compute the ...
3
votes
3answers
72 views

Running a loop until x mod 10 =0

I need something like this LaTeX: while x mod 10 != 0: x++ My LaTeX translation which compiles infinitely is this: \newcommand{\lfn}{ \loop \ifnum \pgfmathresult<1 \...
21
votes
1answer
467 views

Make a holiday calendar with automatic “school week numbering” in tikz

I am trying to make a two sided holiday calendar (DIN A4, two pages for one school year). For this I started with an example from Robert Krause and tried to modify it. Here is how it looks so far: % ...
2
votes
1answer
49 views

Documentation of loop over item

In this answer there is a loop construct used called loop over item. I am looking for a documentation of this and for a reference in which file it is defined. \ifdate{workday} { \tikzset{every ...
3
votes
2answers
60 views

File name not handled correctly in /foreach loop

For some reason when I try to specify a file name for \includegraphics in a loop, either using \foreach or using \clist, I get a file not found error. The error displays a valid path for the file, and ...