# Defining macros with arguments

With newcommand I can define customized command like \ABC. Is there any way to define a command with arguments. For example I want \brat{A}{B} be the same as [\![A,B]\!].

• Just to make sure: You want use to round parentheses and one comma (and no spaces) to set off the two parameters?
– Mico
Jul 13, 2014 at 12:32
• No, I want to feed the arguments, I don't know how. Jul 13, 2014 at 12:33
• So would \brat{A}{B} be acceptable syntax?
– Mico
Jul 13, 2014 at 12:35
• \newcommand\ABC[3]{Something with #1, #2 and #3} where the number is the number of parameters. Jul 13, 2014 at 12:42
• This might be relevant: tex.stackexchange.com/questions/28042/…. Jul 13, 2014 at 13:38

The general form of \newcommand is

\newcommand\commandname[number of arguments][value of optional argument]{code}


(Most of the time there won't be an optional argument, in which case this is omitted.) The arguments are given as #1, #2 etc in code.

To define your \brat command you would write

\newcommand\brat[2]{[\![#1,#2]\!]}


You then use this macro by writing \brat{A}{B}, \brat{A}{C} and so on. If almost all of the time you wanted the first argument to be A then you could instead use an optional first argument and define

\newcommand\Brat[2][A]{[\![#1,#2]\!]}


You use this version of the macro n almost exactly the same way except that you do not need to specify A: so \Brat{B} produces the same as \brat{A}{B} before. To change the value of the optional argument from A to C, say, you would write \Brat[C]{B}. This is the same as \brat{C}{B} using the first macro.

In TeX, we can define macros with arguments by

 \def\macro#1#2#3#4{body with #1 argument, #2 argument, #3 argument, #4 argument}


and usage is:

 \macro{first}{second}{third}{four}


or

\macro fstf


which is equivalent to \macro{f}{s}{t}{f}.

There is another method to declaring "delimited" parameters (which is not supported by LaTeX \newcommand), see (for example) TeX in a Nutshell, pages 9 and 10.