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

3
votes
2answers
113 views

Writing a recursive matrix pattern

Consider the following matrix \begin{equation} \begin{pmatrix} B_{0,0} & B_{0,1} \\ B_{1,0} & B_{1,1} \end{pmatrix} \end{equation} The next matrix in the iteration is going to ...
2
votes
3answers
86 views

Loop, compare to macro value in condition and multiple macros if true

I seem to be stuck and for now am trying my luck through trial and error to find the right way to do this. Here is a general idea: % I DECLARE NEW MACROS WITH NAMES AS DEFFINITION. AND ASIGN LETTERS ...
2
votes
1answer
27 views

Double for loop with nested for loop dependant on outer

I would like to iterate over an array and then use the current value of the iterator as an argument to the next for loop. So far my code looks as follows but I can't get the syntax correct. \foreach ...
4
votes
1answer
55 views

How to call a command in a loop?

there is a code \documentclass{beamer} \usepackage[utf8]{inputenc} \usepackage[english,russian]{babel} \makeatletter \newcommand*{\dothis}[1]{% \stringcases {#1}% {% {a}{so you typed a}% {b}{now ...
2
votes
1answer
45 views

Forloop with tikz-cd

I am trying to write a macro that (for now) takes as input a number n, and outputs a tikz-cd diagram consisting of n consecutive arrows. However the following code leads to an error: You can't ...
3
votes
2answers
104 views

Why does a loop fail to repeat when filling longtable contents?

The following works: \documentclass{article} \usepackage{longtable} \begin{document} \newcount\n \n=0 \begin{longtable}{ccc} \loop \ifnum\n<10 \advance\n by1 hello \repeat ...
2
votes
2answers
60 views

How to indent for loop

I would like to write the following pseudo code : data_points.foreach { point => for(i <- point.size()) { do something.... } } But when I try to use \For \EndFor I loose ...
2
votes
3answers
38 views

includegraphics with leading zero in for loop

I would like to include graphics which have a filename with leading zeros. The filenames are: pic_001_test.png pic_002_test.png . . . pic_028_test.png I'm able to output leading zeros in a ...
8
votes
3answers
492 views

Repeat characters n times

I wanted to create a new command, which allows me to repeat any characters I want for n times. After some searching and trying, I came up with this: \usepackage{multido} \newcommand{\myrepeat}[2]{% ...
3
votes
1answer
37 views

Tex csname index off by one inside loop

I'm trying to write a write a simple implementation of a list of notation (more as a technical exercise than for actual use). I've run into a rather strange issue with numberings. The following is my ...
0
votes
0answers
40 views

Variable font size of a text string

I was wondering if it is possible to use \fontsize{<size>}{<line space>} in a loop in order to create a text string of strictly decreasing/increasing font size from, say, 30 to 2. Surely ...
3
votes
1answer
54 views

Import several parts of file at once

As a follow up to this Question Situation I would like to create an excerpt from a script that I have TeX'ed as a compendium of the most important statements (theorems & definitions). I seek ...
4
votes
3answers
69 views

How to use loop with arc in tikz appropriately?

This is my code, as you can see it is pretty simple. But I know it can be written way more easily with the appropriate use of \for. Unfortunately, I am still learning and can't seem to make it work ...
3
votes
1answer
40 views

TeX \@for loop within a section title

I am creating a macro for turning a list of files into a comma-separated list of monospaced file names, and using it as a heading. I have written a short script for doing so: MWE: ...
3
votes
2answers
49 views

write tokens to external files / loop unless ifeof does not work for me

I'm trying to write lines including tokens to an external file and read them again in a different document. I face two prolblems: (1) Is there a way around the ugly \unexpanded{} when calling my ...
2
votes
1answer
32 views

Tabbing environment with automatic tab stops

I'm attempting to define a custom tabbing environment which allows me to align subsequent lines of text with elements in a previously generated block which cannot be inside the tabbing environment. ...
2
votes
2answers
38 views

Document with a given number of pages

I would like to create a calligraphy practice book filled with dotted lines but with a given number of pages i.e. 16 or 32 or 64. Any suggestions? \documentclass[a4paper]{article} ...
4
votes
1answer
54 views

Create Tabular from comma separated parameter list

I tried to find an answer to this but currently I have no idea how to get it to work. I want to create a new command which fills some lines of a tabular based on a given list with variable length ...
1
vote
0answers
25 views

How we use while loop in latex to input multiple files in main document

I am trying to input multiple files from different directories in my main LaTeX document and I want to use while loop to do that so that all .tex files can be read from a directory. Please give your ...
4
votes
3answers
135 views

Tikz: deal with exceptions within loops

I am a fan of \foreach loops in tikz, but often find myself in a situation where I want to make an exception for a single iteration of the loop. For example, \documentclass{article} ...
8
votes
2answers
231 views

Foreach loop inside the Tikz picture - Creation of memory cards using Tikz

This question regards creating a memory game using Tikz.I would like to ask for help with creating a loop that will place memory cards on the page. There are many standards, I believe, but let us ...
1
vote
0answers
19 views

Loops within tikz calendar library

(this post is related to this one) Consider the following MWE: \documentclass{report} \usepackage{tikz} \usetikzlibrary{calendar} \newcommand*{\holidays}[1]{% \def\@holidays{#1}% } \holidays{} ...
6
votes
1answer
45 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
71 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
167 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
43 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
169 views

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
394 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
118 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
87 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
51 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
133 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
55 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
53 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
45 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
63 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
100 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
176 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
476 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
311 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
123 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
108 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
135 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
69 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
63 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
275 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
124 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} { ...