Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color in MathJax

Tags:

css

mathjax

I want to display questions on my blog in red in color and answers in blue in color. In questions and answers I am using MathJax 2 to render MathML. I am controlling the coloring of MathJax using CSS like this.

h3, h2, h4, h5
{
    text-align: left;
    font-weight: bold;
    font-family: Verdana;
}

.question
{
    text-align: left;
    color: Red;

}

.centerit
{
    color: Blue;
    text-align: center;
}

that works perfectly fine in IE, but in Firefox it always displays the MathJax in black color. Is there any workaround to resolve this issue?.

like image 878
user288645 Avatar asked Jun 19 '12 07:06

user288645


People also ask

Is MathJax the same as LaTeX?

MathJax can display mathematical notation written in LaTeX or MathML markup. Because MathJax is meant only for math display, whereas LaTeX is a document layout language, MathJax only supports the subset of LaTeX used to describe mathematical notation.

Is KaTeX better than MathJax?

KaTeX is purely about TeX/LaTeX input and HTML output, whereas MathJax also processes MathML and AsciiMath (two other math formats), and produces output not just in HTML but also SVG and MathML.

What is MathJax used for?

MathJax is a javascript display engine for rendering \TeX or MathML-coded mathematics in browsers without requiring font installation or browser plug-ins. Any modern browser with javascript enabled will be MathJax-ready.

How do you write equations in MathJax?

Inline MathJaxTo start a formula you use either a dollar sign $ or you can use a slash an an open parentheses "/(". To end the inline math, you have another dollar sign or a back slash and a closing parentheses. Enclosing in double dollar signs put the math on its own line.


1 Answers

If you want to color different parts of an equation different colors (e.g. if you wanted to color-code variables), use \textcolor command instead of \color to avoid spacing issues.

See the difference:

Using \textcolor (preferred):

<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

$$
y = \textcolor{red}{\sin} x
$$

Using \color (makes for incorrect spacing):

<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

$$
y = \color{red}{\sin} x
$$

Colorized MathJax equations for improved readability demo: trigids.com.

like image 170
Nikita Zdvijkov Avatar answered Sep 18 '22 19:09

Nikita Zdvijkov