# Why two different print styles for the x's?

Created the rather nasty markup below. Why are there two different print styles for the x's?

$$\ce{[H+]^4 + (K_{a1} + xC_T)[H^+]^3 +(K_{a1}K_{a2} + (x - 1 )C_TK_{a1}-K_w)[H+]^2 + K_{a1}((x - 2)C_T-K_w)[H+] - K_{a1}K_{a2}K_w }\tag{C4}$$

renders as

$$\ce{[H+]^4 + (K_{a1} + xC_T)[H^+]^3 +(K_{a1}K_{a2} + ( x - 1 ) C_T K_{a1}-K_w)[H+]^2 + K_{a1}((x - 2)C_T-K_w)[H+] - K_{a1}K_{a2}K_w }\tag{C4}$$

• This was a feature that mhchem had actually considered implementing earlier ;) See About the scope of mhchem Jul 27 '18 at 16:51

You are mixing chemistry typeset with maths typeset; I don't think that the mhchem module is set up for this. There is probably much more wrong than what you consider a bug. Assuming $K$ is an equilibrium constant, it should be in italics (it is not with \ce) and the subscript should be in upright font (but get interpreted as variables within \ce). A similar thing happens to the interpretation of the $x$.
The macro \ce{ ... } will always try to interpret its contents as a chemistry or reaction equation; it is not designed to handle anything else. So in your equation, actually only the protons should be wrapped within this macro:
$$\begin{multline} [\ce{H+}]^4 + (K_\mathrm{a1} + xC_T)[\ce{H+}]^3 + (K_\mathrm{a1} K_\mathrm{a2} + (x - 1) C_T K_\mathrm{a1} - K_\mathrm{w})[\ce{H+}]^2\\ + K_\mathrm{a1} ((x - 2)C_T - K_\mathrm{w})[\ce{H+}] - K_\mathrm{a1} K_\mathrm{a2} K_\mathrm{w} \tag{C4} \end{multline}$$
$$\begin{multline} [\ce{H+}]^4 + (K_\mathrm{a1} + xC_T)[\ce{H+}]^3 + (K_\mathrm{a1} K_\mathrm{a2} + (x - 1) C_T K_\mathrm{a1} - K_\mathrm{w})[\ce{H+}]^2\\ + K_\mathrm{a1} ((x - 2)C_T - K_\mathrm{w})[\ce{H+}] - K_\mathrm{a1} K_\mathrm{a2} K_\mathrm{w} \tag{C4} \end{multline}$$