# How to define new command for commands like \frac{} or \int{}^{}?

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.

You can define a command with parameters:

\newcommand{\divbytwo}{\frac{#1}{2}}


The #1 is the placeholder for the first parameter to the macro: \divbytwo{3} will expand to \frac{3}{2}.

\newcommand{\divby}{\frac{#1}{#2}}


will do the job. The  tells TeX how many parameters there will be. They're put in places #1 and #2. Of course in this simple example\divby is just frac so you gain little by defining it.

• Thank you, but can we handle two parameters together by any chance: something like: \newcommand{\divby}{\frac{#1}{#2}}? – Mathmath Feb 21 '13 at 23:55
• The optional argument of \newcommand (the number in square brackets) determines the number of arguments of the new command. So, in your case: \newcommand{\divby}{\frac{#1}{#2}} – Sašo Živanović Feb 22 '13 at 1:33

You can also use the "old" macro for the fractions (used in plain TeX):

{a\over b}


that produces the same result of

\frac{a}{b}


For integrals, I suggest you the following macro:

\def\intx#1{\int {#1}\,dx}


that produces the integral of #1 with its differential (where x is your variable)

• Using \over is best avoided in LaTeX, and also \def is discouraged in document preambles. – egreg Feb 22 '13 at 9:47