2

I'm trying to create some shortcut for the Leibniz notation for partial derivatives. Here the code

\newcommand{\px}[1][]{\frac{\partial{#1}}{\partial x}}

When I invoke this without arg, it's work properly, but at the time of pass an arg it doesn't work that I expect.

An example of code

\documentclass[10pt,letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish,es-tabla]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,amsthm}
\newcommand{\px}[1][]{\frac{\partial{#1}}{\partial x}}
\begin{document}
    \[
        \px\quad\px{F_x}
    \]
\end{document}

The result is

enter image description here

Instead of

enter image description here

Thanks in advance.

  • 1
    \px\quad\px[F_x] should do the trick – Simon Feb 9 at 20:44
  • The idea is when I type \px{F_x} do the same thing when I type \frac{\partial F_x}{\partial x} and when I type \px show \frac{\partial}{\partial x} – Patrick Feb 9 at 20:48
  • optional arguments use [] not {} – David Carlisle Feb 9 at 20:48
  • 3
    There are at leasr three interesting packages that greatly simplify typing Leibniz' notation, and do more than this simple shortcut: esdiff, diffcoeff and derivative. You should take a look at their documentation. – Bernard Feb 9 at 20:50
3

If you define \px as

\newcommand{\px}[1][]{\frac{\partial{#1}}{\partial x}}

the [1] defines \px as a command with 1 argument, but the [] written right after the [1] make this argument optional. If you included something between this second pair of square brackets, it would become a default value for this optional argument. So with \px defined as above, the command \px doesn't take any argument with curly braces, only an optional argument with square brackets.

You could also get the result you are looking for by removing the [] in the definition of \px. In that case, your command would take a single argument with curly braces.

Here is a complete example.

\documentclass{article}
\usepackage{amsmath}
\newcommand{\px}[1][]{\frac{\partial{#1}}{\partial x}}
\newcommand{\otherpx}[1]{\frac{\partial{#1}}{\partial x}}
\begin{document}
\[
\px{}, \quad \px{F_x}, \quad \px[F_x], \quad
\otherpx{}, \quad \otherpx{F_x}
\]
\end{document}

  • 1
    Thanks, it is a lot useful – Patrick Feb 9 at 21:09
  • 1
    Very kind Vincent I hope that you I have seen my comment of the professor who didn't even ask me thanks since he had the MikTeX distribution a bit outdated. – Sebastiano Feb 9 at 22:22
4

Is this the required result of the your question?

enter image description here

\documentclass[10pt,letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish,es-tabla]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,amsthm}

\newcommand{\px}[1][]{\frac{\partial#1}{\partial x}}
\begin{document}
    \[
    \px[F_x], \px
    \]
\end{document}
  • 1
    Thanks for your help, it's works – Patrick Feb 9 at 20:51
  • @Patrick Happy to help you... it's true I'm scarce user compared to the others but sometimes I find the right solution. – Sebastiano Feb 9 at 20:52
  • Why the second argument? – egreg Feb 9 at 21:07
  • @egreg Done!!!! Before I was in chat on Physics.SE. – Sebastiano Feb 9 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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