Advertisement
AlbeChero

macro recursion

Mar 17th, 2021
1,597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 0.68 KB | None | 0 0
  1. \documentclass{article}
  2.  
  3. \makeatletter
  4. \newcommand\myrepeat[3]{%
  5.     % #1 is the number of repetitions
  6.     % #2 is the code to repeat
  7.     % #3 is the code to put in the middle
  8.     \expandafter\myrepeat@aux\expandafter{\romannumeral\number\number#1 000}{#2}{#3}%
  9. }
  10. \newcommand{\myrepeat@aux}[3]{\myrepeat@auxi{#2}{#3}#1;;}
  11. \def\myrepeat@auxi#1#2#3#4{%
  12.     \ifx#3;%
  13.     \expandafter\@gobble % recursion has ended
  14.     \else
  15.     \expandafter\@firstofone % still one m to swallow
  16.     \fi
  17.     {\myrepeat@auxii{#1}{#2}{#4}}%
  18. }
  19. \def\myrepeat@auxii#1#2#3{%
  20.     #1\ifx#3;\else#2\fi
  21.     \myrepeat@auxi{#1}{#2}#3% restart the recursion
  22. }
  23. \makeatletter
  24.  
  25. \begin{document}
  26.    
  27.     \myrepeat{5}{Non devo}{\\}
  28.  
  29. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement