{loops} is about looping constructs which allow a programmer to apply the same operation multiple times, each time with possibly different parameters.

learn more… | top users | synonyms (1)

8
votes
2answers
156 views

How does expansion matter?

\newcount\@repeat% \def\repeat#1#2{% \@repeat#1\relax% \ifnum#1>\z@\relax% \advance\@repeat by -1\relax% \repeat{\@repeat}{#2}#2% \fi}% \repeat{2}{1}\\% \repeat{11}{f}\\% ...
4
votes
1answer
40 views

TikZ: issue with lines in foreach loop

\documentclass[tikz]{standalone} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \coordinate (h) at (0, 3); \coordinate (O) at (0, 0); \draw (O) -- +(-3, 0); \draw[-latex] (O) -- ...
4
votes
1answer
51 views

\foreach not behaving in axis environment

Am hesitant to ask yet one more embarrassing question, but I can't seem to see the problem with the \foreach in the MWE. It should produce several horizontal lines but only produces the one with the ...
3
votes
1answer
43 views

Beamer and a for each loop

I'm using the beamer presentation package and trying to combine the examples from this post How to iterate over a comma separated list? with the beamer package. In modifying the top example, chaning ...
3
votes
1answer
62 views

Latex - figures side by side using loop

I am trying to put 6 figures in 3rows & 2 columns: \foreach \x in {1,2,3,4,5,6,7,8,9,10,11,12} { \begin{figure}[h] \caption{This is the caption.} \vspace{0.0cm} \centering \includegraphics[height ...
6
votes
4answers
136 views

How to fill a dynamically generated table with dynamic content?

how do I generate a tabular dynamically while filling it with dynamic data? Example: Let's say I have \def\N{10} and I want to generate a table with \N columns, where the top cell of each column ...
6
votes
1answer
37 views

How to add a \global before \pgfmathsetmacro?

It seems that one can't add \global before a \pgfmathsetmacro as that yields: You can't use a prefix with `\begingroup'. But that is the functionality I need here. I am trying to compute the ...
4
votes
3answers
143 views

Creating commands with a TeX `for` loop

I am trying to create many different commands based on a single command (essentially a custom header) in a predictable way. Is there a way to do this in TeX/LaTeX? My specific example: I'm writing a ...
7
votes
2answers
88 views

\foreach from 1 to 1 [duplicate]

How to make a command (without testing) that contains a foreach loop that may count from 1 to 1 if necessary ? \documentclass{minimal} \usepackage{tikz} \newcommand{\boucle}[1]{% \foreach \x in ...
7
votes
2answers
149 views

How to make a portion of curve red using TikZ?

I want to make the the closed loop part of the figure by "ultra red" color only and the other part by blue. (from (2,0) .. (0,0.93) .. (-0.93,0) .. (0,-0.93) .. (2,0)) \documentclass{standalone} ...
2
votes
1answer
99 views

Dynamic table column generation

I'm trying hard in finding a way to streamline my table generation. As you can see in the attached code, the problem is related with the code "\@for \el:=#1\do{\textbf{\el} &}", where "&" ...
0
votes
1answer
28 views

Forloop macro does not work with other macro in condtion

This is my primative code: \documentclass{article} \usepackage{xstring} \usepackage{ifthen} \usepackage{pgfkeys} \newcommand{\setvalue}[1]{\pgfkeys{/variables, #1}} ...
7
votes
1answer
58 views

How to remove end-if in algorithms

I am writing an algorithm in latex, but there are lots of end-if and end-whiles in my algorithms which makes it un-professional and ugly. Is there a way to remove them from output of latex? ...
31
votes
10answers
2k views

How to iterate over a comma separated list?

How can I iterate, loop, process, or otherwise do something, with each element from a comma separated list of things? This question has been asked perhaps many many times, and the are already lots of ...
5
votes
1answer
218 views

Plotting loops: trajectories and directions

Plotting loops: trajectories have directions. How to plot the following figures using tikz 1st I start to plot the 2nd fig using the code \begin{tikzpicture} \draw (3,2) ellipse (.5cm and ...
0
votes
1answer
35 views

exsheet print several exams same document

How to print several exams in the same document using exsheets? I need to print several exams using \includequestions[random=1]{easy} \includequestions[random=1]{medium} ...
1
vote
0answers
56 views

array and loop to set frametitle, subsection, and text

In the example below, I store text into three variables (\subTa, \subTb, \subTc), and then use these variables to set the subsection, set the frametitle, and display text on each slide, all using ...
2
votes
0answers
46 views

Using a for loop to loop through sequentially named tex files [closed]

I'd like to loop through all .tex files in a directory using code that looks like the following: \documentclass{article} \usepackage[hmargin=1cm,vmargin=1cm]{geometry} \usepackage{pdflscape} ...
11
votes
1answer
116 views

PGF's `foreach` recognises when there are no list items and doesn't run the code. Is this guaranteed?

The PGF \foreach macro behaves differently when the item list is totally empty than it does when a single item happens to be empty. \documentclass{article} \usepackage{pgffor} \begin{document} ...
2
votes
1answer
99 views

How to loop over R objects OUT OF chunks

I want to typeset with TeX a report based on data from an R object (dataframe). The idea is to print a nice TeX table from each line of a R dataframe. Something like \begin{tabular}{ l c r } A1 ...
8
votes
2answers
248 views

LaTeX Loops in \newcommand

I have used LaTeX for about a year now and every time I write a paper I try to improve on my knowledge so recently I've been creating my own commands to help save time. I am interested if it is ...
6
votes
3answers
169 views

How can I get these two nested \foreach loops to work?

I try to use nested \foreach loops to create edges between many nodes. \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node (a) at (0, 1) {}; \node (b) at (0, ...
1
vote
0answers
26 views

Label of figure in a for loop

I am adding figures to my TeX file using the following code: \foreach \paramA in {a,b,c} { \foreach \paramB in {1,2,3} { \begin{figure} \addOneImage{pathToImage/imageName_\paramA_batch\paramB.png} ...
4
votes
2answers
128 views

How to get the number of elements in a \foreach loop?

Does the PGF command \foreach provide a simple possibility to get the number of elements iterated? It has a parameter count to hold the current element number, so a workaround is to iterate the list ...
6
votes
2answers
131 views

Can I automatically draw my cards from a list?

So, I've made a format to print cards out (Shown below). Is it possible for me to fill each card environment from some sort of list, instead of having to write out \cards{foo} for each card? I could ...
3
votes
2answers
80 views

highlighting vowels using a background color [duplicate]

Is it possible to give the letters a,e,i,o,u,y a different background color in a piece of text by using a loop or package? For instance, give the a's a red background, the e's a blue background, etc. ...
10
votes
2answers
137 views

Dynamically define commands

I have some latex code that goes a bit like this: % Sp defines a generic command for an arbitrary space, % and all of the others just delegate the bulk of their % work to it so that when I decide to ...
3
votes
1answer
93 views

Xparse macro with optional parameter breaks value for PGF foreach

I write a document class and want to execute something a certain number of times, depending on a user-defined quantity. So I thought I'd use a foreach loop from PGF together with accessor macros: ...
10
votes
4answers
109 views

Results of xfor loop failing with numerical arguments

I am trying to write a macro that selects an item from a comma separated list, \select{2}{A,B,C,D,E} results in B. I am using the xfor package to process the list, but would try etoolbox if that ...
5
votes
1answer
129 views

Three loop diagram

I want to make a three loop diagram such as the one on the left. I use the following script \fmfleft{i}\fmfright{o} \fmf{boson}{i,v1}\fmf{boson}{v2,o} ...
2
votes
1answer
73 views

Conditional assignment in a loop

Objective: I want to compile the temporary.tex file containing PSTricks code twice. One with -jobname=Rotated and the other one with -jobname=Unrotated. The resulting Rotated.ps will be passed to ...
6
votes
2answers
81 views

Extra row appearing in table assembled in pgf for loop

I'm constructing a table one line at time inside a \pgfplotsforeachungrouped. An unwanted line appears after the \hline at the end of the last round of the loop as evidenced by the lone decimal point ...
6
votes
1answer
295 views

TikZ Self Loops Style Question

I have a question on how to "style" the self loops in my diagram. Here is my preamble: \documentclass[letterpaper]{tufte-handout} % Additional LaTeX Packages \usepackage{amsmath} ...
5
votes
3answers
291 views

Nested lists in \foreach loop in TikZ

I want to draw a bunch of nodes with different styles (a, b, ...) at different points (named 00, 01, ...). I am using the following code: \foreach \n/\lst in { a/{00, 14, 20, 34}, b/{01, 11, 23, ...
27
votes
2answers
295 views

What's the difference between the various methods for producing for loops?

I've been wondering about the various methods available for looping over a comma separated list and the like. In particular, I was wondering about their various strengths and weaknesses. In other ...
4
votes
1answer
67 views

Loop Multi-Contingency using etoolbox

I want to use the etoolbox package to manage some loop contingencies over a counting index. In particular, I'd like to do something different on the first and last times through the loop. Now I can ...
0
votes
0answers
17 views

Figures in latex using loop [duplicate]

To put maximum of 6 figures in 3 rows & 2 columns in a A4 page using loop, I tried like: \foreach \x in {1,2,3,4,5,6,7,8,9,10,11,12} { \begin{figure}[h] \caption{This is the caption.} ...
10
votes
3answers
118 views

Looping Through a Nested List

I have a hunk of data like so: { { {AA},{AB}, ... {AZ} }, { {BA}, {BB}, ... {BZ} }, ... ... { {ZA}, {ZB}, ... {ZZ} } } defined in a macro called \clebschdata. Each term XX is a list of eleven ...
30
votes
2answers
836 views

Color all vowels differently in a LaTeX document

Is it possible to give the letters a,e,i,o,u,y a different color in a piece of text? For instance, color all the a's red, the e's blue, the i's green, etc. EDIT: Without doing it manually of course.
15
votes
3answers
214 views

Printing the first N terms from a telescoping series

I would like to produce a LaTeX document that generates the first N terms of the telescoping series sum(1/k-1/(1+k)) where k=1,2,3...,N, such that it displays at least the first 10 terms. I want the ...
8
votes
1answer
70 views

Splitting file into lines and lines into parts

I'm working on a song book using LaTeX. It's early in the project, and the songs aren't all picked out yet, but I thought I'd fix the inner workings of it in the meantime. Since many people will ...
5
votes
2answers
224 views

Problems using `addlegendentry` in a loop with `pfgplots`

I have some spectra to plot, which I exported from the Siemens Xray toolbox, which works nicely with pgfplots. Since these are multiple files that look the same I think I can do it with a for loop, ...
3
votes
1answer
110 views

How to put a series of figures in annex

I want to put 51 figures , with names 0001.png ,....., until 0051.png, in annex ans I'm wondering if I can do something similar to this in latex . for i series_of_figures; put figure in annex , with ...
3
votes
1answer
90 views

Why do the following nested loops spin beyond my expectation?

Let's consider the following code that reflects my simplified scenario. I want to show a distinct integer for each slides. Of course the real scenario is not to do such a silly thing. ...
6
votes
2answers
92 views

Separators for author group (IF conditon)

I am new to LaTeX, just a beginner, basically a Perl developer. I have created a LaTeX file \begin{document} \cont{\iname{\isurname{Name1}\ifname{K. C. G.}}\iname{\isurname{Name11}\ifname{Y. ...
5
votes
2answers
256 views

How can I label TikZ-graphs on four vertices with a loop?

I need to draw all these simple labelled graphs on four vertices. Anyway, can I do this in a quick manner with a loop? And put them in an array? I have already drawn all unlabelled simple graphs on ...
10
votes
1answer
241 views

XeTeX UNICODE Table

I would like to try to write a minimal XeTeX source that generates a comprehensive UNICODE table, substituting in local fonts as required by the current plane. I made the attached code as an MWE for ...
3
votes
1answer
135 views

Creating a list of 'stacks' leads to 'Argument of \@firstoftwo has an extra }'

the title may be confusing, but I'm not sure how to name it better. This current question is the result of my other ones, and the hints I got from users in this board. Steven B. Segletes helped me ...
5
votes
1answer
189 views

Package PGF Math Error: Sorry, an internal routine of the floating point unit

This type of error (! Package PGF Math Error: Sorry, an internal routine of the floating point unit got an ill-formatted floating point number ...) arises when trying to use a predefined list for the ...
2
votes
1answer
83 views

LaTeX: Different spaces when using readarray, whiledo and value

The answer of the following problem is given in Ulrikes Comment. Thank you very much! I am trying to use external data for similar documents I have to write. The number of these data varies so I ...