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.
796
questions
0
votes
2
answers
45
views
Check if a predicate is satisfied on all tokens in LateX3 using conditionals
I am trying to write an expandable conditional that test if a condition is satisfied and it does not seem to work as expected.
Currently here is my approach (with \token_if_letter_p as an example of a ...
0
votes
0
answers
11
views
Accede to particular data inside variable
Suppose I have multiple products, each with a name, number, description, and photos (which could be one or multiple photos).
I want to automatically list the names of the products on the cover page ...
0
votes
0
answers
47
views
How to manipulate lists in LaTeX? I want to get a value from a list based on its numerical index
I want to use the expl3 package to manipulate lists in LaTeX. My goal is to create an empty list called \mylist, fill it with values, and then retrieve a specific value based on a given numerical ...
2
votes
1
answer
39
views
How can i make the intersections library remember the "total" macro outside the specific path? [duplicate]
When defining the intersection coordinates of two paths (via the intersections library), I can store the number of found intersections in a macro for later use, i.e. foreach:
\draw[name path=A] (0,0) -...
5
votes
3
answers
482
views
Counter in Loop
I'm trying to set the color of every three items in a 5x3 pattern from a tikz picture:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \m in {1,2,3}{
\...
7
votes
6
answers
832
views
Draw Small Regular Polygons
I'd like to use tikz to draw regular polygons that are too small for shapes.geometric. My goal is to have them in-line with the text:
But when I try to write a tikzset to so I can quickly and easily ...
3
votes
2
answers
131
views
Help with loops – why is there an Ω?
I am just getting some experience with looping constructs in TeX/LaTeX. I thought I understood how \@tfor works, and things were mostly coming out as I wanted. But I ran into some unexpected ...
0
votes
1
answer
96
views
Two for loops and the second starts with i+1
I need some help with generating an image. (Disclaimer: Most of it is ChatGPT generated). It is compiling so the warning isn't too serious, but it still bothers me and I can't think of a solution to ...
0
votes
1
answer
75
views
How can I input external files by using a list of names?
My code is the following:
\documentclass[ngerman,german,14pt,twoside,openany]{scrbook}
\usepackage[left=2.5cm,right=2.5cm,top=2cm,bottom=2.5cm]{geometry}
\usepackage[ngerman]{babel}
\usepackage[utf8]{...
5
votes
2
answers
311
views
Use for loops to generate TikZ coordinates corresponding to linear combinations of vectors
I am trying to draw linear combinations of vectors. I started defining coordinates manually, but it's too time- and space-consuming:
\begin{center}
\pgfplotsset{compat=1.15}
{
...
2
votes
2
answers
87
views
Automating drawing horizontal lines until the end of the page
I have a page filled with text (arbitrary vertical height) and would like to fill the rest of the page with horizontal lines. So far my solution is to manually adjust how many lines are drawn:
\...
2
votes
2
answers
84
views
Polynomial long division with macro command in a for loop (to get different coefficients)
I would like to create problem sheets with polynomial long division, where each student gets different polynomials. I tried to use the polynom package, but the following code does not compile (it does ...
0
votes
1
answer
70
views
how to put uppercase text into a variable [closed]
with this code
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\begin{document}
\newcommand{\TeIII}{ tit e3 }
\newcommand{\AeIII}{\UseName{author24} }
\...
1
vote
1
answer
140
views
Creating LaTeX Macros to Generate Tables from Predefined Variables
I've been struggling for the past two days to create macros for populating a thesis title page, as I'm planning to share it as a template with my colleagues. As you all know, thesis title pages have ...
2
votes
3
answers
277
views
Defining a custom if command
In the following minimal example, I am able to define a custom \if* command based on ifcsname, however when I use it inside \loop construct I get Extra \fi errors
\documentclass{article}
\...
0
votes
0
answers
39
views
Creating a yearly training log with calendar.sty and loops
I'm quite new to LaTeX and just playing around learning new things.
So i want to create a PDF that i can print as a book to log my training and still be able to write some things with a pen. It should ...
2
votes
4
answers
127
views
Loop to input content into tabular
I'm trying to input files that represent rows of a table into a tabular environment using a loop, but I'm having trouble using input.
Here is a MWE of my code without using loops. I have files with ...
2
votes
1
answer
36
views
Iterating over a list and conditionals in tabular environment not working. Incomplete \ifnum; all text was ignored after line 72
i work on a project with a lot of people and there are many who are not really familiar with LaTeX. Therefore, I have to define a command (\timeplan{}), which simplifies coloring tablecells (each ...
5
votes
6
answers
387
views
Partition string in substrings of equal length and iterate through them
To avoid the XY problem, I'll describe what I am looking for (the X) and the issue that I found while attempting X (the Y). To be clear: I'm not trying to troubleshoot Y, I'd be grateful if only X is ...
3
votes
3
answers
176
views
Define a new command as a loop of existing Latex commands
I want to define a new command, which is a composition of commands already defined within the \csvsimple package. Therefore I've written the following code, which correctly works for my purpose:
\...
1
vote
2
answers
71
views
Table csvreader: loop over columns
I have a csv file called "data.csv" containing the following data:
1,2,3
4,5,6
I am writing the following table in Latex by using \csvreader:
\begin{table}
\centering
\begin{tabular}{|c|c|c|}...
1
vote
1
answer
46
views
Doubt about \pgfplotsinvokeforeach
I was using tikz and I had a problem using \draw[] inside a \foreach loop, so I found \pgfplotsinvokeforeach and I have doubts about how it works. This is an example
\documentclass{article}
\...
0
votes
3
answers
87
views
Creating newcommands using a loop
I am currently writing a reader and have to write a lot of sub & superscripts so I have written a function
% Define the electric field vector
\NewDocumentCommand{\vE}{O{#1} O{#2}}{
...
4
votes
2
answers
222
views
Repeat the same TikZ graphic to fill the entire page
What I'm trying to do
I am creating some handwriting drill sheets. In these sheets, the exact same pattern is repeated horizontally and vertically over the entire page. The following 3 images were ...
0
votes
0
answers
25
views
Repeat characters n times to fill the current line [duplicate]
In this answer, someone provides a macro for repeating a string a given number of times. Here's a minimal working example of that macro:
\documentclass{article}
\makeatletter
\newcount\my@repeat@...
2
votes
1
answer
87
views
How to concatenate a variable with string in tikz for loop?
Is it possible to concatenate a TikZ loop variable with a string? For example, consider the following tikzpicture
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\...
1
vote
1
answer
90
views
getting automatically the initials of names
This sounds like some basic stuff, and yet I cannot manage to find a solution, packaged or native.
I have documents with people who have from 2 to 4 names (typical Danish name could be Søren Jens ...
3
votes
2
answers
104
views
passing argument to \includegraphics inside \foreach loop
I am trying to define a loop to create 4 of my slides in a Beamer presentation. Each slide will have a figure. A minimal example is below:
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\...
2
votes
1
answer
58
views
Name \pic object using loop variable
What is the good way to name \pic object when \foreach variable is used? I use the variable in \foreach as part of the node name. If I do not using local bounding box, then there is no shape name ...
1
vote
1
answer
113
views
How to make a loop-generated table depending on the outcome of a calculation?
As a Dutch teacher my grading scale goes from 1,0 to 10,0. The calculation of the grade depends on three variables: the N-term; the score of the student; the total number of points for the exam.
I ...
0
votes
1
answer
39
views
simplest way to access element of list inside loop
I would like to access the elements of a list inside a loop. Here is a minimum example:
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage{pgffor}
\begin{document}
\...
1
vote
0
answers
51
views
How to graph a series defined function like $\sigma_{n=0}^\infty (-1)^nx^n$? [closed]
I want to graph, for example, this function: $\sigma_{n=0}^\infty (-1)^nx^n$.
0
votes
1
answer
56
views
loop in tabular environment
I am trying to create a table depending on the size automatically. There is kind of a proliferation of loop commands in LaTeX, which makes it hard to figure out which one is suitable. I tried plain ...
3
votes
4
answers
952
views
How can I write a LaTex command with 'if'-'then'-'else'?
I read LaTeX \if condition and How to write if and then in algorithm?, but so far it did not ring a bell for me.
I am trying to create a command named dottedSkill like below.
The logic behind it is:
...
2
votes
1
answer
102
views
Draw a circle with arrow on it to indicate loop
As shown in the pic, I already have three nodes and arrows connecting each other. The arrows form a loop and I want to add a circle with arrow on it(perhaps with text in it) inside the triangle area ...
1
vote
0
answers
59
views
Setting and displaying date ranges extracted from filenames in the header
I already asked a related question about this topic some months ago. However, I have a project with this structure:
Project:
|- main.tex
|
|- pages
|- 20230101.tex
|- 20230102.tex
|- ...
4
votes
3
answers
206
views
Expl3 to simplify expansion issues with loop-built Tabularray content
A follow-on from my previous question answered thanks to @egreg. (Perhaps Prof. Gregorio would be able to help me here too.)
Situation
I am creating a Table of Questions (ToQ) macro for creating ...
1
vote
1
answer
56
views
Missing number, treated as zero error when using for loops and conditionals in tikz
I would be nice to be able to have a code that, by modifying certian parameters like height and width and cells to be colored red or green, generates a table for me. The code I have is already a ...
0
votes
2
answers
78
views
Iterate with forloop instead of foreach [closed]
I have this {C/4/a/n,D/4/b/n,E/4/c/n}
This is how I iterate it with foreach:
\foreach \x\y\w\z in {C/4/a/n,D/4/b/n,E/4/c/n} {
\x - \y - \w - \z
}
But I need to do it with forloop.
It is ...
3
votes
3
answers
596
views
Repeat a pattern until the page is filled
General overview
I make Chinese grids for handwriting exercice. The goal is to use the maximum space given in A4 page (with 1cm margin).
MWE
For the moment here is my code:
\documentclass[a4paper]{...
4
votes
3
answers
200
views
Fill in the table automatically with numbers with a certain step
Let me give you an example of how I started to solve this problem (but without success):
\documentclass[a4paper,12pt]{article}
\usepackage{caption}
\usepackage{colortbl}
\usepackage{ifthen}
\begin{...
2
votes
2
answers
82
views
LaTeX does not finish compiling (infinite loop, maybe) when I place multiple \tl_use commands inside the \bool_until_do loop
I am trying to retrieve data from a .aux file using expl3.
I want to ignore the first line because it serves a different purpose (hence the \ior_str_get:NN \l_seccion_lista_ior \l_tmpa_tl). The ...
2
votes
3
answers
260
views
How to set up a sequence of clips in TiKZ with a loop?
Here's the simplest file I can think of which demonstrates my problem: I simply want to draw two circles, half filled:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
...
1
vote
3
answers
113
views
Why doesn's naming coordinate with \foreach iterator work inside axis environment?
Without the axis environment, we can write something like this
\documentclass[beamer,crop]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\foreach \...
0
votes
0
answers
66
views
Unknown function `corner' in for-loops
I would like to draw this graph: each side of the regular pentagon is replaced by five circular dots.
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\...
4
votes
3
answers
114
views
Changing value of an array inside foreach doesn't effect the array outside of foreach
Editor: TexMaker
Tex distribution: Latex
I have a foreach statement, and I'm changing some of array cell's values inside of the foreach block.
But it seems that the changes have not applied on the ...
0
votes
2
answers
58
views
Algpseudocode, for-next loop: control variable in next line
In this pseudo-code excerpt, is it feasible to add a new argument for the variable v with a syntax like \ForAll {$v$}{$v \in V(G)$} to get the output next v?
\documentclass{article}
\usepackage{...
1
vote
3
answers
138
views
Storing a series of tokens for later evaluation
Is it possible to expand the tokens in a string as though they were typed at that point in the source file? I'm trying to do something like this:
\begin{vmatrix}
\@for\tmpone:=a,b,c\do{%
\def\...
0
votes
0
answers
21
views
Problem with Multiple Dotted Lines using Loop Repeats
I am trying to use the "loop repeat" to write multiple dotted lines as follows.
\documentclass{article}
\usepackage{amsmath}
\usepackage{arydshln}
\setlength\dashlinedash{0.3pt}
\setlength\...
2
votes
2
answers
99
views
Conditionals in \foreach loops
I drew a ruler using the MWE below then I realized that It draws each medium (5 mm step) vertical line over the small ones (1 mm step) and each large (numbered) vertical bar over both medium and small ...