{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)

7
votes
1answer
99 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
175 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
118 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 ...
8
votes
2answers
242 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
260 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
35 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
229 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? ...
35
votes
10answers
3k 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
261 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
74 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
89 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
54 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
122 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
272 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
661 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
287 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
39 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} ...
5
votes
2answers
198 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
156 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
95 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
211 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
112 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
115 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
179 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
95 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
92 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 ...
7
votes
1answer
934 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} ...
6
votes
3answers
1k 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
351 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
105 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 ...
10
votes
3answers
137 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
870 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
228 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
74 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 ...
6
votes
2answers
518 views

Problems using \addlegendentry in a loop with pgfplots

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
131 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
96 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
113 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
336 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
340 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
225 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
284 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
129 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 ...
3
votes
1answer
111 views

Looping over elements to change font in math mode

I have the following code: \documentclass{article} \newcommand*{\ident}[1]{\texttt{\small #1}} \makeatletter \newcommand\ci[1]{% \def\citmp{}% \@for\reserved:=#1\do{% ...
2
votes
2answers
349 views

TikZ: drawing an evolution of an ellipse to a hyperbola with the same focus

Is there a high speed way to draw the evolution of an ellipse, to a parabola, and then into a few hyperbolas with the same focus? From the picture, we see that we start out with three elliptical ...
10
votes
1answer
100 views

Insert empty pages until certain page number

I have sections which have to start exactly at the predefined page numbers and the potentially unfilled pages between these sections should be filled with empty pages. Is there a for-loop available ...
8
votes
1answer
316 views

TikZ: Automating a process with a for loop instead of coding in each piece

I am positive I could create the incoming hyperbolas and then the deflections by the planet by hand for each one, but how the image is set up conjures up the felling this could be done through ...
3
votes
1answer
402 views

Adding PDF pages with \includegraphics using a loop

I need to include PDF pages with \includegraphics. I know there is the package \usepackage{pdfpages}. So this is what I have: \begin{picture}(0,0)(75,272.5) ...
8
votes
2answers
399 views

StrSubstitute for multiple replacements in a loop?

I am trying to replace multiple keywords using \StrSubstitute inside a loop using foreach - but unable to accumulate all the results. The result of each \StrSubstitute call is getting lost inside the ...
4
votes
1answer
192 views

Running out of main memory when using loops in TikZ

I have a TikZ drawing (namely, pairs of rulers) that I want to replicate 12 times, side by side. I'm using foreach constructs to help me in this process and to draw the 5-cm, 1-cm and 1-mm ticks for ...