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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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.

2
votes
1answer
50 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
140 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
29 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
226 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
256 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
33 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 ...
4
votes
2answers
337 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
119 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
66 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
52 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
205 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
121 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
69 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
59 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
20 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
95 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
27 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
52 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
79 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
127 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
58 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
72 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
72 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
75 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
63 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
52 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
119 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
142 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 ...
1
vote
2answers
100 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
34 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
350 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 ...
5
votes
1answer
70 views

Defining conditionals (newif) in a loop using the loop variable

I want to define a set of conditionals using newif in a loop. The loop variable should become part of the conditional's name. However, I'm running into trouble when trying to set the conditional and ...
2
votes
2answers
79 views

Creating ruled page for stationery

I'm trying to create a ruled page for stationery using customized line colors, etc. I'm currently using the memoir class as the document class. I want lined paper. I can create a single line pretty ...
0
votes
1answer
86 views

Metapost for loop of a list

Suppose I have a array of path path pat[]; I try to define a function like this: def drawpaths(expr plists)= for p in plists: pickup defaultpen; draw pat[p]; endfor enddef so that I can ...
2
votes
1answer
138 views

TikZ Feynman: Double loop

I need a specific diagram in 't Hooft's double line notation. I already got most of it but one feature is missing. My code for the diagram so far: \documentclass{article} \usepackage{tikz-...
7
votes
2answers
121 views

Loop through letters and apply a color to the first 3

I need help with these macros. What I'm trying to achieve is to loop over all the letters in the title of a custom environment. Then colorize the first three letters of that title with a different ...
2
votes
2answers
206 views

Creating 63 Idempotent Latin Squares of order 25 and then creating 3 Mutually Orthogonal Latin Squares of order 21

For an assignment in my design theory class I am trying to construct idempotent latin squares and mutually orthogonal latin squares as stated in the question. I understand the process and can do this ...
1
vote
1answer
134 views

tikz: Drawing a curve using the \foreach cycle

In tikz: drawing a parametrised curve I asked about drawing a curve using the \pgfplotfunction command. I could make my code better if I could use the \foreach cycle: \documentclass{minimal} \...
1
vote
1answer
519 views

How to write a Makefile in Windows to compile a Latex document using a loop

I need to write several documents that are fairly close to each other, i.e.same structure of header/footer, call a common set of forms. I wrote a Main.tex document with a set of \if\x 1 { my document ...
3
votes
3answers
263 views

iterating a loop macro

I tried to make a command which give depending on an optional parameter x, x-many ' signs. \documentclass[a4paper]{article} \usepackage{ifthen} \newcounter{i}% \newcommand{\commu}[2][]{% \...
3
votes
2answers
90 views

Looping up to a value of a totcount counter

I'm trying to implement a foreach loop in LaTeX limited by the value of a totcount counter, but this doesn't work at all and I don't understand why. Can this be done at all, and if yes, how? Here's ...
1
vote
1answer
87 views

expand string array in loop with label

I would like to expand one string array in a short metafun loop. Each box should be labelled with the appropriate string ("classicism", "Lumières", "romanticism"). How can I make the label function, ...
4
votes
1answer
307 views

How to use a command inside \addplot options

How can I use a command inside an \addplot option? My guess is that I'd have to find the right expansion order. The example below illustrates the problem. I'm not looking for a workaround (which I ...
1
vote
1answer
179 views

Iterate through a list by index

I'm making a TikZ picture in which I have a list of node names and coordinates and I want to go through the lists putting ith node name at the ith coordinate. My MWE: \documentclass{beamer} \...
4
votes
2answers
86 views

Does TikZ offer a concise way to test for membership in a specified set?

Does TikZ offer a reasonably native/concise way of expressing 'if the loop variable is an element of this set, then...'? Remarks. An example for what I am asking for is the pseudo-code \...
1
vote
1answer
169 views

Paragraph ended before \pgffor@@vars was complete. (\foreach)

Until now I always used \invokepgfplotsforeach{1,...5} successfully. Since I have some nested dynamic code all using #1, #2, #3, etc., I wanted to name the foreach's variable #1 by using \foreach. \...
1
vote
1answer
60 views

Creating lines of custom shapes in Tikz using \foreach

I am trying to crate a "grid" of custom shapes that takes 8 inputs: 1 = origin x 2 = origin y 3 = box length x 4 = box height y 5 = # of columns x 6 = # of rows y 7 = column space x 8 = row ...
0
votes
0answers
70 views

Compile just stops

I have this document where I make money for a board game with my own design. Now the issue: The compiler stops at page 251 (of 384 pages). No error message, nothing! \documentclass{article} \...