Tag Info

New answers tagged

4

ConTeXt solution \def\repeatstring#1#2{\edef\concathere{\dorecurse{#1}{#2}}} \starttext \repeatstring{5}{abc}\concathere \stoptext


7

Repetition via \romannumeral trick The number is multiplied with 1000 to convert it to a roman number. Then TeX produces a long string consisting of letter m, whose length is the original number. Then \repeatstringX looks at the next token, if it is an m, then the string unit is output. Otherwise the next token is the end marker F and the loop stops. ...


8

There are various ways to accomplish your needs. \documentclass[11pt]{article} \usepackage{xparse} % for D % for A, B, C \newcounter{mycount} \makeatletter \newcommand\repeatstringA[2]{% \setcounter{mycount}{#1}% \ifnum\themycount>0 #2% \addtocounter{mycount}{-1}% \expandafter\@firstofone \else \expandafter\@gobble \fi ...


5

Here, I set up a recursive loop. Works with macros, too. \documentclass[11pt]{article} \newcounter{mycount} \def\repeatstring#1#2{% \setcounter{mycount}{#1}% \ifnum\value{mycount}>0\relax#2% \addtocounter{mycount}{-1}% \repeatstring{\value{mycount}}{#2}% \fi% } \begin{document} \repeatstring{5}{abc} \repeatstring{3}{\today} \end{document} ...


5

You are misunderstanding how the logical <expression> should be given. The result should be 'logically true', not the text true: \documentclass{article} \usepackage{etoolbox} \newcounter{countdown} \newcommand\concathere{} \newcommand\repeatstring[2]{% \setcounter{countdown}{#1}% \renewcommand\concathere{}% \whileboolexpr {test ...


9

I think the problem arises because when the sprial changes direction two squares are drawn at each corner. For example, if the spiral is moving right, when the x < x_max condition is not met the direction is changed but the y coordinate is not moved up so the next square is drawn in the same place as the last square. I've corrected this in the code below ...


2

Thanks to the inspiration from David's and Joseph's use of #1 as placeholder for the loop counter, I was able to improve the implementation that I've given in the question. I'll post it here mostly as a learning exercise for anyone who happens to have a similar use case. This version only expands the loop counter and leaves all other tokens alone, removing ...


3

I get the same output files with the following test.tex file: \documentclass[]{article} \usepackage{tikz} \usetikzlibrary{arrows,shapes,snakes,automata,backgrounds,fit} \usepackage[pgf]{dot2texi} \newtoks\dtttoks \begin{document} \begingroup \global\dtttoks={} \foreach \x / \y in {0/1,1/2,2/3}{ \edef\temp{a\x\space -> a\y\space [label = ...


7

There are a number of possible approaches to doing this without the complexity: I'll cover a couple using expl3. First, if you don't mind keeping things non-expandable then you could do something like \documentclass{article} \usepackage{expl3} \ExplSyntaxOn \cs_new_protected:Npn \For #1#2#3#4 { \int_step_inline:nnnn {#1} {#2} {#3 - 1} {#4} } ...


6

This loop just uses expansion. In order to use #1 as the loop counter it is easiest to define it anew each time, if you didn't want access to the counter you could more easily use \myrepeat{5}{some code} Note i didn't use \repeat as that name is taken in the existing \loop syntax. \documentclass{article} \def\myrepeat#1{\ifnum#1=0 ...



Top 50 recent answers are included