Share Your Experience: Take the 2024 Developer Survey

# Questions tagged [recursion]

{recursion} is the self-referral operation such that particular steps in a program depend on solutions to instances of the same program (as opposed to iteration).

101 questions
Filter by
Sorted by
Tagged with
108 views

### Newcommand with adaptive number of arguments

What I am looking for is a single newcommand, let's call it \wedges, with a variable number of inputs that yields in a flexible way the following result: I have already written the code for the ...
520 views

### Recursive macros revisited

Consider the following code \documentclass{article} \usepackage{xifthen} \def\question#1 #2 #3?{\ifx#1 #2 #3?\relax\else#1 #2 #3 or\expandafter\question\fi} \newcommand{\test}[1]{\question#1} \begin{...
164 views

### Draw recursion tree

Suppose we want to draw recursion tree of T(n)=T(n/4)+T(n/2)+n^2 using Justtree package that introduced here (justtree.sty). I try as follows: \begin{justtree} { declare count={tree n}{...
• 187
389 views

### How to make a recursive function 'trace'?

I'd like to trace the recursive calls of some arbitrary function. This includes the stack unwinding'' as the activation records are popped off. For reference, here is an example of what I'm after. ...
245 views

### Non-tail recursion and argument expansion order

I'm having a trouble understanding the expansion order of TeX macros: \newcount\x \def\dec#1{% \ifnum#1=0 .% \else #1% \x=#1 \advance\x by-1 \dec{\number\x}% #1% \fi% } \...
• 353
317 views

### How to make a recursive macro

The following simple example is for typeseting (a)(b)(c)(d) by recursion. An error massage ERROR: LaTeX Error: \begin{document} ended by \end{)}. is received when running the code. What's wrong with ...
• 2,727
175 views

### Understanding implicit error on a recursive function

I was originally following the idea from Garrick Peschke To import all .tex files inside a folder, but I want my Lua function to also search inside subfolders. Unfortunately I can't make the Lua ...
• 45
59 views

### latex macro fails to parse expression although bracket groups match

The tensor package allows the typesetting of tensors using commands like, $\tensor{X}{^b^o_a_t}$ to produce the following expression: Together with the physics package it is possible to ...
• 453
19 views

### Recursively search for images in local TDS tree

Latex finds ~/texmf/generic/images/f.ps but not ~/texmf/generic/images/d/f.ps Is there a way to make it recursively search folders in my local texmf tree?
• 23
101 views

### Recursively using \@ifnextchar in itemize environment

I'm having some troubles using the \@ifnextchar macro recursively. My goal is to be able to call \subitem{item1}{item2}...{itemN} inside either an enumerate or itemize environment. This is what I have ...
• 143
136 views

### \bool_set:Nn setting variable to itself gives error

I have a (recursive) function that accepts a bool as an argument and first copies this to some local boolean variable (using grouping so the value is restored after the function call). When making the ...
152 views

### Towards a square filling curve and Lindenmayer system drawing library

I am trying to obtain the first terms of a sequence of curves that converges to a curve in the family of well known plane (or space) filling curves. This is a variation I found in the book "...
• 23
1 vote
88 views

### Printing text in recursion

I am working on writing a recursive command for calculating the Ackermann function. Throughout the calculation, I would like to print out some text. However, I am unable to do so. \documentclass{...
• 364
262 views

### Recursion with counters not resetting counters

I'm trying to use recursion to draw Sierpinski's triangle in TikZ. I have something that's partially working, but not quite. At each step, I draw something. Then, if the counter is positive, I call my ...
• 559
185 views

### Join databases with datatool

I'm trying to get a function that can take a variable amount of csv files as an argument, and then join them into a single database for Latex's datatool. The databases are all in a uniform format (...
1 vote
82 views

I am working on a textbook that has a repeated structure for 40 chapters. I set up the TeX file to use \dorecurse to provide that structure, then it uses \input to enter in the data into each section ...
• 13.2k
334 views

### Recursive function in pgfplots

I'm trying to plot Legendre polynomials, which can be done very easily by calling a recursive function. For instance, in Python this would like like this: def legendre(xi, p): if p==0: ...
• 3,051
366 views

### Ackermann macro

I am very new to this website, and am still in the learning stage of LaTeX/TeX. Recently i stumbled upon the Ackermann Function exercise, and i still can't figure out how to complete it properly. That ...
954 views

### Fibonacci macro

I am trying to make a Fibonacci macro, that works as follows. I was able to do so, and I tried to make everything private by using @ (i know it isn't necessary here, but I am trying to practice...). ...
• 913
3k views

### Ackermann Function

I am trying to write a macro to evaluate the result of the Ackermann function. If anyone doesn't know it, is defined as follows: So I am trying to write a code that is able to compute it but I can't ...
• 913
681 views

### LaTeX \newcommand recursion gets very slow

I am writing a GCD calculator in LaTeX. Here I wrote Euclid's recursive algorithm, which should work with logarithmic time. The code here counts GCD of 377 and 233 (which is 1). The code works fine, ...
• 313
635 views

### Interesting recursive behaviour with \frac error

I have this code below. Obviously it's not actually valid code because there's no second argument to \frac, but nonetheless I'm curious why it produces what it does. $\text{abc\frac{123}}$ ...
• 181
3k views

### Simple recursion in LaTeX

I am trying to get into LaTeX recursion and created a command \tower[2][3][4][2] that returns a power tower, 2^{3^{4^2}}, for any number of arguments. My attempt: \documentclass{beamer} \usepackage{...
• 148
128 views

### The "\newcommand", with 25 parameters, recursively defined through other "\newcommand" does not work

I defined a custom command with 25 parameters with the "newcommand" that I called "commandM". I am working with block matrices. You need to repeat them in the text with one or two modified entries. ...
• 2,941
339 views

### Precision improvement - recursive sequence plot for Newton method

The Newton method for solving x+x^2=0 works only four steps, as the iterates are not computed accurately. The fpu library allows much increased precision, but I don't know how to use. Could somebody ...
• 33
1 vote
207 views

### How to use if control sequence properly

I don't understand why this code doesn't produce what I describe in the output. \documentclass{article} \newcommand{\defaultvalue}{\textit{initialvalue}} %indentation pour les (sous)-questions non-...
• 155
251 views

I'm trying to figure out how one could input markdown files recursively. I'm using the markdown package and it does allow inputting files with /markdownInput. This works for the moment but in my ...
• 41
121 views

### How do you plot a recursive sequence in pgfplots/tikz? [duplicate]

I'm trying to plot a recursive sequence namely x(1)=1, x(n+1)=1/2[x(n)+2/x(n)]. I've tried messing around with the \tikzmath library but so far I'm not really successfull. My main issue is properly ...
• 345
102 views

### Visualising the cumulative hierarchy

I would like to visualise von Neumann's cumulative hierarchy of sets as in the following picture from Wikipedia: How can I define a recursive procedure which gives me V_n for every natural number n? ...
• 21
169 views

### Metapost plotting B-Spline recursive formula gives strange results

I am currently trying to make a general B spline basis plotter with meta post. The definition of a basis function is on wikipedia under properties. The knots of a b spline should have the pattern ...
• 885
2k views

### How to write the sum of function inside LaTeX?

\documentclass[border=10pt,pstricks]{standalone} \usepackage{pst-func,amsmath,amssymb} \usepackage{xfp} \begin{document} \psset{xunit=1,yunit=2,linewidth=1pt} \begin{pspicture}[plotpoints=500](...
196 views

### How to add recursive rows to a table, until they reach the end of the page in ConTeXt?

I have a table in ConTeXt like this: \starttext \chapter{This is a title} \bTABLE \bTABLEhead \bTR \bTD a \eTD \bTD b \eTD \bTD c \eTD \eTR \eTABLEhead \bTABLEbody ...
• 13.2k
360 views

### Macro that takes a variable number of arguments, and creates a table with one row per argument

I am trying to create a macro that takes a variable number of arguments and creates a table where each argument becomes one row; so assuming the command is called dynamictable, calling it like this \...
• 237
322 views

### Draw a recursive staircase function

I am trying to draw the following figures shown below However I am really unsure how to go about it. Sorry for not including a MWE as I usually do. But I do not know where I am going to start.
• 11.4k
148 views

### Infinite recursion with \tl_map_variable:nNn

I'm trying to use one of LaTeX3's mapping commands \tl_map_variable:nNn as follows: \documentclass{article} \usepackage{expl3} \begin{document} \ExplSyntaxOn \tl_new:N \l_foo_tl \tl_set:Nn \l_foo_tl ...
• 13.4k
305 views

### How do I unravel apparent recursion in an edef statement?

The text book that I'm writing requires the ability to dynamically build an alphabetically sorted list. As to not invoke the overhead of high powered, general purpose packages, I have opted instead to ...
• 95
43 views

### Page numbering affected by recursive programming

I asked this question How to do recursive program with latex and got the following excellent answer by @JosephWright \documentclass{article} \usepackage{advdate} % Set the first practice date \...
• 1,348
238 views

### Align elements inside a newcommand

I made this newcommand \boldAcr: \makeatletter % we need to use kernel commands \newcommand{\boldAcr[1]}{\MakeTextUppercase{\textbf{#1}}\@boldAcrOne} \newcommand\@boldAcrOne{\@ifnextchar\stopBold{\@...
• 389
954 views

### How to do recursive program with latex

I am trying to make a schedule for two groups of people who will watch the same experimental lectures at the same laboratory in different dates. I need to skip the holidays. I intend to get something ...
• 1,348
25 views

### Recursive newcommand - Align words [duplicate]

I would like to define a command that does this: \command word1 word2 ... n-word --> Word1 Word2 ... n-Word with first letter bold and capital. I wrote this: \makeatletter % we need to use ...
• 389
308 views

### Function recursion in TikZ

I am trying to plot the following function in Latex with Tikz: My current code looks like this below, which does not include the summation. \begin{tikzpicture} \datavisualization [visualize as ...
170 views

### How to use \@ifnextchar to create a "table of references" macro?

At the bottom of every section in a big policy manual I need to include a table of references to a procedures manual like this: \begin{table}[H] \begin{tabular}{ |c|c| } \hline \multicolumn{2}{|...
• 127
1 vote
83 views

### Recursive QCircuit Diagrams - "Missing number treated as zero"

I want to draw a huge QCircuit diagram recursively. So I want a recursive macro like this: \documentclass{article} \usepackage{qcircuit} \newcommand\recurse[1]{ \ifnum1=#1 \gate{Y} \else \...
• 255
117 views

### Problem with storing recursive calculus

I have the following issue with some recursive calculus. I just write the function \recsum that recursively computes the sum of an unspecified amount of integers. It works when I call the function ...
• 821
495 views

### How to avoid input stack overflow during recursion

Although there is already a ↗question with a similar title, I take the risk of asking again, because the linked topic is a bit bloated in my opinion, the answers/solutions too complicated. So here is ...
• 55.2k
374 views

### Glossaries package with recursive terms (eg TCP/IP)

[TeXstudio on Mac] I'm using the glossaries package, and I'm wondering how best to handle recursion? For example, with the following glossary terms defined (note the tcpip definition invokes the ...
• 307
1 vote
111 views

### How can I automatically surround each new item in a token list with braces as delimiters?

I'd like to know how to create a macro that can append new elements/items to a macro list (token list) BUT also adds { and } around each added item. Example I'd like it to save each new item like this:...
• 13.3k
1 vote
96 views

### Re-defining a variable w.r.t itself a finite number of times

Is there any way to re-define a variable a finite number of times? Here's MWE of what I'm looking for to work: \documentclass[11pt]{article} \newcommand{\A}{..} \newcommand{\B}{../\A{}} % \...
• 263
1 vote