9

I'd like to make all my math blue. So far I only use the $, equation and align environment, so it'd we nice it it worked for those. If it works for others, that'd be even greater.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\everymath{\color{blue}}
\everydisplay{\color{blue}}

\begin{document}
    Let $\vec{v}$ be some vector. A fancy one.

    \begin{align}
        \vec{v} = \vec{a} \\
                &= + \vec{b}
    \end{align}

    \begin{equation}
        \vec{v} = \vec{a} + \vec{b}
    \end{equation}
\end{document}

I get

untitled.tex|14 error| Improper \halign inside $$'s

I know I could just write my own environments but I really would love to just tell it: Make everything blue no matter what.

4
  • 3
    Please tell us whether you use pdfLaTeX, XeLaTeX, or LuaLaTeX to compile your document.
    – Mico
    Jul 14, 2021 at 13:57
  • 1
    @Mico: I don't think that this is relevant in this case as all three end up with the same error message (tested for you)
    – Markus G.
    Jul 14, 2021 at 15:10
  • You can colour the math font(s) (tex.stackexchange.com/questions/201239/…), but requires font-spec or unicode-math, so not a pdflatex solution. You only want specified environments to apply blue text/maths, elsewhere is unchanged, is that correct? Some solution sets will be engine-specific.
    – Cicada
    Jul 14, 2021 at 16:00
  • 1
    @MarkusG. - Sorry about the purpose of my earlier comment not being clear. The point is not that some TeX executables might avoid the error condition generated by \everymath. Rather, it's that XeLaTeX and LuaLaTeX -- more precisely, the fontspec package which runs only under XeLaTeX or LuaLaTeX -- offer a solution that isn't available under pdfLaTeX. To wit, if the unicode-math package (which loads fontspec automatically) is loaded, then the option Color=0000FF while executing \setmathfont will render all inline math and display math material in blue; no need for \everydisplay.
    – Mico
    Jul 14, 2021 at 16:42

2 Answers 2

15

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\everymath{\color{blue}}


\AtBeginEnvironment{equation}{\color{blue}}
\makeatletter
\def\maketag@@@#1{\hbox{\m@th\normalfont\color{blue}#1}}
\makeatother

\begin{document}
    Let $\vec{v}$ be some vector. A fancy one.

    \begin{align}
        \vec{v} = \vec{a} \\
                &= + \vec{b}
    \end{align}

    \begin{equation}
        \vec{v} = \vec{a} + \vec{b}
    \end{equation}
\end{document}
5
  • 1
    +1 but what about \[...\]?
    – campa
    Jul 14, 2021 at 17:02
  • 2
    @campa it wasn't in the question:-) \g@addto@macro\[{\color{blue}} Jul 14, 2021 at 17:10
  • But the inline math isn't blue ... (unless I'm going blind). Jul 14, 2021 at 22:53
  • 2
    @barbarabeeton The $\vec{v}$ is blue in the output. Jul 15, 2021 at 0:53
  • @AzorAhai-him- -- Logically, it should be. I guess I'll have to have my browser checked. (It has been known to misbehave.) Jul 15, 2021 at 1:34
11

If you use either XeLaTeX or LuaLaTeX to compile your document, you may render all inline math and display math material in blue automatically by employing the unicode-math package and setting the option Color=0000FF while executing \setmathfont. E.g.,

\usepackage{unicode-math}
\setmathfont[Color=0000FF]{Latin Modern Math} % set a suitable math font

Here's an MWE (minimum working example) and its output:

enter image description here

\documentclass{article}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}[Color=0000FF]
\begin{document}
Let $\vec{a}$, $\vec{b}$, and $\vec{v}$ denote vectors. Suppose
\begin{equation}\label{eq:new}
     \vec{v} = \vec{a} + \vec{b}
\end{equation} 
\end{document}
3
  • More than once when I had a font-related problem I used LuaLatex. I never experienced any compatibility problem or whatever. So why doesn't everyone simply use LuaLatex? (I am myself guilty of using pdflatex by default as well.) Jul 21, 2021 at 23:43
  • @JohannesLinkels - You raise a very good question. :-) My impression is that a large part of all LaTeX users are taught the bare minimum (and often less than that!) of LaTeX by their college or grad school advisers, who in turn learned LaTeX from their advisers, etc. An econometrician/mathematician friend of mine, while we were chatting about the generally abysmally low levels of LaTeX proficiency of what appears to be a clear majority of mathematicians, once opined, "most mathematicians are neanderthals." That may have been a needless insult to neanderthals...
    – Mico
    Jul 22, 2021 at 3:51
  • @JohannesLinkels - In truth, until about 5 or 6 years ago, using Lua(La)TeX for production work was something best left to the more adventurous spirits. Fortunately, LuaTeX has stabilized since then, and nowadays 99.99% of all alleged bugs in LuaLaTeX are not bugs but user coding errors.
    – Mico
    Jul 22, 2021 at 3:56

You must log in to answer this question.

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