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).
110 questions
3
votes
1
answer
73
views
Confusing Recursive Macro definition with LaTeX
I came up with a resursive macro method to achieve my previous plot question:
\documentclass[tikz,border=10pt]{standalone}
\def\totalwidth{8}
\def\totalheight{2}
\def\mysep{0.5}
\newcommand\mynode[3]{%...
5
votes
2
answers
223
views
Optimization of a function that recursively splits a sequence of tokens
I currently have the following code to recursively split and access a sequence according to a list of separators:
%% -------------------------------- PREAMBLE -------------------------------- %%
\...
5
votes
1
answer
219
views
Recursive auto-nesting of math decorations (e.g., \hat \bar x -> \hat{\bar{x}})
I'm writing a style file for my research group's use, and one thing that happens a lot is multiple modifiers acting on a math symbol. An extreme example of this might be, for instance,
\hat{\bar{\...
5
votes
2
answers
236
views
expl3: fully expandable reformatting of comma-delimited text
I am trying to change the delimiter of comma-separated values (e.g., "a,b,c" -> "a-b-c") in a manner that normalizes input by trimming whitespace and removing empty entries (e.g....
0
votes
5
answers
162
views
Add $k$ instances of a certain character [duplicate]
I'm trying to write a latex command that will allow me to concatenate k times a certain string. Both k and the string will be provided as input. However, I'm having trouble starting. I want to make ...
2
votes
2
answers
123
views
Expansion of arguments in commands [closed]
I have madethis command \RepNum{#1}{#2}. This command is created to indicate the number of times the argument #1 is repeated in the list #2, separated by commas.
\def\RepNum#1#2{%
\begingroup
\...
3
votes
2
answers
144
views
Unbounded expansion in Tex
I'm trying to write a macros for processing lists.
Here's a simplified version of what I'm using to do that.
\def\processlist#1{
\ifx#1\relax
\let\next=\relax
\else\ifx#1,
\let\next=\relax
\...
2
votes
3
answers
217
views
Recursive drawing for the Multigrid γ-cycle
I'm trying to reproduce the image here for an arbitrary choice of γ. γ=1 should give a V-cycle, γ=2 should give a W-cycle, and so on...
I've written a recursive code that I would love to keep since it'...
1
vote
1
answer
208
views
Breaking out of recursion in LaTeX macro using Lua?
Thus far I have:
\documentclass{article}
\usepackage[legalpaper, landscape, margin=0.5in]{geometry}
\usepackage{ifthen}
\usepackage{xcolor}
%\usepackage{luacode}
\setlength{\parindent}{0pt}
\...
9
votes
3
answers
307
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 ...
6
votes
6
answers
670
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{...
0
votes
1
answer
429
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}{...
3
votes
1
answer
553
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. ...
6
votes
2
answers
281
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%
}
\...
2
votes
2
answers
479
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 ...