TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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:


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] 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.

share|improve this answer
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
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}[2]{\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


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)

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.