Questions tagged [loops]

{loops} is about looping constructs which allow a programmer to apply the same operation multiple times, each time with possibly different parameters.

Filter by
Sorted by
Tagged with
4 votes
2 answers
78 views

Expansion of foreach loop inside \draw

I have a hard time understanding the response to the GitHub issue pgf-tikz/pgf#356. The original question asker has posted the following MWE. I've wrapped it with \begin{document} for completeness. \...
0 votes
1 answer
64 views

Unexpected behavior when drawing a regular polygon

I'm practicing using pin and marks on \coordinate and \node. Goal/Expected output A regular polygon parametrized by the number of sides n with each vertex marked by a circular dot and a label outside ...
1 vote
3 answers
61 views

Using & inside a for loop to automate matrix creation

I want to make a command that fills a matrix with zeros. Here's how I thought it could work: \documentclass{article} \usepackage{pgfplots} \usepackage{amsmath} % Math \pgfplotsset{compat=1.18} \...
user avatar
1 vote
1 answer
24 views

Supplying an Undefined Command as an Argument

I am trying to make an environment where you supply a variable name via an argument: \documentclass{article} \usepackage{pgfplots} % Foreach loops inside align \pgfplotsset{compat=1.18} \...
user avatar
0 votes
3 answers
65 views

Lua function returning a list of values to TikZ foreach loop

I was trying to come up with a Lua-based solution to another question here and failed miserably. There something I certainly don't understand about LuaLaTeX. Here is a toy code that shows the problem. ...
user avatar
  • 1,467
0 votes
0 answers
35 views

How to input multi parts of a file

I have a .tex document(external.tex, for example) whose content is like this: ... ... %*#<start> some code %*#<end> ... ... %*#<start> some other code %*#<end> ... ... I want ...
user avatar
  • 2,355
1 vote
3 answers
67 views

Input multi files at one time by \foreach

I have several files in the sub-folder ./tmp -- "a.tex" whose content is \def\aaa{aaa}, "b.tex" whose content is `\def\bbb{bbb}. Then I input them to my main doc at one time by \...
user avatar
  • 2,355
3 votes
2 answers
107 views

Change anchor location throughout TikZ foreach loop?

I have some TikZ code to generate a unit circle with N evenly spaced vectors going from the center to the circumference of the circle. \begin{tikzpicture} \newcommand\wpic{4} \newcommand\wcir{3} \...
user avatar
  • 33
5 votes
1 answer
251 views

Clockwise and counterclockwise path around the origin

I want to draw the following At first I thought of doing something like a dipole but then I realized that it was not like that, it is just a curve that returns it to the origin of coordinates in a ...
user avatar
  • 351
0 votes
0 answers
30 views

How to leave a space between two longtables and horizontal lines in both tables?

I was wondering how to add space between two tables generated by the code below. Also, \hline doesn't work when I use it in both loops but works if I use it only in one. f.write('\\rowcolor{colour10} ...
user avatar
  • 33
0 votes
1 answer
39 views

For loop with keys of property list

I am using a properties list and I would like to be able to create a command that produces the list of keys to be used to generate a for loop. I am currently using \prop_map_inline to generate all the ...
user avatar
1 vote
1 answer
37 views

Automatic line breaking of boxes

I want to automate some things in LaTeX using loops and saveboxes, but the boxes don't want to go automatically to the next line when there is no space for them (saveboxes are necessary). The code ...
user avatar
2 votes
2 answers
76 views

Loop through Entire Bib Database

I would like to loop through all entries in the BibLaTeX database and generate a \csxdef based on the each key. The pseudo code for what I desire is: \foreach \EntryKey in \ListOfAllBibliography {% ...
user avatar
0 votes
1 answer
119 views

Part 2: Custom Tags and Questions in Exam Class

This is an expansion of the problem I posted, which @John Kormylo has provided a solution for. https://tex.stackexchange.com/questions/640726/create-custom-tags-for-questions-in-exam-class Here is ...
user avatar
2 votes
3 answers
112 views

How to use for loop to input files

Suppose I am writing a book with 45 chapters (in separate files 1.tex 2.tex etc) and I want to input them into main.tex. How can I write a for loop for this?
user avatar
  • 359
0 votes
1 answer
43 views

I keep getting a bar and 0 at the end of the nested forall loop I write within a Pseudocode [closed]

\documentclass{article} \usepackage{algorithm} \usepackage{algorithmic} \begin{document} \begin{minipage}{0.46\textwidth} \begin{algorithm}[H] \caption{foo} \begin{algorithmic}[1] \STATE let $S$ ...
user avatar
  • 1
0 votes
0 answers
45 views

Looping through values from other database using the ID (primary key) with datatool (using expl3?)

I have set up a database structure for projects and people. The aim is to have the IDs of the people as a value stored in a column of the project database. Now I would like to refer to the people, ...
user avatar
4 votes
4 answers
338 views

Get value from \foreach

I build a macro named \fromlist to get value from a list. The value can be typeset, but can not be invoked directly, why and how to deal with it? Code: \documentclass[a4paper]{article} \usepackage{...
user avatar
  • 2,355
12 votes
5 answers
955 views

How can I create a comma-separated list of characters from a text string?

How can I split the string Hello World! - stored into a macro \def\mystring{Hello Word!} - into a comma-separated list of characters (including spaces) which can be used as argument of a \foreach loop ...
user avatar
3 votes
4 answers
250 views

How to iterate through macro parameters in a for loop? or how to expand a macro parameter with a counter?

I'm trying to expand a macro argument with a counter inside a for loop with the next code: \documentclass{article} \usepackage{xparse} \usepackage{forloop} \NewDocumentCommand\test{m O{II} O{III} O{...
user avatar
4 votes
1 answer
65 views

Loop variable in node anchor specification

Given a loop variable \x, I would like to use it as (foo.\x west), for example, where \x could be north. My attempt: \documentclass[tikz,border=1mm]{standalone} \begin{document} \begin{tikzpicture} ...
user avatar
  • 595
2 votes
1 answer
57 views

How to draw tikz figures side by side, while using a loop?

Right now I have some code like this: \begin{minipage}{1cm} \begin{tikzpicture} \draw plot[domain=0:2,rotate=-90] (\x, { (sin(pi*\x r)* sin(pi*\x r) + sin(pi/2*\x r)*sin(pi/2*\x r) + 2*...
user avatar
  • 365
0 votes
2 answers
56 views

LaTex macro with \begin and \end parts split in different loops

Consider the minimal working example below that progressively superimposes (using the overpic package) images contained in a pdf file. \documentclass{beamer} \usepackage{overpic} \begin{document} \...
user avatar
0 votes
0 answers
17 views

Algorithm in LaTeX doesn't show for or while loops [duplicate]

I have a LaTeX document for a report, it's a bit extense and I have to include a relatively large algorithm. I had issued with it because instead of displaying through the pages I wanted it went to ...
user avatar
3 votes
2 answers
148 views

Generate Table via a Loop over a List

I would like to create a table that shows the evaluations of a formula for some given input list. My initial idea was to evaluate the formula using the fp package within a \@for loop. This however ...
user avatar
  • 133
2 votes
1 answer
93 views

Use a variable in foreach

I am trying to use a variable in my foreach loop. It would make things a lot easier, because i only need to change one value and multiple loops are affected. Something like this: \begin{tikzpicture}[y=...
user avatar
2 votes
1 answer
152 views

How to detect EOF for two source files in loop condition?

For a critical edition in two languages, my Main.tex file has a loop that: reads a line from first source file reads a line from second source file outputs the lines with the \chunks command uses \...
user avatar
0 votes
0 answers
33 views

Running pdftex in a »for loop« over many *.tex files, using a format, and hitting file names with umlaut and / or spaces

This is a follow up to this question: mylatex.ltx and a file name with an umlaut and / or spaces I'm producing 50 *.tex files by using a template engine (jinja2), a python script, a *.csv file with ...
user avatar
  • 28.8k
3 votes
1 answer
51 views

Repeating code between two commands on a new page

I have a quite complex code where I need to repeat a few lines (consisting of commands, for simplification here in MWE only a few words). In the MWE for printing the same as above in italic. The ...
user avatar
  • 942
6 votes
2 answers
519 views

Why doesn't this \foreach work?

I don't understand why this doesn't work. I changed x to y and z but it didn't work. Any ideas? \documentclass[11pt]{article} \usepackage{pgfplots,pgfplotstable} \pgfplotsset{compat=newest} \begin{...
user avatar
  • 213
2 votes
1 answer
142 views

Run a forloop for a variable times

Consider this MWE: \documentclass[varwidth=3in, multi={my}, crop, ignorerest=true]{standalone} \usepackage{polyglossia, lipsum, forloop} \usepackage[most, magazine]{tcolorbox} \usetikzlibrary{patterns,...
user avatar
  • 2,355
1 vote
1 answer
64 views

Manipulating csv lists and nested csv lists with expkv using custom class file

This is a followup question to Class with keyval option consisting of lists of keyval pairs. In an answer to that question, Skillmon showed how to write a class that would provide a command, \people, ...
user avatar
  • 12.1k
1 vote
1 answer
41 views

Class with keyval option consisting of lists of keyval pairs

I'm trying to figure out how to write a class that would allow for a key-value option where the key is called people, which would take a list of grouped key-value pairs (e.g., name, title, and role) ...
user avatar
  • 12.1k
2 votes
3 answers
37 views

Parboxes generated in a for loop go off the end of my document page

I am a TeX novice. I am looking to typeset an arbitrary number of small (18 mm x 7 mm) labels which are produced iteratively based on alphanumeric strings stored in a CSV file. Each label should ...
user avatar
0 votes
1 answer
64 views

Why does LaTeX use the wrong header?

Based on my question "Check if number is in list" I have another problem: I used the answer from Steven to get two lists: highlightedProjects and normalProjects. The projects are tex-Files ...
user avatar
12 votes
2 answers
265 views

Variable number of arguments: generate alignment characters

I'm trying to define a command \letin that should produce something that looks as follows. Note that it should support a variable number of "let" arguments and a single "in" ...
user avatar
  • 328
0 votes
1 answer
61 views

Can I collect all the code in one code?

I want to write a single code for many polygons using foreach. How can I plot each one with the same code by using n variables and writing n values? I am repeating a few steps in the same way as below....
user avatar
  • 33
2 votes
1 answer
82 views

Latex3 and \foreach: Do common operation over list of clist variables

I am trying to learn LaTeX3. In writing one of my projects I faced a situation in which is usefull working with short comma-separated lists, testing whether they are empty, have only one item, etc ... ...
user avatar
4 votes
3 answers
240 views

Simplify code for repeating same image

I want to print an image in the layout, My current code: \documentclass{article} \usepackage{graphicx} \usepackage{blindtext} \usepackage{showframe} \begin{document} \begin{center} \includegraphics[...
user avatar
  • 1,921
1 vote
2 answers
130 views

How to make a table from text file?

I have a text file, where every line is a question. I want to take this file and make a questionnaire with it, so I need a loop that takes each line and makes a table line with it, along with a True/...
user avatar
1 vote
0 answers
44 views

How to automatically construct an mxn matrix with same coefficients and different pedices?

Let's suppose I have an mxn matrix like the following \documentclass{article} \usepackage{amsmath} \newcommand*{\vth}{\vartheta} \newcommand*{\vph}{\varphi} \newcommand*{\pt}[1]{\left(#1\right)} \...
user avatar
  • 197
3 votes
2 answers
112 views

I can't take my shape one step further. how can I draw more

I can't keep repeating the shape in the corners. I can't issue a command like corner of the corner. I want it to continue in a loop like fractal but I couldn't make the loop. With the command I wrote, ...
user avatar
  • 33
1 vote
0 answers
31 views

Avoiding vertical shift when using \foreach to display a series of images

I'm trying to show a sequence of almost identical images in a beamer frame, to be able to step back and forth and compare the differences. The images are numbered as image1.pdf, image2.pdf etc., and ...
user avatar
  • 167
2 votes
1 answer
52 views

How can I write a macro to convert a list into a table?

I think this is an easy for-loop question, but I can't seem to get it to work... I frequently need to put a CC list at the end of the documents that I prepare. I have been making the list manually, ...
user avatar
  • 123
0 votes
1 answer
58 views

DTLforeach* - "unrecognized key in key option"

I'm quite new to the LaTeX universe, so ..., in fact, I'm not sure, if the DTLtool is best suited for my purposes. I'd like to use data from a .csv in a table environment used for all tables in the ...
user avatar
4 votes
3 answers
160 views

Connect points in array with \foreach

How can I get the next element in array that's being looped with \foreach? Here is an example what I'd like to achieve, but it obviously doesn't work \documentclass{article} \usepackage{tikz} \begin{...
user avatar
  • 2,345
0 votes
0 answers
36 views

Custom TABLE of abbreviations

I'm using the acronyms package, to manage the acronyms in my report. I have a separate file in which all the acronyms are defined using: \begin{acronym} \acro{DC}{Direct Current} \end{acronym} I don'...
user avatar
1 vote
1 answer
63 views

What is wrong with this version of foldr?

To gain a better understanding of macros, expansion and tex-core in general, I tried to implement foldr like this: \long\def\cons#1#2{% \def\tmp{#2}% \ifx\tmp\nil% [#1,[]]% \else \consI{#...
user avatar
2 votes
1 answer
38 views

Can't get foreach to work with ifinlistcs

Could anyone kindly explain why the \ifinlistcs is always false when I try to use \foreach to provide each test element? Of course, I can use \dolistcsloop as it is the recommended way to process the ...
user avatar
  • 23
1 vote
0 answers
43 views

How can I get R and Tikz to cooperate in a loop?

I'm using knitr and compiling my .Rnw file in Rstudio. Here's a MWE illustrating my issue. I want the code below to output "1, 2, 3" but instead it gives me "1, 1, 1". %%%%%%%%%%%%%...
user avatar
  • 11

1
2 3 4 5
15