Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

4
votes
1answer
49 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
34 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
190 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
97 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
45 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
265 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
35 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
305 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
46 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
32 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
567 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
197 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
32 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
170 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
670 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
73 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
77 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
178 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
762 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
185 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 ...
0
votes
0answers
59 views

Write pseudocode, missing number treated as zero

I've written this pseudocode and I encountered two problems. First, it shows the message: Missing number, treated as zero 4 times; and second, I can`t write code inside the loops. Even if I write the ...
1
vote
1answer
139 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
58 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
113 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
58 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
39 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
72 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
66 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
62 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
53 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
51 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
70 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 \...
20
votes
1answer
444 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
47 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
59 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 ...
3
votes
3answers
45 views

Unexpected Results from \dolistloop

Given \def\CSVList{a,b,c}, using \dolistloop{\CSVList} does not seem to process the \CSVList as expected: Perhaps I am not understanding how \dolistloop is supposed to work, but this example is ...
0
votes
1answer
89 views

LaTeX error: illegal parameter number in definition of \pgffor@b

I am trying to use a loop. The following does not work: \foreach \a in {no,has}{ \begin{table}[H] \footnotesize \captionsetup{width=.9\linewidth} \caption{text} \vspace{-22pt} ...
3
votes
3answers
117 views

Iterate over part of a list

I know that the package etoolbox has a \foreach command. I want to set a list once an use it multiple times. In the example, I would set \mylist equal to the comma separated value list 10,20,30,40,...
2
votes
1answer
66 views

Loop newcommand with variable arguments

Following my previous question, I would like to know how to have variable inputs for a newcommand in order to do the following \documentclass{article} \newcommand*{\repsum}[VARIABLE NUMBER]{ \...
9
votes
4answers
531 views

Loop code for repeated sums

I tried to read other topics regarding \newcommand* to create a macros in order to have repeated summations with a single command but I was not able to understand the logic behind it. Let me explain ...
1
vote
1answer
156 views

Creating a for loop for an enumerate environment that will take the number of items, and what the items say

I know how to put \foreach loops into tikz code, but that isn't super helpful here. I'm building a rubric and I'd like to be able to say "there are this many items in the rubric and the first one ...
1
vote
1answer
93 views

Paragraph ended before \tikz@intersect@path@names@parse was complete

MWE: \documentclass[]{article} \usepackage{tikz} \usetikzlibrary{calc,intersections,through,backgrounds,matrix,patterns} \usepackage[normalem]{ulem} \usetikzlibrary{decorations.pathreplacing} \...
12
votes
1answer
118 views

Smarter way for a drawing

Consider the following MWE: \documentclass[border=5pt]{article} \usepackage{tikz,anysize} \marginsize{0cm}{0cm}{0cm}{0cm} \definecolor{forest}{RGB}{34,139,34} \definecolor{rot}{RGB}{220,20,60} \...
1
vote
1answer
70 views

Defining a macro for tabularx line that expands counter values but doesn't error on &

I can do this with brute force, but I've run into this problem in several settings and can't seem to get the macro expansion to work out the way I want. Here's my current code (which is pretty close ...