Do we have any AMS TeX or LaTeX syntax in Math-mode for background color that ALSO works in MathJax?

191 views
Skip to first unread message

saf....@gmail.com

unread,
Nov 28, 2012, 10:51:16 PM11/28/12
to mathja...@googlegroups.com
For instance in MathJax, for the font colors, the color extension (color.js) changes the \color command to be compatible with the LaTeX implementation, and also defines \colorbox, \fcolorbox, and \DefineColor, as in the LaTeX color package.

I know that in MathJax, one can use \bbox[options]{math}, \class{name}{math} and \style{css}{math} etc. to highlight a math expression with a background color. But these syntaxes are clearly HTML specific and hence won’t work in pure AMS-TeX/LateX.

Thanks..Saf

saf....@gmail.com

unread,
Dec 2, 2012, 10:55:22 PM12/2/12
to mathja...@googlegroups.com, saf....@gmail.com
I was using, for example, \[\colorbox{yellow}{x^2)}\] to highlight “x-squared” and it was displaying x^2 as a plain text with yellow background. After doing some searching, I noticed that I needed to enclose the math expression in the above command with inline TeX delimiters such as $...$ or \(…\) etc. For instance, \[\colorbox{yellow}{\(x^2\)}\]would highlight x-squared in yellow in math-mode.

Hence, I've concluded that Mathjax’s \colorbox command is compatible with LaTeX implementation, and can be used to highlight (with background color) an expression in math-mode. Please feel free to suggest if my conclusion needs a correction.

Thank..Saf

Davide Cervone

unread,
Dec 18, 2012, 7:46:03 PM12/18/12
to mathja...@googlegroups.com
Your conclusion is correct. You can make things easier, perhaps, by
defining your own macro, such as

\newcommand{\colormath}[2]{\colorbox{#1}{\(#2\)}}

so that you can use

\colormath{yellow}{x^2}

and not have to worry about the delimiters in the second argument.
You can include this definition in your configuration by adding

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
Macros: {
colormath: ["\\colorbox{#1}{\\(#2\\)}",2]
}
}
});
</script>

in your page just before the script that loads MathJax.js itself.

Hope that helps.

Davide


On Dec 2, 2012, at 10:55 PM, <saf....@gmail.com>

saf....@gmail.com

unread,
Jan 6, 2013, 4:44:12 PM1/6/13
to mathja...@googlegroups.com
Davide,

Thank you for confirming. I also like your suggestion of defining a custom macro for highlighting math in color. However, in most cases, I will not have a control over user input, so I'll let the user use the original AMS-LaTeX command (also supported by MathJax) for highlighting math - i.e.,  \[\colorbox{colorName}{\(math\)}\]

-Saf
Reply all
Reply to author
Forward
0 new messages