This solution is now available as a package: leftindex
I tried adjusting egreg’s answer to the general case. It is not built specifically for \int and therefore does not produce quite as perfect an output for that particular symbol. The benefit is that it provides relatively nice results in the general case. I provide the command
\leftindex^{<left superscript>}_{<left subscript>} {<symbol>}
This will indent the left superscript with the same value as the negative indentation of the right subscript. Sometimes, this yields wrong results. Therefore, the command takes two additional, optional arguments:
\leftindex[<slanting phantom>][<height phantom>]
^{<left superscript>}_{<left subscript>} {<symbol>}
This one will instead calculate the left superscript indentation using the <slanting phantom>. If provided, it will calculate the height based on the <height phantom>.
There is also another, underlying command
\manualleftindex
{<height phantom>}
{<slanting phantom>}
{<subscript>}
{<superscript>}
which is mainly intended for use in other commands (or packages).
\documentclass{article}
\usepackage{expl3,mathtools,kpfonts}
\ExplSyntaxOn
\DeclareDocumentCommand\manualleftindex { mmmm }
{
% #1 = height phantom
% #2 = slanting phantom
% #3 = left superscript
% #4 = left subscript
\mathpalette __leftindex_auxiliary_mathpalette_command:nn { {#1}{#2}{#3}{#4} }
}
\ExplSyntaxOff
\DeclareDocumentCommand\leftindex { o o E{^_}{{}{}} m }
{
% #1 = slanting phantom
% #2 = height phantom
% #3 = left superscript
% #4 = left subscript
% #5 = symbol
\IfValueTF {#1}
{
\IfValueTF{#2}
{
\manualleftindex { #2 } { #1 } { #3 } { #4 }
}
{
\manualleftindex { #1 } { #1 } { #3 } { #4 }
}
}
{
\manualleftindex { #5 } { #5 } { #3 } { #4 }
}
#5
}
\DeclareDocumentCommand\LeftIndex { o o E{^_}{{}{}} }
{
% #1 = slanting phantom
% #2 = height phantom
% #3 = left superscript
% #4 = left subscript
\IfValueTF {#1}
{
\IfValueTF{#2}
{
\manualleftindex { #2 } { #1 } { #3 } { #4 }
}
{
\manualleftindex { #1 } { #1 } { #3 } { #4 }
}
}
{
\manualleftindex { } { } { #3 } { #4 }
}
}
\ExplSyntaxOn
\cs_new_protected:Npn\leftindex_kern_horizontal:n#1
{
\kern #1 \relax
}
\cs_new_protected:Npn\leftindex_set_mathsurround_to_zero:
{
% This is equivalent to "\m@th"
\dim_set:Nn \mathsurround { 0pt }
}
\cs_new_protected:Npn__leftindex_auxiliary_mathpalette_command:nn#1#2
{
__leftindex_auxiliary:nnnnn { #1 } #2
}
\dim_new:N\l__leftindex_phantom_height_dim
\box_new:N \l__leftindex_slanting_phantom_with_subscript_box
\dim_new:N \l__leftindex_slanting_phantom_with_subscript_dim
\box_new:N \l__leftindex_slanting_phantom_with_subscript_without_indentation_box
\dim_new:N \l__leftindex_slanting_phantom_with_subscript_without_indentation_dim
\dim_new:N \l__leftindex_indentation_of_slanting_phantom_subscript
\box_new:N \l__leftindex_superscript_temp_box
\dim_new:N \l__leftindex_width_of_superscript_dim
\box_new:N \l__leftindex_subscript_temp_box
\dim_new:N \l__leftindex_width_of_subscript_dim
\cs_new_protected:Npn__leftindex_auxiliary:nnnnn#1#2#3#4#5
{
\group_begin:
\hbox_set:Nn \l__leftindex_slanting_phantom_with_subscript_box
{ $ #1 #3 \sb{xxxxxx} $ }
\dim_set:Nn \l__leftindex_slanting_phantom_with_subscript_dim
{ \box_wd:N \l__leftindex_slanting_phantom_with_subscript_box }
\hbox_set:Nn \l__leftindex_slanting_phantom_with_subscript_without_indentation_box
{ $ #1 \hbox:n {$ #1 #3 $} \sb{xxxxxx} $ }
\dim_set:Nn \l__leftindex_slanting_phantom_with_subscript_without_indentation_dim
{ \box_wd:N \l__leftindex_slanting_phantom_with_subscript_without_indentation_box }
\dim_set:Nn \l__leftindex_indentation_of_slanting_phantom_subscript
{
\l__leftindex_slanting_phantom_with_subscript_without_indentation_dim
-
\l__leftindex_slanting_phantom_with_subscript_dim
}
\tl_if_blank:nTF { #4 }
{
\dim_zero:N \l__leftindex_width_of_superscript_dim
}
{
\hbox_set:Nn \l__leftindex_superscript_temp_box
{
$
\leftindex_set_mathsurround_to_zero:
#1 \sp { #4 }
$
}
\dim_set:Nn \l__leftindex_width_of_superscript_dim
{
\box_wd:N \l__leftindex_superscript_temp_box
-
\l__leftindex_indentation_of_slanting_phantom_subscript
}
}
\tl_if_blank:nTF { #5 }
{
\dim_zero:N \l__leftindex_width_of_subscript_dim
}
{
\hbox_set:Nn \l__leftindex_subscript_temp_box
{
$
\leftindex_set_mathsurround_to_zero:
#1 \sb { #5 }
$
}
\dim_set:Nn \l__leftindex_width_of_subscript_dim
{
\box_wd:N \l__leftindex_subscript_temp_box
}
}
\mathop{}
\leftindex_kern_horizontal:n
{
\dim_max:nn
{ \l__leftindex_width_of_superscript_dim }
{ \l__leftindex_width_of_subscript_dim }
}
\mathopen{ \vphantom { #2 } }
\tl_if_blank:nF { #4 }
{
\sp {
\mathmakebox[0pt][l]{
\mathmakebox[ \l__leftindex_indentation_of_slanting_phantom_subscript ][r]{ #4 }
}
}
}
\tl_if_blank:nF { #5 }
{
\sb {
\mathmakebox[0pt][r]{ #5 }
}
}
\group_end:
}
\ExplSyntaxOff
\begin{document}
[
x \leftindex^{a+b}_{c+d} {\int} f(x), dx
]
[
\leftindex^{1}{0} {f}^u_v
\neq
\leftindex^{pq}{0} {H}^u_v
]
[
\leftindex^{a}{b} {\Gamma}^c_d
\neq
\leftindex[]^{a}{b} {\Gamma}^c_d
]
\end{document}

\documentclass{article} \usepackage{mathtools} \begin{document} \[ \prescript{\rlap{a}}{b}{\int} \] \end{document}? – Zarko Aug 06 '20 at 17:26