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.

1
vote
1answer
46 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
1answer
28 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
21 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
41 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
49 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 \...
16
votes
1answer
269 views
+200

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
38 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
48 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
40 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
33 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
52 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
31 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
490 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
23 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
39 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} \...
11
votes
1answer
112 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
66 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
60 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
144 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
33 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
248 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
262 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
37 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
408 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
131 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
74 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
54 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
206 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
128 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
76 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
95 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
40 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
21 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
96 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
34 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
55 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
94 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
148 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
34 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 ...
1
vote
2answers
59 views

How can I automatically surround each new item in a token list with braces as delimiters?

I'd like to know how to create a macro that can append new elements/items to a macro list (token list) BUT also adds { and } around each added item. Example I'd like it to save each new item like ...
5
votes
1answer
76 views

Loops in tikz for accessing labels

I would like to create something like this drawing using Tikz: I found a nice tikz example that creates something similar: \documentclass[border=10pt]{standalone}% \usepackage{tikz} \begin{document}...
1
vote
1answer
82 views

Tikz Feynman fit a line inside a loop

I am trying to write a two loop Feynman diagram in a particular format (using pdflatex!), basically with a line dividing in half a loop. Unfortunately while the outcome in the image below is almost ...
0
votes
0answers
86 views

LaTex \input from .txt file containing .tex entries

I have been searching/browsing different examples but cannot seem to find the answer I am looking for. I have a .txt file that lists the names of .tex files in my directory: contents of example.txt: ...
0
votes
2answers
84 views

Problem with \ifthenelse inside some loops

Why this code produce some value not in the diagonal? Nine in total all below the diagonal. \documentclass{article} \usepackage{tikz} \usepackage{ifthen} \begin{document} \begin{tikzpicture} \...
0
votes
1answer
54 views

Calling Lua on the output of a \@for loop to add “and” to the end of a comma-separated list

I'm trying to make a package-free command that applies a command across a comma-separated list, and then adds the word ``and'' to the output as is grammatically appropriate. I've already gotten some ...
3
votes
4answers
120 views

Macro to apply a custom command across a comma-separated list

I want to make an apply function that can apply any single-argument command to a comma-separated list of arguments, and print the results separated by commas. (ETA: I want to make the command from ...
3
votes
1answer
174 views

TikZ: groupplot with nested foreach loops to highlight background of profile

I'm trying to use \groupplots and \pgfplotsinvokeforeach to generate a dynamic picture showing different profiles. Within those profiles I'd like to highlight different ranges (sequences) with a ...
2
votes
2answers
157 views

Iterate over an array

Let us assume this example \documentclass{article} \newcommand\printlist[1]{ Loop to get each element \el and its index \ind from {#1}{ \ind. \el\\ } } \begin{document} \printlist{A, B, C} \...
1
vote
0answers
37 views

Tabular splitting in cells with automatic split and words fitting

I need to create a 3 columns of the same width and split it into cells of the same hight, so when I print text and formulas it will automatically placed in the next cell if it doesn't fit. So when I ...
5
votes
3answers
359 views

Foreach loop in Preamble

I am familiar with the \foreach loop in the TikZ pakage. Is there an analogous loop I can use in my preamble? I like to use \M, \A, \I, and other commands as shorthand for matrices. So instead of ...