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

10
votes
3answers
526 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
2answers
116 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
89 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
56 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
48 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
61 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
40 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 ...
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 ...
13
votes
3answers
2k views

varioref: \vref or \vpageref at page boundary (may loop)

Sometimes a have situations, where I'm not able to compile a document, because the varioref package result in a loop. Here is a MWE, which result not in an endless loop, but it demonstrate the issue ...
0
votes
0answers
41 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
41 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. ...
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 ...
2
votes
2answers
40 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} ...
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
26 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} ...
1
vote
0answers
20 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{} ...
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 ...
3
votes
1answer
72 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) ...
6
votes
1answer
46 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 ...
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
318 views

How can I create copies of a document with a running number?

I am making a questionnaire, to be filled out with pen and paper. I need 40 copies of it, with around 13 pages each. I expect that some participants might take the questionnaire apart, so I have to be ...
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. ...
5
votes
3answers
164 views

loop in tabular that uses \the\count to access current line number

I would like to generate an automatic table using loop. As suggested here before, it is best to first generate the lines in a toks and then pass them to tabular. However, I have problems with ...
15
votes
4answers
396 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!
6
votes
1answer
446 views

Repeating the same column type

I'm using package numprint to create a table which automatically formats its columns. However, the table has many columns. Right now, my table definition looks like this: \begin{tabular}{l n{2}{3} ...
2
votes
2answers
119 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
88 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 ...
19
votes
4answers
897 views

Foreach loop between two lists

\documentclass{article} \usepackage{tikz} \def\firstlist{0,1,2} \def\secondlist{0,1,2} \newcommand{\testa}{ \foreach \x/\y in {\firstlist/\secondlist} { \draw(0,\x)--(1,\y); } } ...
23
votes
3answers
1k views

Make fireworks with only text

For the holidays, I wanted to follow up to the question about making fireworks with tikz (How can we display fireworks?): How can we make fireworks with only text? I have made a crude attempt below. ...
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
135 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} @ {} @ {} @ {} @ ...
25
votes
4answers
478 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 ...
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 ...
1
vote
1answer
285 views

Loop through table for boxplot prepared

I am trying to produce figure with 2 boxplot prepared plots from an inline data file. I grabbed this code from here to use as a starting point. Given that the wrapper code allows the boxplot data to ...
4
votes
4answers
312 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 ...