TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

In my thesis i need to use quite often the partial differential fraction like

\frac{\partial^\alpha x}{\partial y^\alpha }}

I therefore defined the command

\newcommand{\partialfrac}[3][]{\frac{\partial^ #1 #2}{\partial #3 ^ #1}}

That should be equal to the first one using


That works if I define the optional #1 input. I would like to be able to skip the superscript if i want to (usually ^1 is not written...) but if I omit the optional input i receive an error. Is there a way to tell latex to "skip" the superscript somehow?


share|improve this question
up vote 6 down vote accepted

An expandable test would be:

  % #1 is empty
  % #1 is not empty

Also ^#1 fails if #1 consists of several tokens. This is fixed by ^{#1}.


    \partial \ifx\\#1\\\else^{#1}\fi #2%
    \partial #3 \ifx\\#1\\\else^{#1}\fi

  \partialfrac{a}{b} = \partialfrac[\alpha]{x}{y}


share|improve this answer

I think there is still room for an xparse-based version. Thanks to \IfNoValueTF test, it is possible to check whether the optional first argument is present:


\NewDocumentCommand{\partialfrac}{o m m}{%
 \frac{\partial #2}{\partial #3}%
 \frac{\partial^{#1}#2}{\partial #3^{#1}}%

  \partialfrac{a}{b} = \partialfrac[\alpha]{x}{y}

The result:

enter image description here

share|improve this answer

use etoolbox to test for optional argument and act accordingly.

\newcommand{\partialfrac}[3][]{\frac{\partial\ifblank{#1}{}{^ #1} #2}
      {\partial #3 \ifblank{#1}{}{^ #1}}}


share|improve this answer

Without a package, you can do it thus:

  \frac{\partial\mysscript #2}{\partial #3\mysscript}}
share|improve this answer

I'm sorry I opened this question: i tried for 1 hour before opening it and then found the solution 2 minutes after....



works as intended.

Thank you very much

share|improve this answer
You will note that a slight horizontal space is introduces with the syntax ^{}, which may not be what you actually wish, when the argument is blank. – Steven B. Segletes Apr 28 '14 at 13:42
You are right... I will look for one of yours solution. – Luca Amerio Apr 28 '14 at 14:09

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.