Math inside \text looses the information that it is inside a subscript $X_{a+b,\text{\ensuremath{a+b}}}$.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
$X_{a+b,\text{\ensuremath{a+b}}}$
\end{document}
I'd like to find different ways to "fix" that.
Background: This is for my package mhchem. There is no striking use case I can think of, right now. It's more of a "make it consistent" feature.
If you use, for instance \ce{H2O} in text mode, then my package will typeset this correctly using the current text font, so it will also look nice in headlines and TOCs. It basically uses math mode with some \texts. I give the user the freedom to insert math anywhere they wish, and they could even write something like \ce{NO_{2n + $\sum_i x_i + y_i$} or something else. I had to choose such a weird example, because all the sensible expressions (n, 2n, 2n+1) already get a special treatment. However, I still want to allow any math expression there, no matter how weird and nested.



\textbut just\mathrm. – campa Jul 25 '17 at 12:42\text, but maybe your application requires the use of\text. – Steven B. Segletes Jul 25 '17 at 12:47