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

I defined a macro for writing a partial derivative:


this works when inserting two parameters. But I want to modify it so that when inserting only a single parameter, it will leave the numerator blank and fill only the denominator with that parameter. i.e.,


will produce

\frac{\partial}{\partial x}

How can I achieve that?

share|improve this question
Also see this related question on a flexible-partial-derivative-macro. – Peter Grill Sep 23 '11 at 16:30
up vote 14 down vote accepted

The best approach is to make the numerator variable optional:


Now \pder[f]{x} and \pder{x} will work as you wish.

A solution that uses the syntaxes \pder{f}{x} and \pder{x} is


which however is quite risky, because an open brace after \pder{x} will be mistaken for the start of the second argument (spaces are ininfluent). All in all, the optional argument path seems better.

If you don't plan to often use \pder inside moving arguments, \DeclareRobustCommand can be changed into \newcommand, but the command would be fragile and so needing \protect in front of it when in moving arguments.

share|improve this answer
It works alright, but is it possible to define it so that the commmand \pder{y}{x} is still a valid one, instead of the square brackets? as I find this form (curly braces) nicer. – PineApple Sep 22 '11 at 11:37
@PineApple See edited answer – egreg Sep 22 '11 at 12:55

In addition to following the excellent answers of egreg and Ant, who both suggest to use a definition of the \pder macro where the first (numerator) argument is explicitly optional, you could also just keep your existing macro but insert a pair of empty braces, like {}, whenever you want the numerator to consist of just the partial symbol:

$\pder{f(x,y,z)}{x}$ and $\pder{}{x} f(x,y,z)$

Not as elegant as the other method, for sure, but this way your code will immediately make clear if you accidentally forgot to specify one or the other argument of the \pder command. Happy TeXing!

share|improve this answer

You can make #1 an optional parameter by providing a default value for it (in this case nothing at all):

(edited to fix an accidental paste of the original definition - thanks @Gonzalo for spotting this!)


This allows




(note the square brackets for the now optional argument).

share|improve this answer
Your definition, as it is, requires two mandatory arguments, so $\pder{x}$ won't work and $\pder[y]{x}$ will produce undesired results. If you want the first argument to be optional with no default value, your definition should be \newcommand{\pder}[2][]{\frac{\partial#1}{\partial#2}}. – Gonzalo Medina Sep 22 '11 at 11:57
Edited to fix. Sorry -- I managed to paste the original version rather than my changed one from my text editor! – Ant Sep 22 '11 at 13:29

use it as an optional argument:

\pder{x} will produce $\frac{\partial}{\partial x}$

\pder[x]{y} will produce $\frac{\partial x}{\partial y}$


enter image description here

share|improve this answer
Why do you use two extra macros and \@ifnextchar instead of the regular optional argument syntax like ant and egreg? – Tobi Sep 22 '11 at 11:21

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.