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

6
votes
1answer
38 views

Generate barcodes with a for loop

I want to create labels with barcodes. The individual barcodes should be a sequence of numbers which identify objects. After some trial and error, the GS1 package seemed to work for me. Since I have ...
3
votes
1answer
67 views

Is there any way to draw the same shapes at different positions efficiently, for example \foreach?

I know there is a similar question, but I do not think it gave the best solution. Here is my code: \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm] \clip(-0.5,-1) ...
4
votes
4answers
155 views

Expandable macro with loops and advanced string functions?

This might be a very basic problem (as a follow-up to this question) but I cannot figure out how to do it: I need a macro \mycmd{sometext} that yields a string depending on the first character of its ...
1
vote
1answer
31 views

Defining newtheorems using loops

I would like to define Theorem x.y say x,y are integers between 1 and 20. Then, I need to write 400 sentences like \newtheorem*{theorem1.1}{Theorem 1.1}. EDIT: I'm typping some old book in a ...
3
votes
2answers
39 views

Error in foreach loop when number range defined with a macro

I am having problems to implement a loop that runs over the months of the year and the days of each month. A simple representative example of my current approach is shown below. ...
4
votes
2answers
84 views
+50

Printing Solutions on Different Page

I have the following source code that generates random questions regarding conversions from Arabic to Roman Numerals. I would like the solutions to be printed on a new page after the exercises end. I ...
15
votes
4answers
347 views

Preparing a special exam sheet for every student

I am wondering if there is a way to read the data from an excel file and then somehow using a forloop outside a tabular, get a special exam sheet for each student. Until now, we have been using a ...
2
votes
1answer
41 views

How to print all the picture in the root directory?

I have many pictures in the root directory like this: I want print all of them in .pdf files. It is too effortless to do it one by one. How to do it efficiently. Thank you!
2
votes
2answers
107 views

How to check for more elements a foreach loop?

I want to check if there are more elements in a foreach loop. How can this be done? This is an example for loop: \foreach \p/\q in {a/{1,2,3}, b/{4,5,6}} \foreach \r in \q { (\r) } EDIT#1 An ...
5
votes
1answer
72 views

How can I use \foreach in math environments?

I'm looking for a way to generate in a loop the rows of an align environment, or IEEEeqnarray or some such thing. I can see that \foreach works in math mode (inside \[ \] e.g.), but something like ...
2
votes
1answer
43 views

longtable and for loop problem

Can anyone explain me the difference betweeen the following to tables? Why has the second one an additional line with one column? \newcounter{kartonnr} \newpage \begin{longtable}{|p{1.5 cm}|p{.8 ...
2
votes
3answers
100 views

Evaluate binomial coefficient with \pgfmathtruncatemacro

How is it possible to evaluate complex formulas like \binom{2^{4}-3}{2^3} with \pgfmathtruncatemacro ? I want this to evaluate to 1287. What already works: \begin{tikzpicture} \foreach \l ...
3
votes
1answer
53 views

LaTeX3 loop expanding to repeated {}s

I’m using the ExPex package for vertically aligned linguistics glosses. For various reasons I have some stuff that looks like this: \ex \begingl \gla \rlap{thisisaverylongword} @ {} @ {} @ {} @ ...
2
votes
3answers
47 views

Create and use macro names dynamically within a loop for redefining lowercase greek letters

This is follow-up question to this one. My aim is to let greek letters behave the same like normal latin letters, when it comes to get them upright. At the moment I'm using \mathrm to get letters ...
1
vote
0answers
29 views

Count lines of multiple files (Using minted for formatting.)

I am using minted to show source code in my document like this: \section{Image functions} \inputminted{python}{src/imagefuncs.py} \section{Matrix operations} \inputminted{python}{src/matrices.py} ...
2
votes
0answers
62 views

\foreach in pgfplots [duplicate]

My final goal is to create a groupplot with 10*10 figures. I here have reduced the problem so that it will be easier to explain. First, I have created some dummy data which I store in test.txt and it ...
2
votes
1answer
93 views

Using line thickness as a loop variable in TikZ

Here is a very simple code that mysteriously does not work; a simple pgf loop where the first variable is the y-coordinate and the second variable is the line thickness. LaTeX rejects the thickness ...
6
votes
2answers
170 views

Calling several tex files with a loop?

I have 160 tex files named "regj.tex" for j=1,...,160. Each file contains a table. These tex files do not contain the preamble/begin{document}/end{document}. For example reg1.tex is ...
25
votes
4answers
460 views

Expandable (quick) sort array macro?

I'm trying to implement a (quick) sort algorithm. Here is what I can do : \documentclass[preview, border=7mm]{standalone} \usepackage{pgffor} % \push{xs}{\i} add \i in the array \xs ...
4
votes
4answers
277 views

Create math-exams with lists of student names

I am a math teacher form Germany. I want to create tests for my students. As is customary I will design two test groups: Test A Test B I will also have a list of names: Joe Peter Julie ... I ...
3
votes
2answers
120 views

How can I remove hardcoded numbers from this TikZ algorithm for drawing a circle of circles?

I have some TikZ code for drawing a circle of little circle images (for showing pictures of a team of people). The number of people shown can vary, so I'm trying to remove hardcoded numbers to make it ...
6
votes
1answer
101 views

\foreach dimension too big

I want to create an animation of satellites. I am using the code below. However I'd like it to run smoothly so I want to produce many frames. It turns out the maximum number of frames I can create via ...
1
vote
0answers
20 views

Looping through elements in a sequence [duplicate]

In a follow up of Highlighting words only the first time they appear it was suggested to use \seq_use:Nn to display the content of a sequence. It works really nice but it concatenates the items with a ...
2
votes
4answers
125 views

TikZ's \foreach \x/\y in… the set of running indices being a macro

Please look at this minimal example which contains my question: \documentclass[english]{article} \usepackage{tikz,ifthen,listings} \newcommand\IndexListOne{1,2,3} ...
1
vote
1answer
66 views

Permuting an index list; and creating an index list of 0's and 1's

I want to run the steps of a loop in random order and also save the order in which the iterations were carried out: \documentclass[english]{article} \usepackage{tikz} ...
3
votes
1answer
56 views

Automate importing pages from PDF file and add text to some of these

I'm trying to use LaTeX for lecture notes, but am having trouble implementing it the way I want to. For each lecture I will have access to a PDF file with presentation slides, where one slide ...
8
votes
4answers
262 views

drawing music staves with \rule loop

I want to draw blank music staves using nothing but \rule in a loop. (I know there is MusiXTeX and Lilypond, not to mention Tikz, but really, I just want some horizontal lines.) In this example, the ...
2
votes
1answer
110 views

Print iteration counter in for loop

I am new using for loops in latex, and not sure if the following is possible. This is basically what I am trying to achieve: \documentclass{article} \begin{document} \foreach \x in {a,b,c} { ...
7
votes
1answer
120 views

How can I get different colors in each element of double loop

This is my code \documentclass[tikz]{standalone} \usetikzlibrary{calc} \usetikzlibrary{intersections} \usetikzlibrary{arrows} ...
6
votes
5answers
514 views

How can I draw several polygons on the same base line using TikZ?

I want to construct a figure that will be symmetrical polygons on the same base. So, there is an equilateral triangle, a square, a pentagon, a hexagon, etc. one side of all these is the same ...
4
votes
1answer
50 views

Beamer successive overlay actions in reverse order

I try to make this macro work in reverse order, I mean the display is made from the left in a stared version instead from the right, ex : ...=8 , ...=2*2*2=8 , 2^2=2*2*2=8 I can't imagine how to do ...
0
votes
1answer
27 views

Automatically rotate through image files?

Note: this is NOT about rotating the image itself. In my book I have a bunch of decorative vignettes like this: , , and so on.... And I created a command for it: ...
6
votes
1answer
143 views

Why does \loop behave differently depending on order of its contents?

Just a question out of curiosity. I tested the code below, and first two {\loop...\repeat} commands returned \TeX!\quad six times, and others returned it five times. Why do only first two ...
2
votes
1answer
52 views

How to output text value of counter in for loop

Consider following code: \documentclass[12pt]{article} \usepackage{amsmath} \usepackage{forloop} \begin{document} \newcounter{i} \forloop{i}{0}{\value{i} < 3} { % trying to get the text of ...
6
votes
2answers
226 views

Generate the n-th letter of the alphabet in a tikz loop [duplicate]

The following code draws 10 nodes, labelled from 0 to 9. \documentclass[a4paper,10pt,landscape]{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \i in {0,...,9}{ ...
2
votes
2answers
166 views

Accessing value in forloop

This code is not compiling and creates an error "Missing number, treated as zero". \newcounter{x} \forloop{x}{0}{\value{x} < 5}{ value is \value{x} \\ } How can the value of x be printed ...
4
votes
3answers
75 views

\forlistloop of etoolbox reference requested

I am having a problem of using the command of \forlistloop of etoolbox unlike the way of typical C program where int a[5] for ( i = 0; i <5; i++) { a[i] } one could access i I am not sure ...
5
votes
1answer
82 views

Tikz Intersecion doesn't recognize path named with name path

I have problems with using path names defined even in the same loop. the following code produces error message: ! Package tikz Error: I do not know the path named `ab6'. Perhaps you misspelt it. ...
2
votes
0answers
109 views

Iterating through a character/string array in LaTeX

I have an array of strings, and am trying to output each element into LaTeX. I am able to achieve that using the following code: \documentclass[12pt,english,nohyper]{tufte-handout} ...
3
votes
1answer
30 views

Bad linebreak with tabulars in loop

I have built arrays (with csnames) containing contact information, and I would like to print out all the contacts in tabular format, using a loop. But when the tabulars overflow the \textwidth, ...
7
votes
2answers
351 views

How to repeat over all characters in a string?

I have a command that formats a single character, let's call it \d{}. (In my case, \d{} adds a dot under a Chinese character, as this is the custom to emphasize Chinese texts). I want to define a ...
3
votes
3answers
132 views

question in using \foreach to iterate over lists

I am learning \foreach to see if it will work for what I want to do. I can't figure why the following does not generate the expected output. MWE \documentclass[12pt,titlepage]{article} ...
1
vote
1answer
35 views

\ForEachX and string concatenation

I'm writing a class where I have an arbitrary number of strings that I'd like to concatenate, then loop over and typeset using \ForEachX from the forarray package. If I define a command to add to a ...
1
vote
2answers
44 views

Tables and equations in a 2 column paper

I am trying to write a paper with 2 columns and I need to insert tables and formulas in it, however, they are not fitting. Is there a way how to make these shrink to fit the page size? MWE: WIC is ...
2
votes
1answer
34 views

pgffor `foreach` loop over databib macro-generated list

The databib package from the datatool bundle allows one to import BibTeX databases and work with them from within LaTeX. The author field can be accessed as \DTLbibfield{Author}, which returns data ...
3
votes
2answers
177 views

Loop to create new counters

I want to create counters in a loop like this (with the packages multido, totcount) : \newcounter{compteurChi}% first counter \regtotcounter{compteurChi}% define the first counter as a ...
3
votes
2answers
103 views

How do I create different math problems and their answers?

(How to extract elements from a loop in an array?) I'm trying to create "n" versions of a homework and their answers in the last page changing or increasing each variable every loop. So far I can ...
2
votes
1answer
78 views

Problem using macro with TikZ foreach

I am using a simple macro adapted from an answer to the following SO question: http://stackoverflow.com/questions/3951392/latex-space-after-every-letter The modified macro simply takes a string and ...
11
votes
3answers
277 views

3n arguments in a macro (n is an even number) for curves whose thicknesses increase or decrease

For some mathematical figures it's nice to be able to vary curve thickness smoothly along a path, to reproduce hand drawn mathematical figures made with inking liners for instance. One way to do it ...
0
votes
0answers
61 views

Take input from csv file and use it to create a custom-made table in tikz

I have a csv file that looks like this: Scott, William, Todd,Esben, Martin, Jesper, Alexander W.L Right now, the names are written this line \aebuildtable{20}{Scott,William,Todd,Esben, Martin, ...