We know that we could define a new command for boldfaced or calligraphic C, for example I can define \newcommand{\Cx}{\mathbb{C}}
, which will produce the boldfaced C, i.e. $\mathbb{C}$
for me. But how do I define new command for say more complicated commands, e.g. \frac{}{}
for getting fractions or say \int{}^{}
for definite integrals? I tried defining \newcommand{\fr(,)}{\frac{}{}}
, but it is not working. It seems to me there should be a correct way to define it.
[Tex/LaTex] How to define new command for commands like \frac{} or \int{}^{}
macrosmath-mode
Best Answer
You can define a command with parameters:
The
#1
is the placeholder for the first parameter to the macro:\divbytwo{3}
will expand to\frac{3}{2}
.Edit: incorporating comments from the OP and @SašoŽivanović asking/answering about macros with more than one argument -
will do the job. The
[2]
tellsTeX
how many parameters there will be. They're put in places#1
and#2
. Of course in this simple example\divby
is justfrac
so you gain little by defining it.