I wanted to define some partial derivative commands that would be \partial y/\partial x if it was inside an inline equation and would use \frac{\partial y}{\partial x} if inside an equation environment. I searched around and came up with (honestly, probably from TeX.SE but I don't remember which question/answer it was):
\makeatletter
\newcommand{\pd}[2]{%
\def\@tempa{document}
\ifx\@tempa\@currenvir \partial {#1}/\partial{#2} \else
\def\@tempa{equation}
\ifx\@tempa\@currenvir \frac{\partial {#1}}{\partial {#2}}\else
\fi\fi
}
which was awesome! But then I tried using it inside:
\begin{equation}
\begin{aligned}
f &= \pd{y}{x} \\
g &= \pd{y}{z}
\end{aligned}
\end{equation}
and it didn't render correctly because the current environment was aligned and not equation. I could add aligned to my if statement but then I'll need to add branches for all the varieties of *matrix and who knows what else. I could add a default so that if it's not in document it always renders with the \frac{}{} form.
But all of that just doesn't seem like the right way to go. Is there a way to see if the command is issued somewhere inside of an equation environment, even if it is somewhere up the environment tree?
