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.

0
votes
0answers
16 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....
6
votes
3answers
333 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]...
5
votes
2answers
189 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
30 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 ...
7
votes
1answer
165 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
21 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
46 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 ...
17
votes
4answers
595 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 \...
3
votes
2answers
64 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
76 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
168 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
705 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
181 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
44 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
134 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
48 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
102 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
57 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
36 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
60 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
65 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
59 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
47 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
50 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
66 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
397 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
44 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
58 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
83 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
91 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
57 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
524 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
118 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
73 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
117 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
68 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 ...
2
votes
1answer
65 views

loop makes empty tabular

First, I have seen a couple similar posts, which is how I got as far as I have gotten: loop and char & problem with using loop inside the tabular environment I am also pretty sure this could be ...
7
votes
2answers
161 views

Simplify things in TikZ

How can I simplify some positioning with some foreach loops or some own styles? Here is the original picture: And here is my MWE: \documentclass[border=5pt,tikz]{standalone} \usetikzlibrary{calc} \...
0
votes
0answers
52 views

Usage of While-do constructs LaTeX

I'm curious, when reading about the ifthen-packages I've come across the syntax of while-do statements. What are they used for ? For example this piece of code from the documentation (this is copy-...
6
votes
2answers
297 views

How to print a line break in a loop in Plain TeX?

Let's say I have this simple loop: \newcount\u\u1 \loop \the\u~ \ifnum\u<2 \advance\u1 \repeat This prints the numbers as 1 2 What I want to achieve is 1 2 To do so I ...
6
votes
2answers
276 views

Produce a table with numbers given by another macro

I want to create a table with the numbers added by latex itself and the terms are left aligned. First I ask a question about how to produced a multiplication table. And I try to use \newenvironment to ...
2
votes
0answers
43 views

Double loop in Plain TeX [duplicate]

I want to test double loop in Plain tex but i use latex instead since tex command doesn't work. Here is an example. I want to use TeX to produce something like this: 1+1 1+2 1+3 1+4 2+1 2+2 2+3 2+4 ...
5
votes
2answers
549 views

Color names in foreach loop

Edit: I can't delete this question despite it being based on a silly mistake. Please don't waste time reading/answering. I'm trying to draw a row of boxes which alternate colours, and I'm using a \...
3
votes
1answer
161 views

movie creation using tikz

I would like to create a movie using tikz images, but it seems a lot of work without some sort of automation. I have a background mesh of triangles, and a red line crossing them. At each of the ...
5
votes
3answers
102 views

Use array-meaningful ampersand to change column in foreach loop

I wish to loop over this code: \begin{tabular}{l*{8}c} first column & column a & column b & column c & column d & column e & column f & ...
2
votes
1answer
63 views

expl3: making arguments from a loop

Here's what I'm trying to do: \documentclass{minimal} \usepackage{expl3} \ExplSyntaxOn \cs_new_protected:Npn \erw_loop:n #1 { \int_zero:N \l_tmpa_int \int_do_while:nNnn {\l_tmpa_int}...
7
votes
2answers
216 views

Macro not working in foreach loop

I'm trying to color the cells in a few columns with different colors, depending on bounds passed as an argument. I would like to have one macro that takes two arguments: a .csv file and a comma ...
2
votes
1answer
166 views

Error of \begin{problem} ended by \end{problem}… huh?

So, I know if I get a mismatch error like error: \begin{problem} ended by \end{document}, that means I have mismatched number of \begin and \end commands. But here, I am getting the following error: !...