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

0
votes
0answers
32 views

LaTeX code as a Python Subroutine

This is my problem. I have a rather sophisticated LaTeX code, namely master.tex It reads a .csv file as an imput It reads .pdf drawings as an imput It calls other subordinate .tex files It contains ...
5
votes
2answers
124 views

Tikz fill color

At the moment I'm using this command in the preamble to fill the color of the specified row with grey: row 2/.style={ nodes={fill=gray!10} } Unfortunately I have to write this ...
2
votes
2answers
57 views

Pass a list to a keycommand or keyenvironment

I want to define command or environment using the keycommand package and pass a list to one key. In my case this would be a list of images. To be more explicit: How can I make the following ...
1
vote
0answers
20 views

How to create looped output with knitr?

In my thesis, I have found 79 different concepts I need to describe in detail in the appendix. I used R for the analysis, and I want to use knitr for creating that appendix. Each description follows ...
4
votes
2answers
108 views

How to make editorial table from sections

How would it be possible to make an editorial list/table? I'm not asking how to create a list or table, but if it is possible to attach something to \section's and \subsection's in the form of a \...
3
votes
1answer
55 views

TikZ > Is it possible to use the identifier of coordinates as string?

I am drawing pictures with TikZ using loops, for instance \foreach \point in {(i),(j),(k)} {...}. Is it possible to use the name of the coordinates as string to label a node? I'd like to use \node at ...
0
votes
2answers
30 views

If condition controlled with a loop variable

I want to print some images according to a variable being changed in a loop: if variable group is 1, then the image should not be printed. But if the value of group is 2, then the image should be ...
3
votes
2answers
123 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 ...
1
vote
0answers
36 views

Produce multiple documents using a loop in LaTex

I want to produce multiple documents in LaTeX. There is a list of values for every document that should be created, in the example it´s \mylist. My first approach was to use the \foreach function to ...
2
votes
3answers
104 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
32 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
60 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
51 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
114 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 \end{...
2
votes
2answers
65 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
56 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 \...
11
votes
3answers
564 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
44 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
56 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
74 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
43 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: \documentclass[...
3
votes
2answers
53 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
42 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
41 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} \usepackage{...
4
votes
1answer
66 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
36 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
144 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} \usepackage{...
8
votes
2answers
239 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
27 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
50 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
73 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
171 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
32 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
46 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. \documentclass{...
4
votes
2answers
172 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
417 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
42 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
121 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
98 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
52 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 cm}|...
2
votes
3answers
166 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
57 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} @ {} @ {} @ {} @ ...
3
votes
3answers
67 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
48 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
102 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
182 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 \begin{table}[...
25
votes
4answers
489 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 \def\push#1#2{...
4
votes
4answers
346 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 ...