# How do you deal with multiple superscripts while writing higher order partial derivatives?

I have a set of PDE's i am trying to type in, certain higher order terms in them already have a superscript.

I am using the physics package function \pdv[n]{}{} , this is the code I have written

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{physics}

\numberwithin{equation}{section}
\begin{document}

\newcommand\vt{v_{\theta}}
\newcommand\vr{v_{r}}
\newcommand\vx{v_{x}}
\newcommand\vts{v_{\theta}^{*}}
\newcommand\vrs{v_{r}^{*}}
\newcommand\vxs{v_{x}^{*}}
\newcommand\ts{t^{*}}
\newcommand\rs{r^{*}}
\newcommand\xs{x^{*}}

\section{Governing Equations}

\begin{multline}
\pdv{\vrs}{\ts}+\vrs\pdv{\vrs}{\rs}+\vts\frac{1}{\rs}\pdv{\vrs}{\ts}+\vxs\pdv{\vrs}{\xs}-\frac{\vt^{*^2}}{\rs}= \\ -\frac{1}{\rho}\pdv{p^{*}}{\rs}+\frac{1}{\mu}\left[\frac{1}{\rs}\pdv{\vrs}{\rs}+\pdv[2]{\vxs}{\rs}+\frac{1}{\rs}\pdv[2]{\vxs}{\theta}+\pdv[2]{\vxs}{\vxs}\right]
\end{multline}
\end{document}


When I tried to compile this I get an error stating

 "! Double superscript.\l__deriv_p_denom_tl ...ariable:nn {pdv}{\xs }\sp{2} \end{multline} ".


How can this be resolved? I believe that this stems from the higher order PDE terms.

• Welcome to TeX.SE! It's great that you've included your code, but please consider adding a minimal working example; not only does it make it easier to help you, but often the process of producing it solves your problem on its own. – dgoodmaniii Dec 5 '19 at 12:56
• (1) welcome, (2) on this site you are much much more likely to get help if you provide a self contained minimal example others can copy and test as is. Here we have to guess the document class and preamble. – daleif Dec 5 '19 at 12:56
• Your code seems to give the output that you are looking for @Hrushikesh_gosatkar. Where are you facing the error, can you specify? – tachyon Dec 5 '19 at 13:15
• From the error, I can see you load the derivative package aswell since \l__deriv_p_denom_tl is from there. In developing that package, I couldn't think of find any situation, where one would run into the double superscript issue. I will make a fix for it and upload it to CTAN, when I get some more free time. – Simon Dec 8 '19 at 14:35

What you need is some strategic placement of curly braces.

Basically, you can't just type a^b^c in LaTeX, because it woudn't understand that the entire b^c part is supposed to be the superscript. Instead, you have to enclose that in braces, like this: a^{b^c}.

The same thing happens in your equation - you just need to sprinkle in some more braces. The easiest solution is to put an extra pair in each of your \newcommand definitions which contain ^.

\newcommand\vt{v_{\theta}}
\newcommand\vr{v_{r}}
\newcommand\vx{v_{x}}
\newcommand\vts{{v_{\theta}^{*}}} % extra {}
\newcommand\vrs{{v_{r}^{*}}}      % extra {}
\newcommand\vxs{{v_{x}^{*}}}      % extra {}
\newcommand\ts{{t^{*}}}           % extra {}
\newcommand\rs{{r^{*}}}           % extra {}
\newcommand\xs{{x^{*}}}           % extra {}


I tracked the problem to the following:

When you define the newcommands the command is not a single token, thus you cannot put a superindex if another exists.

You need to add extra braces to your newcommands definitions

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{physics}

\numberwithin{equation}{section}
\begin{document}

\newcommand\vt{{v_{\theta}}}
\newcommand\vr{{v_{r}}}
\newcommand\vx{{v_{x}}}
\newcommand\vts{{v_{\theta}^{*}}}
\newcommand\vrs{{v_{r}^{*}}}
\newcommand\vxs{{v_{x}^{*}}}
\newcommand\ts{{t^{*}}}
\newcommand\rs{{r^{*}}}
\newcommand\xs{{x^{*}}}

\section{Governing Equations}

\begin{multline}
\pdv{\vrs}{\ts}
+\vrs \pdv{\vrs}{\rs}
+\vts \frac{1}{\rs} \pdv{\vrs}{\ts}
+\vxs \pdv{\vrs}{\xs}
-\frac{\vt^{*2}}{\rs}= \\
-\frac{1}{\rho}\pdv{p^{*}}{\rs}+\frac{1}{\mu}\left[\frac{1}{\rs}\pdv{\vrs}{\rs}+\pdv[2]{\vxs}{\rs}+\frac{1}{\rs}\pdv[2]{\vxs}{\theta}+\pdv[2]{\vxs}{\vxs}\right]
\end{multline}
\end{document}


Then everything works as expected.