{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
34 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
126 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
21 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
31 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 ...
1
vote
0answers
38 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 ...
11
votes
3answers
568 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
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 ...
2
votes
3answers
105 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
61 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
57 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
3k 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
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
44 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
43 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
67 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
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{...
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
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
145 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{...
1
vote
0answers
29 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
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 ...
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) ...
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 ...
4
votes
4answers
172 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
329 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
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{...
5
votes
3answers
170 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
424 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
43 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!
7
votes
1answer
532 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} n{...
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 ...
19
votes
4answers
940 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); } } \...
25
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
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
169 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} @ {} @ {} @ {} @ ...
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{...