Could anyone explain why the sub-indexes were placed not at their correct positions when color is used? 
With some further experiments I found that the problem can be fixed by surrounding the sub-indexes with more {}, but why without the extra {} the code does not produce correct output?
\documentclass[11pt]{article}
\usepackage{xcolor}
\newcommand{\dint}{\displaystyle \int}
\begin{document}
\[
\dint_1^e \frac{\ln x}{x} dx =
\dint^{\color{red} \ln e}_{\color{red} \ln 1} u ~du %buggy
=\dint_{\color{cyan}{\ln 1}}^{\color{cyan}{\ln e}} u ~du %buggy
= \dint^{\ln e}_{\ln 1} u ~du %without using color, it works fine
\]
\end{document}
^{{\color{red} \ln e}}or^{\textcolor{\color{red} \ln e}}– David Carlisle Dec 10 '21 at 21:15