I would like to be able to measure the space taken up by an \int
and have that length stored in a \newlength{}
. It is not as easy as
\settowidth{\@IntWidth}{\widthof{$\int$}}
In the MWE below, I attempt to apply a negative \kern
of the measured spacing and redraw the symbol in red. If the measuring was done correctly, the red symbol should be exactly on top of the black symbol, but I get:
Notes:
- This ONLY address the case where there is both an upper and lower limit given, so the code that deals with the other options is commented out.
Code:
\documentclass{article}
\usepackage{amsmath}
\usepackage{calc}
\usepackage{xcolor}
\usepackage{xparse}
\newcommand{\dx}{\mathrm{d}x}%
\makeatletter
\let\OldIntOp\int
\newlength{\@IntWidth}
%% https://tex.stackexchange.com/a/345383/4301
\RenewDocumentCommand\int{e{_^}}{% underscore ALWAYS before ^
%\IfNoValueTF{#2}{% No upper limit
% \IfNoValueTF{#1}{% No lower and upper limit
% \OldIntOp
% }{% Only lower limit
% \OldIntOp_{#1}
% }
%}{
% \IfNoValueTF{#1}{% No lower, but do have upper limit
% \OldIntOp^{#2}
% }{% Both lower and upper limit
\OldIntOp
\settowidth{\@IntWidth}{\widthof{$\OldIntOp$}}% ????? How compute this ??????
\kern-\@IntWidth
{\color{red} \OldIntOp_{#1}^{#2}}
% }
%}%
}\makeatother
\begin{document}
\noindent
In inline math $\OldIntOp_a^b y\dx$, and in display math it is:
\begin{flalign*}
&\displaystyle\OldIntOp^b_a y\dx
\textstyle\OldIntOp_a^b y\dx
\scriptstyle\OldIntOp_a^b y\dx
\scriptscriptstyle\OldIntOp_a^b y\dx
&
\end{flalign*}
In inline math $\int_a^b y\dx$, and in display math it is:
\begin{flalign*}
&\displaystyle\int^b_a y\dx
\textstyle\int_a^b y\dx
\scriptstyle\int_a^b y\dx
\scriptscriptstyle\int_a^b y\dx
&
\end{flalign*}
\end{document}