Skip to content

Commit 049739b

Browse files
committed
Added RGB color model. Perhaps more later. (Issue #287.)
1 parent f8e3f35 commit 049739b

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

extensions/TeX/color.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unpacked/extensions/TeX/color.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* MathJax/extensions/TeX/color.js
44
*
55
* Implements LaTeX-compatible \color macro rather than MathJax's
6-
* original (non-standard) version. It includes the rgb, gray, and
7-
* named color models, and the \definecolor macro.
6+
* original (non-standard) version. It includes the rgb, RGB, gray,
7+
* and named color models, and the \definecolor macro.
88
*
99
* ---------------------------------------------------------------------
1010
*
@@ -27,7 +27,7 @@
2727
// The configuration defaults, augmented by the user settings
2828
//
2929
MathJax.Extension["TeX/color"] = {
30-
version: "2.0.1",
30+
version: "2.0.2",
3131

3232
config: MathJax.Hub.CombineConfig("TeX.color",{
3333
padding: "5px",
@@ -116,21 +116,37 @@ MathJax.Extension["TeX/color"] = {
116116
},
117117

118118
/*
119-
* Get an RGB color
119+
* Get an rgb color
120120
*/
121121
get_rgb: function (rgb) {
122122
rgb = rgb.split(/,/); var RGB = "#";
123-
if (rgb.length !== 3) {this.TEX.Error("RGB colors require 3 decimal numbers")}
123+
if (rgb.length !== 3) {this.TEX.Error("rgb colors require 3 decimal numbers")}
124124
for (var i = 0; i < 3; i++) {
125125
if (!rgb[i].match(/^(\d+(\.\d*)?|\.\d+)$/)) {this.TEX.Error("Invalid decimal number")}
126126
var n = parseFloat(rgb[i]);
127-
if (n < 0 || n > 1) {this.TEX.Error("RGB values must be between 0 and 1")}
127+
if (n < 0 || n > 1) {this.TEX.Error("rgb values must be between 0 and 1")}
128128
n = Math.floor(n*255).toString(16); if (n.length < 2) {n = "0"+n}
129129
RGB += n;
130130
}
131131
return RGB;
132132
},
133133

134+
/*
135+
* Get an RGB color
136+
*/
137+
get_RGB: function (rgb) {
138+
rgb = rgb.split(/,/); var RGB = "#";
139+
if (rgb.length !== 3) {this.TEX.Error("RGB colors require 3 numbers")}
140+
for (var i = 0; i < 3; i++) {
141+
if (!rgb[i].match(/^\d+$/)) {this.TEX.Error("Invalid number")}
142+
var n = parseInt(rgb[i]);
143+
if (n > 255) {this.TEX.Error("RGB values must be between 0 and 255")}
144+
n = n.toString(16); if (n.length < 2) {n = "0"+n}
145+
RGB += n;
146+
}
147+
return RGB;
148+
},
149+
134150
/*
135151
* Get a gray-scale value
136152
*/

0 commit comments

Comments
 (0)