I'd like to modify the \int
command such that it adds an automatic negative space, e.g. \!
after the integral sign. Preferentially, I'd like to be able to not edit any of my code, so cleverly redefining \int
seems like my best option. Unfortunately, naive implementations get the limits wrong:
\documentclass{article}
\usepackage[intlimits]{amsmath}
\usepackage{ifthen}
\newcommand{\diff}[2][]{
\ifthenelse { \equal {#1} {} }
{\ensuremath{\mathop{\mathrm{d} #2}}}
{\ensuremath{\mathop{\mathrm{d}^#1 #2}}}
}
\begin{document}
This is what I would want:
\begin{equation}
\int_0^\infty \mspace{-4mu}\diff[3]{\boldsymbol r} f(\boldsymbol r),
\end{equation}
but with this ``user code", containing no negative spacing explicitly:
\begin{verbatim}
\int_0^\infty \diff[3]{\boldsymbol r} f(\boldsymbol r),
\end{verbatim}
which for comparison with the above gives:
\begin{equation}
\int_0^\infty \diff[3]{\boldsymbol r} f(\boldsymbol r),
\end{equation}
mostly because this gives me the option to remove it or change the spacing when I see fit.
\end{document}
Which results in:
Best Answer
With this code
you remove space after the
\int
but your code must be written always with\int_{..}^{..}
with limits and in that specific order. You could write some trickery so that if the limits are blank they are not added to the code. Or you could do some trickery with\@ifnextchar
so that one checks for both limits in any order and the result is more clean.If it's wanted, I can add that. Here's the code (thanks to @kyle_the_hacker):In any case, here's an oportunity to add a bit of code I wrote some time ago to add new kind of arguments to xparse.
And it may be even better to check if
\diff
follows and in case it doesn't just have the original behaviour, just change the definition to this (it's a pity that spaces aren't skipped, so we need to explicitly check for a space and then check for\diff
after that)After a few thoughts
Completed rethink code that I would use for a complete flexibility. This adds all possible combinations of sub-superscripts for the
\int
plus the natural input for differentials\dd x
,\dd{\bm x}
,\dd^2 x
,\dd^{a_1}{x_1}
.that with the
xparse
code from before it would become