# Define a command including paranthesis and brackets

I would like to define a command using another one to make it short. But the old command includes paranthesis and square and curly brackets. For example

\oldlongcommand[A](0:4){B}


I would like to define a command named new and write \new(A,0,4,B) or \new{A,0,4,B} to make it short. I tried to write simply

\newcommand{\new}[4]{\oldlongcommand[#1](#2:#3){#4}}


But it is not working.

How can I achieve this?

• With your current definition you cannot use \new{A,0,4,B} but you must use \new{A}{0}{4}{B}. Something like \newcommand*{\new}[1]{\newaux#1\relax} \def\newaux#1,#2,#3,#4\relax{\oldlongcommand[#1]{#2}{#3}{#4}} might go in the right direction, but it can depend on how the old command is defined, and whether the arguments can be commas or not. – campa May 24 '18 at 14:17
• Sorry, but it is not working. The arguments are just as I write. There is a : in the paranthesis. can it be the reason? – Muhsin May 24 '18 at 17:31
• @campa You did not obey syntax according to \oldlongcommand's parameter text. I think it could be: \newcommand*{\new}[1]{\newaux#1\relax} \def\newaux#1,#2,#3,#4\relax{\oldlongcommand[#1](#2:#3){#4}} – Ulrich Diez May 29 '18 at 22:09
• @UlrichDiez Absolutely true. The troubles of copy-pasting snippets :-) – campa May 30 '18 at 6:47

You defined:

\newcommand{\new}[4]{\oldlongcommand[#1](#2:#3){#4}}


From the parameter text of your definition one can see that your macro \new does process four undelimited arguments.
Thus you need to provide four undelimited arguments and not just one.

\new{A}{0}{4}{B}


Using delimited arguments implementing syntax \new(A,0,4,B) is feasible as well.
Be aware that with the example below nesting parenthesis is not a good idea.
Also spaces/space tokens surrounding the commas will not get removed.
Braces around the single comma-delimited arguments will get stripped off.

\newcommand\new{}%
\long\def\new(#1){\newinternal#1,}

\newcommand\newinternal{}%
\long\def\newinternal#1,#2,#3,#4,{\oldlongcommand[#1](#2:#3){#4}}%


\new(A,0,4,B)
\newinternal A,0,4,B,
\oldlongcommand[A](0:4){B}

With this approach one level of surrounding braces will be stripped off when \newinternal gathers its comma-delimited arguments – e.g.:

\new({A},{0},{4},{B})\oldlongcommand[A](0:4){B} instead of
\oldlongcommand[{A}]({0}:{4}){{B}}.

With this approach spaces surrounding commata/parenthesis will not get removed – e.g.:

\new(A , 0, 4, B )\oldlongcommand[A ]( 0: 4){ B } instead of
\oldlongcommand[A](0:4){B}.