3

I want to put all math mode in a color, for example, red. But I don't know how to do that. In this web I found how to do it, but in Beamer, I want do it too in Article, Book, etc.

Thanks for your time.

3
  • 5
    \everymath{\color{red}}, \everydisplay{\color{red}}? Commented Nov 12, 2014 at 7:22
  • 1
    Welcome to TeX.SX! I'm not sure why you'd want such a device.
    – egreg
    Commented Nov 12, 2014 at 10:43
  • Sort of related: tex.stackexchange.com/q/335/86 Commented Nov 12, 2014 at 21:56

1 Answer 1

8

Here is a way:

\documentclass{article}

\usepackage{xcolor}
\usepackage{amssymb}

\makeatletter
\renewcommand{\displaymath}{\color{red}\[}
\renewcommand{\enddisplaymath}{\]\@ignoretrue\color{black}}

\renewcommand{\(}{\relax\ifmmode\@badmath\else\color{blue}$\fi}
\renewcommand{\)}{\relax\ifmmode\ifinner$\color{black}\else\@badmath\fi\else \@badmath\fi}

\catcode`\$=13
\def${\ifmmode\)\else\(\fi}
\makeatother

\begin{document}

Una funzione $f:U \longrightarrow \mathbb{C}, U\){} aperto di $\mathbb{C}${} si dice  \textbf{olomorfa} se \`{e} \(\mathbb{C}\)-derivabile in ogni punto di \(U\), ovvero se \(\forall\) \(z_0 \in U\ \exists\){} finito
\begin{displaymath}
\lim_{h \to 0}\frac{f(z_0+h)-f(z_0)}{h}=\frac{\partial f}{\partial z_0}, h\in \mathbb{C}.
\end{displaymath}
\(f\){} \textbf{intera} se olomorfa su \(U=\mathbb{C}\).

\end{document}

However this solution is a little impractical for inline math mode. I suggest to use this trick only for display math mode, and use a contracted extra command when inline. Doing this with \everymath and \everydisplay is unsafe, as mentioned here: \everymath and author color

1
  • You can use the xspace package and then use \def${\ifmmode)\xspace\else(\fi} instead of \def${\ifmmode)\else(\fi}. With this we avoid using {} to add spaces
    – G al Cubo
    Commented Jan 23, 2018 at 2:39

You must log in to answer this question.

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