I would like the simplest (in terms of length of characters) way to create a macro that does something or, optionally, does something n times.
In fact, all I want to do is to create something like --------X where the -`s go from 1 to n. I do not want to have to supply 1 to the macro as that is default and the most used case.
So
\dash{X} gives -X
\dash[3]{X} gives ---X
or
\dash{X}[3] gives ---X
or
\dash{X}{3} gives ---X
or
\dash{3}{X} gives ---X
I don't care about the syntax. Just that it is short and works as intended and should be efficient. I probably don't want to have nested groups used because there would be no point and it would be inefficient, but either way doesn't matter.
I'd like to use as little extra packages as possible unless some package does this well to make it pretty short.
Something like
\newcommand{\dash}[2][1]{\directlua{for i=1,#1 do tex.print('-') end}#2}%
works with LuaLaTeX but tex.print
seems to add a space after/before each dash resulting in - - - -X.
\dash
: fix Werner's code by doing\prg_replicate:nn {#1}{{#2\kern0pt}}#3
– egreg Feb 5 '17 at 11:20