MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

MathJaX Colors Does Not Match HTML Colors / MathJaX 2 Colors

Open RoyiAvital opened this issue 2 years ago • 2 comments

Issue Summary

I am using \color to colorize my text.
I found out that:

  1. \color{Cyan} and \color{Magenta} doesn't match MathJaX v2 results.
  2. \color{Cyan} and \color{Magenta} doesn't match HTML results.

Steps to Reproduce:

Render the following on MathJaX 3.2. with the color package enabled:

$$\begin{align*}
\color{Cyan} f \left( \alpha x + \beta y \right) & \color{Cyan} = \alpha f \left( x \right) + \beta f \left( y \right) \\
\color{Magenta} f \left( \mathcal{S} x  \right) & \color{Magenta} = \mathcal{S} f \left( x \right), \; \mathcal{S}: \text{Shift Operator}
\end{align*}$$

The output will be (From the official demo):

image

The output of MathJaX v2 (Rendered by Math Stack Exchange):

image

One could see the colors are different.
The colors of V2 matches the HTML colors.

Technical details:

  • MathJax Version: 3.2
  • Client OS: Windows 10.
  • Browser: Firefox 118.0.1.

The configuration is as in your demo (This is what I used above).

Remark: By the way, the colors of V3 are very pleasant, I could not retrieve their values, could you share?

RoyiAvital avatar Oct 02 '23 17:10 RoyiAvital

\color{Cyan} and \color{Magenta} doesn't match MathJaX v2 results.

That is correct. The v3 \color command is based on the LaTeX color package (though it is a limited subset of that), not the non-standard \color macro of v2. The v2 command just passed the color name on to the color option of the element's style attribute, whereas the v3 command uses a color model (e.g., RGB, rgb, named, etc.) to select the color and how it is defined.

\color{Cyan} and \color{Magenta} doesn't match HTML results.

That is correct. the v3 \color macro uses the dvips color names and their associated color values so that they are more consistent with actual LaTeX.

If you are looking to have the v2 behavior, there are several ways to do that.

First, the color names for the v3 \color macro are case sensitive, and if you use a name that is not defined, it will pass the name on directly to the color property of the text's style attribute. So you can use

\color{cyan} some text

to get the HTML cyan color for the text, since cyan is not a defined color name.

Another possibility is to note that the v2 \color macro is available in the colorv2 package, which you can load manual either by adding it to your MathJax configuration, or using \require{colorv2} in the page where you need it (but then you need to put the text to be colored in braces, since the v2 command takes the text as an argument). See the documentation for more details, and for links to how to configure MathJax to load one or the other of these, and how to switch the default \color package to load via the autoload feature.

Finally, note that you can use \definecolor to define a new color name, or redefine an existing one. So you could do

\definecolor{Cyan}{named}{cyan}

or

\definecolor{Cyan}{named}{#0FF}

to redefine the names color Cyan to be the HTML cyan color.

By the way, the colors of V3 are very pleasant, I could not retrieve their values, could you share?

The v3 named colors are defined in ts/input/tex/color/ColorConstants.ts.

dpvc avatar Oct 02 '23 18:10 dpvc

@dpvc , Appreciate the informative answer. It makes sense.

I think it should appear on the color package page for v3.

RoyiAvital avatar Oct 02 '23 19:10 RoyiAvital