I want to colour all sub- and super-scripts automatically. Following this question I was able to generate the desired result:
Using the example below.
However, activating the "_" is a problem for me as I have been using it extensively in file names, meaning this solution will typically fail for me when using "\input" and "\includegraphics".
Is there a way that I can activate the characters every time LaTeX enters math-mode?
Example
LaTeX file (typeset simply using pdflatex)
\documentclass{minimal}
\usepackage[active,tightpage,textmath]{preview}
\setlength\PreviewBorder{5pt}%
\usepackage{xcolor}
\newcommand{\amat}{\mathbf{A}}
\newcommand{\bmat}{\mathbf{B}}
\newcommand{\cmat}{\mathbf{C}}
\begin{document}
\(
\cmat_{i}^{k} = \amat^{i}_{j} \bmat^{j}_{k}
\)
\catcode`_=\active
\catcode`^=\active
\newcommand_[1]{\ensuremath{\sb{\begingroup\color{magenta}#1\endgroup}}}
\newcommand^[1]{\ensuremath{\sp{\begingroup\color{cyan}#1\endgroup}}}
\(
\cmat_{i}^{k} = \amat^{i}_{j} \bmat^{j}_{k}
\)
\end{document}



A^{b_{c}}? And, may it be assumed that subscript and superscript material is always encased in curly braces? – Mico Dec 29 '16 at 07:49