4

TLDR; How does one efficiently apply color on every line of every array to override the color by \everymath? i.e from

enter image description here

to

enter image description here

(A compilable example of this is at the bottom)

Is there a way to efficiently apply \color{black} on every line for all arrays (rather than doing it line-by-line)?


I am a big fan of colors and I would like to color up all my inline maths to make the text more readable:

e.g.

But I would like the color for display maths to remain black.

After some googling, I found Stefan's solution, which uses \everymath and \everydisplay from the everysel package. However, there is a known problem with \everydisplay: it does not work with some maths environments in amsmath. To get around it, he suggested redefining displayed math, and I found the following code snippet in OP's comments to his answer:

\let\originaldisplaystyle\displaystyle \renewcommand\displaystyle{\color{black}\originaldisplaystyle}
\let\oldeq\equation \def\equation{\oldeq\color{black}} 

So I tried using them with \everymath, and they are working pretty well, except that the colors in array & cases are not overridden, and I get something like this: enter image description here

enter image description here

I tried redefining cases like this:

 \let\oldcase\cases \def\cases{\oldcase\color{black}}

but it only overrides the color of the first symbol:

enter image description here

Here is the latex for the equation above:

\begin{equation}\label{phi}
    \phi(\delta,w)=  
\begin{cases}
   1 & \text{if } \;  \quad  (a \in div_1 \land b \in div_2)  \Leftrightarrow div_1 = div_2 \\
    0 & \text{if } \;  \quad  (a \in div_1 \land b \in div_2)  \Leftrightarrow div_1 \not= div_2  \\
\end{cases} \text{ where }  \begin{aligned} \renewcommand\arraystretch{1.25}\begin{array}[t]{|@{\hskip0.6em}l} \delta =\{div_1, div_2\} \\ w = \{a,b\}
\end{array} \end{aligned}
\end{equation}

On the other hand, I get Error: Illegal Character in array tag while trying to redefine array by \let\olda\array \def\array{\olda\color{black}}.

However, I am able to change one line of the array by putting \color{black} at the start of the line:

enter image description here

Is there a way to efficiently apply \color{black} on every line for all arrays (rather than doing it line-by-line)? How do I do the same for cases as well?


Here is a compilable example:

\documentclass[11pt, oneside]{article}
\usepackage{geometry}
\geometry{letterpaper}                                      
\usepackage{graphicx}                               
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{mathtools}


\usepackage{xcolor}
\definecolor{myColor}{HTML}{E93F3C}

\usepackage{everysel}

\everymath{\color{myColor}}
\let\originaldisplaystyle\displaystyle \renewcommand\displaystyle{\color{black}\originaldisplaystyle}
\let\oldeq\equation \def\equation{\oldeq\color{black}}

\begin{document}


A  \textit{div point set} is any order-pair $(P,\Theta_P)$ satisfying
\begin{alignat}{2}
  \label{def1_1} 
  &\mathrlap{\lvert\Theta_P\rvert = \binom{\lvert P\rvert}{2} \land P \not= \varnothing} \\[1.5ex] 
  \label{def1_2}
  & \forall D_n \in \Theta_P & \quad & \begin{aligned}[t] \renewcommand\arraystretch{1.25}\begin{array}[t]{|@{\hskip0.6em}l} \color{black}
  (d_n,\delta_n) \mkern-2mu\coloneqq D_n \\
  \lvert d_n\rvert =2\\
  d_n \in \mathcal{P}(P)\\
  \lvert\delta_n\rvert = 2\\
  \bigcup \delta_n = P \setminus d_n \\
  \bigcap \delta_n = \varnothing
  \end{array}
  \end{aligned}\\[1.5ex]
  \label{def1_3}
    & \forall D_n, D_m \in \Theta_P & \quad & \begin{aligned}[t] \renewcommand\arraystretch{1.25}\begin{array}[t]{|@{\hskip0.6em}l}
  (d_n,\delta_n) \mkern-2mu\coloneqq D_n \\
  (d_m,\delta_m) \coloneqq D_m\\
  d_n= d_m \Leftrightarrow D_n=D_m
  \end{array}
  \end{aligned}
\end{alignat}

\begin{equation}\label{phi}
    \phi(\delta,w)=  
\begin{cases}
   1 & \text{if } \;  \quad  (a \in div_1 \land b \in div_2)  \Leftrightarrow div_1 = div_2 \\
    0 & \text{if } \;  \quad  (a \in div_1 \land b \in div_2)  \Leftrightarrow div_1 \not= div_2  \\
\end{cases} \text{ where }  \begin{aligned} \renewcommand\arraystretch{1.25}\begin{array}[t]{|@{\hskip0.6em}l} \delta =\{div_1, div_2\} \\ w = \{a,b\}
\end{array} \end{aligned}
\end{equation}

\end{document}
2
  • A complete compilable example would be better.
    – Manuel
    Sep 19, 2015 at 11:20
  • @Manuel alright, I have updated my answer regarding that. Sep 19, 2015 at 11:36

1 Answer 1

3

Remember that a compilable example is much better. You give a lot of information, but still, we can't compile anything to help you.

What about restoring \everymath{} any time you use in certain environment

\everymath{\color{red}} % May be it's more secure \everymath{\color{red}\everymath{}}

\usepackage{etoolbox}
\AtBeginEnvironment{alignat}{\everymath{}}
\AtBeginEnvironment{equation}{\everymath{}}
% etc.
1
  • Thanks! You solution works pretty nicely! \everymath{\color{red} \everymath{} } would have red not to be applied to content in array, while \AtBeginEnvironment{equation}{\everymath{}} would have the red not to be applied to content in equation! Sep 19, 2015 at 14:18

You must log in to answer this question.

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