[Tex/LaTex] Repeating another text multiple times using commands

macros

I have one command named \commandone, which outputs

test.

I created it using \newcommand\commandone{test}

I want to have a second command \commandtwo{}, which takes an integer input and call the first command \commandone repeatedly according to the input integer. So if \commandtwo{3}, the output will become "

testtesttest

Best Answer

\documentclass{minimal}
\usepackage{pgffor}
\newcommand{\cmd}{test}
% to provide your syntax
\newcommand{\Repeat}[2]{% \repeat already defined
    \foreach \n in {1,...,#1}{#2}
}
\begin{document}
\foreach \n in {1,...,4}{\cmd}

\Repeat{6}{\cmd}
\end{document}

enter image description here

Related Question