1

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.

4

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

  • 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 Jan 23 '18 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.