Here's the really bad case:
With a red bar to show what is bothering me in particular:
Here's a simpler case where the issue is a non-issue, but perhaps one can get a hint of why it starts to get bad:
Here's some minimum code to produce the problem examples:
\documentclass{article}
\usepackage{amsmath}
\usepackage{physics}
\newcommand{\mycommand}[1]{\ensuremath{{#1}_{p}}}
\renewcommand{\vec}[1]{\ensuremath{\mathbf{#1}}}
\newcommand{\normv}[2][p]{%
\ensuremath{\norm{\vec{#2}}_{#1}}%
}
\begin{document}
\begin{equation*}
0 = \frac{x}{\mycommand{x}}
\end{equation*}
\begin{equation*}
\vec{x} = \frac{\vec{x}}{\normv{x}}
\end{equation*}
\end{document}
I got the following bit of code from the answer to this question:
\newcommand{\alignedvfrac}[2]{%
\setbox0\hbox{$#1$} % put the numerator in box0
\dimen0=\wd0 % measure box0
\setbox1\hbox{$#2$} % put the denominator in box1
\dimen1=\wd1 % measure box1
\ifdim\wd0<\wd1 % if box0 is narrower than box1
\dfrac{#1\hfill}{#2} % put \hfill in the numerator
\else
\dfrac{#1}{#2\hfill} % otherwise put \hfill in the denominator
\fi
}
Using it does not help:
I don't understand why it doesn't work as it seems that the problems are basically the same. Can you help me understand?
\mathrlap{_p)
to make the subscript have "no width". requiresmathtools
.\mathrlap{_p}
basically "hides" the subscript in the calculation for the box size?_p
, and there are other such clashes..., so somehow, I need it to go intomathrlap
only for the alignment of the numerator and denominator, but then revert back to normal mode