2

I want to change/redefine the math environment in LaTeX Article class such that whenever I write a mathematical expression inline or in displayed math mode, it appears in a color of my choice. Here is an example of what I mean: enter image description here I can do it manually for every instance of inline math, or displayed math but I instead want to know how I can redefine the environment itself so that I have to do it only once and I can change the colors globally. Here is an MWE (in which I don't color the math):

\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{enumerate}
\item Households save $a_{t} \geq 0$ in the riskless debt issued by 
experts with an interest rate $r_{t}$. Thus, wealth follows:
\begin{equation*} 
da_{t} = (w_{t}z_{t} + r_{t}a_{t} - c_{t})dt = s(a_{t}, z_{t}, K_{t}, G_{t})dt
\item Optimal choice: $c_{t} = c(a_{t}, z_{t}, K_{t}, G_{t})$
\end{equation*}
\end{enumerate}
\end{document}
0

1 Answer 1

2

This is a way.

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{xcolor}
\everymath{\color{purple}}
\begin{document}
\begin{enumerate}
\item Households save $a_{t} \geq 0$ in the riskless debt issued by 
experts with an interest rate $r_{t}$. Thus, wealth follows:
\begin{align*}
\mathrm{d}a_{t} = (w_{t}z_{t} + r_{t}a_{t} - c_{t})\,\mathrm{d}t 
= s(a_{t}, z_{t}, K_{t}, G_{t})\,\mathrm{d}t
\end{align*}
\item Optimal choice: $c_{t} = c(a_{t}, z_{t}, K_{t}, G_{t})$
\end{enumerate}
\end{document}

enter image description here

Note that there can be all sorts of issues, see e.g. this post and this post. Naively one may think to use \everydisplay, too, but there are some drawbacks. At least with inline math and align this proposal works. Please note also that you cannot have an \item in an equation.

2
  • Always my best compliments for your fast answer.
    – Sebastiano
    Dec 19, 2019 at 18:24
  • 1
    This doesn't work for \[\] or \begin{equation}\end{equation} though.
    – handy
    Aug 7, 2020 at 11:24

Not the answer you're looking for? Browse other questions tagged .