# Coloring the exponent a different color than the base number

I want to color an exponent differently than its base. I'm trying to do it as shown below, which displays correctly in the editor I'm using, but my screenreader will not read it.

The problem is something to do with how I am bracketing for the color of the exponent. Perhaps it's not possible to set it separately like I'm trying to do? Is there something wrong in the way I've bracketed for the color of the exponent? Or is this a MathJax issue, with the engine not being able to interpret a colored exponent?

 \textcolor{darkred}{3}\textcolor{blue}{^{4}} =\textcolor{darkred}{3\cdot 3\cdot 3\cdot 3}=81

• Aug 16 at 5:01

Is there something wrong in the way I've bracketed for the color of the exponent?

You should replace

\textcolor{blue}{^{4}}


with

^{\textcolor{blue}{4}}


\documentclass{article}
\usepackage{xcolor}
\begin{document}
$\textcolor{red}{3}^{\textcolor{blue}{4}} =\textcolor{red}{3\cdot 3\cdot 3\cdot 3} =81$
\end{document}


I'm not entirely certain what you mean regarding your screenreader issue, but unless you have some compelling reason not to, you ought typeset this in math mode. I suspect that this might also resolve that issue.

xcolor can work in math mode and can be conveniently used as shown in a similar answer, from which the below is adapted. Note that unlike back then, as pointed out by David Carlisle, \mathcolor is now built into xcolor.

\documentclass{article}

\usepackage{xcolor}

\begin{document}

$\mathcolor{red}{3}^{\mathcolor{blue}{4}} \mathcolor{black}{=} \color{red}{3 \cdot 3 \cdot 3 \cdot 3} \mathcolor{black}{= 81}$

\end{document}


This produces: