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]\!]
.
[Tex/LaTex] Defining macros with arguments
macros
macros
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]\!]
.
Best Answer
The general form of
\newcommand
is(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 incode
.To define your
\brat
command you would writeYou 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 beA
then you could instead use an optional first argument and defineYou 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 fromA
toC
, say, you would write\Brat[C]{B}
. This is the same as\brat{C}{B}
using the first macro.