Skip to main content
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).

Filter by
Sorted by
Tagged with
7 votes
3 answers
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 ...
Freestyla's user avatar
6 votes
6 answers
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{...
VaduzStevin's user avatar
0 votes
1 answer
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}{...
tstt's user avatar
  • 187
3 votes
1 answer
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. ...
TheSinisterStone's user avatar
6 votes
2 answers
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% } \...
Jay Lee's user avatar
  • 353
2 votes
2 answers
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 ...
lyl's user avatar
  • 2,727
4 votes
1 answer
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 ...
Paul's user avatar
  • 45
2 votes
1 answer
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 ...
Ted Black's user avatar
  • 453
0 votes
0 answers
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?
jzz11's user avatar
  • 23
4 votes
2 answers
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 ...
richbai90's user avatar
  • 143
6 votes
1 answer
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 ...
Maximilian Keßler's user avatar
2 votes
2 answers
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 "...
Mandar's user avatar
  • 23
1 vote
1 answer
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{...
G. de Man's user avatar
  • 364
5 votes
2 answers
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 ...
Pi Fisher's user avatar
  • 559
2 votes
3 answers
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 (...
Sharky Bamboozle's user avatar
1 vote
1 answer
82 views

Why is my table of contents not appearing with recursive content in ConTeXt?

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 ...
Village's user avatar
  • 13.2k
0 votes
1 answer
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: ...
aaragon's user avatar
  • 3,051
2 votes
2 answers
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 ...
Lea Hubert's user avatar
9 votes
3 answers
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...). ...
needle's user avatar
  • 913
7 votes
8 answers
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 ...
needle's user avatar
  • 913
19 votes
2 answers
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, ...
DKozl's user avatar
  • 313
17 votes
2 answers
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}$} \] ...
Ethan Lawler's user avatar
7 votes
5 answers
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{...
Void4Win's user avatar
  • 148
2 votes
2 answers
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. ...
MathOverview's user avatar
  • 2,941
3 votes
2 answers
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 ...
bluesky's user avatar
  • 33
1 vote
2 answers
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-...
James Well's user avatar
3 votes
1 answer
251 views

Add markdown files recursively

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 ...
smartens's user avatar
0 votes
0 answers
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 ...
t_kln's user avatar
  • 345
2 votes
1 answer
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? ...
rkrapf's user avatar
  • 21
2 votes
1 answer
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 ...
Makogan's user avatar
  • 885
8 votes
4 answers
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](...
user avatar
3 votes
2 answers
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 ...
Village's user avatar
  • 13.2k
2 votes
2 answers
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 \...
trolle3000's user avatar
2 votes
1 answer
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.
N3buchadnezzar's user avatar
4 votes
1 answer
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 ...
siracusa's user avatar
  • 13.4k
5 votes
3 answers
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 ...
OneMug's user avatar
  • 95
2 votes
1 answer
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 \...
Brasil's user avatar
  • 1,348
2 votes
2 answers
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{\@...
ScTALE's user avatar
  • 389
2 votes
1 answer
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 ...
Brasil's user avatar
  • 1,348
0 votes
0 answers
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 ...
ScTALE's user avatar
  • 389
2 votes
0 answers
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 ...
Christian Seiler's user avatar
3 votes
3 answers
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}{|...
KJC's user avatar
  • 127
1 vote
1 answer
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 \...
Sam Jaques's user avatar
2 votes
2 answers
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 ...
Vinzza's user avatar
  • 821
10 votes
3 answers
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 ...
AlexG's user avatar
  • 55.2k
4 votes
1 answer
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 ...
gone's user avatar
  • 307
1 vote
2 answers
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:...
Jonathan Komar's user avatar
1 vote
2 answers
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{}} % \...
Charles's user avatar
  • 263
1 vote
1 answer
941 views

how to draw recursive picture with tikzpicture?

Suppose I need to draw a Kantor set, or a Sierpinski carpet, or a Koch curve, or any such of simple fractal. Tipically you can do that by drawing a picture, then rescalining it and replicating in ...
user126154's user avatar
4 votes
1 answer
85 views

Getting extra line when using recursive macros

I'm trying to use macros to build a table I'm using a lot, but I keep getting an extra line at the end of the table. The macro implementation is based on the answer at: https://tex.stackexchange.com/a/...
Francisco's user avatar