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


-
Could you clarify a) what your new macro should do with b) how many parameters? A macro name like \fr(,) is almost not possible and would be very cumbersome to actually call in your document. Related: Symbols to avoid while creating new commands and “Non-letters in macro names”. – Qrrbrbirlbel Feb 23 '13 at 4:14

You can define a command with parameters:

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


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 -

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


will do the job. The [2] 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}[1][2]{\frac{#1}{#2}}? – Mathmath Feb 21 '13 at 23:55

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