Stack Exchange Network

Stack Exchange network consists of 174 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.

3
votes
1answer
70 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
150 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
667 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
177 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
29 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
127 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
38 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 ...
1
vote
1answer
90 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
56 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
53 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
60 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
55 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
31 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
45 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
58 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
374 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
42 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
53 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
42 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
71 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
73 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
51 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
513 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
85 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
59 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
64 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
157 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
45 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
284 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
270 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
41 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
489 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
151 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
95 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
59 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
213 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
149 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: !...
4
votes
1answer
94 views

Wrap many math macros into `\ensuremath`

I find it more natural refering to \Phi, \alpha, \sim, etc. outside math mode the same as inside math mode. I.e. writing: Consider \Phi, \alpha{} and \sim{} in the following equation: \begin{equation}...
0
votes
1answer
169 views

Insert multiple pictures

I would like to add all my certificates in my LaTeX document as pictures. Is there any way that lets me insert multiple images without captions as follows: Each image fits on one page for example ...
0
votes
0answers
41 views

hyperref: list of places that linked to a label?

I'm using the hyperref package. I can link to labels with \hyperref[tag1]{tag 1}. I want to create a list that links to every "section" that included a link to the current section. So it would look ...
1
vote
1answer
26 views

Swap many pair of command names in a row

I've learnt from this post how to swap two commands using the let primitive: \let\temp\first \let\first\second \let\second\temp \let\temp\undefined Now, in order not to flood my preamble with this ...
4
votes
2answers
100 views

Loop over the elements of an array so that each frame changes with images and cell content

I would like each frame in a beamer presentation to show a small table + 4 images. For every new frame, the 4 images change. On the contrary, only the content of one cell is changing in the table. ...
3
votes
1answer
39 views

Alternating/looping section dividers

I would like to create a section dividers that alternate/loop around several possibilities. Code I have now: \documentclass{article} \usepackage{halloweenmath} \def\SectionDivider{$$\mathwitch \...
0
votes
2answers
64 views

How to iterate/loop minipage that means execute same minpage with same content?

I have the following code where I write same minipage again and again. I want to write this minipage one time with same output. \documentclass{article} \usepackage{booktabs} \usepackage[a4paper,...
4
votes
2answers
126 views

How can I use \dolistloop from etoolbox with \do redefined in preamble?

I am trying to use \dolistloop from etoolbox with the \do-command redefined in the preamble. However, the redefinition of the \do-command is ignored. If I put it within the document, it works as ...
5
votes
3answers
199 views

etoolbox for loop over range

Is there a way to run a command on a range of consecutive integers (say, 11, 12, 13, 14, 15), specifying only the first and last numbers (11 and 15)? Basically I'm looking for the general LaTeX ...
1
vote
1answer
45 views

Writing captions automatically looking up tables or vectors

I am asking this question because I have not been able to find anything that goes straight to the point. Let's imagine that we want to automatize graph depiction in Latex, showing the evolution of a ...