In my Tex document, I want to colour all the expressions within two dollar signs (such as $e^{i\pi}$, $\log x$ etc), within a pair of dollar signs (such as $$e^{i\pi}+1=0$$), within the \begin{eqnarray}...\end{eqnarray} in a desired color (say, yellow) without doing it each time. Is there any command to achieve this?
Asked
Active
Viewed 158 times
2
leandriis
- 62,593
Solidification
- 135
-
1Probably How put color in all math mode? is related. – leandriis Aug 16 '20 at 16:13
2 Answers
2
Easy with \everymath.Note that doesn't change the equation numbers colour, bur it can easily be changed with the \newtagform command from mathtools.
\documentclass[12pt]{article}
\usepackage{amsmath, bm}
\usepackage[svgnames]{xcolor}
\colorlet{mathcolour}{red}
\everymath{\color{mathcolour}}
\begin{document}
Some text. Some more text. $T_i$ \quad $\mathbf e^{i\pi}$
\colorlet{mathcolour}{DeepSkyBlue}
\begin{align}
a & = \bm{b} \
c & = \bm{d}
\end{align}
\end{document}
Bernard
- 271,350
-
Thanks @Bernard As far as the dollars are concerned, it is okay. Why it doesn't work for "align environment" or "eqnarray environment"? For "align environment" do we have to repeat the command separately every time? – Solidification Aug 16 '20 at 17:06
-
??? My example shows it works for align. I even could change the colour. I didn't test eqnarray, as I never use it – it produces bad spacing at the alignment points. Do you use a standard class? – Bernard Aug 16 '20 at 17:10
-
-
This solution can have lots of unwanted consequences. See \everymath and author color for discussion. The suggested duplicate it probably a better way. – Alan Munn Aug 16 '20 at 17:19
-
I see. Didn't know this (personally I don't colour systematically equations). Thanks for the information. Can we say that, if used, it should be so with the utmost caution? – Bernard Aug 16 '20 at 17:32
-
@Bernard Well it's a solution that will have effects that aren't easy to predict, So in addition to the
\authorissue, allminipageandtabularenvironments will be coloured, as will footnote numbers for example. Frank's solution in the question I linked to solves the first two, but not the footnote numbers. – Alan Munn Aug 16 '20 at 18:00
0
\documentclass{article}
\usepackage{xcolor}
\begin{document}
$T_i$
${\color{red}T_{\color{black}i}}$
${\color{blue}e^{i\pi}}$
\end{document}
edit
\documentclass{article}
\usepackage{xcolor}
\everymath{\color{red}}
\begin{document}
$T_i$
${T_{i}}$
${\color{blue}e^{i\pi}}$
\end{document}
js bibra
- 21,280
-
2This is not what I am looking for. I want a command that all the expressions inside $...$ are automatically colored by a single command at the beginning of the document. – Solidification Aug 16 '20 at 16:50
-
@mithusengupta123 please see edit from -- https://tex.stackexchange.com/questions/211780/how-put-color-in-all-math-mode?noredirect=1&lq=1 – js bibra Aug 16 '20 at 16:56
-
1@jsbibra The
\everymathsolution is not really viable. See comments on the other answer. – Alan Munn Aug 16 '20 at 18:02


