|
3 | 3 | * MathJax/extensions/TeX/color.js
|
4 | 4 | *
|
5 | 5 | * Implements LaTeX-compatible \color macro rather than MathJax's original
|
6 |
| - * (non-standard) version. It includes the rgb, gray, and named color |
| 6 | + * (non-standard) version. It includes the rgb, RGB, gray, and named color |
7 | 7 | * models, and the \textcolor, \definecolor, \colorbox, and \fcolorbox
|
8 | 8 | * macros.
|
9 | 9 | *
|
@@ -117,21 +117,37 @@ MathJax.Extension["TeX/color"] = {
|
117 | 117 | },
|
118 | 118 |
|
119 | 119 | /*
|
120 |
| - * Get an RGB color |
| 120 | + * Get an rgb color |
121 | 121 | */
|
122 | 122 | get_rgb: function (rgb) {
|
123 | 123 | rgb = rgb.split(/,/); var RGB = "#";
|
124 |
| - if (rgb.length !== 3) {this.TEX.Error("RGB colors require 3 decimal numbers")} |
| 124 | + if (rgb.length !== 3) {this.TEX.Error("rgb colors require 3 decimal numbers")} |
125 | 125 | for (var i = 0; i < 3; i++) {
|
126 | 126 | if (!rgb[i].match(/^(\d+(\.\d*)?|\.\d+)$/)) {this.TEX.Error("Invalid decimal number")}
|
127 | 127 | var n = parseFloat(rgb[i]);
|
128 |
| - if (n < 0 || n > 1) {this.TEX.Error("RGB values must be between 0 and 1")} |
| 128 | + if (n < 0 || n > 1) {this.TEX.Error("rgb values must be between 0 and 1")} |
129 | 129 | n = Math.floor(n*255).toString(16); if (n.length < 2) {n = "0"+n}
|
130 | 130 | RGB += n;
|
131 | 131 | }
|
132 | 132 | return RGB;
|
133 | 133 | },
|
134 | 134 |
|
| 135 | + /* |
| 136 | + * Get an RGB color |
| 137 | + */ |
| 138 | + get_RGB: function (rgb) { |
| 139 | + rgb = rgb.split(/,/); var RGB = "#"; |
| 140 | + if (rgb.length !== 3) {this.TEX.Error("RGB colors require 3 numbers")} |
| 141 | + for (var i = 0; i < 3; i++) { |
| 142 | + if (!rgb[i].match(/^\d+$/)) {this.TEX.Error("Invalid number")} |
| 143 | + var n = parseInt(rgb[i]); |
| 144 | + if (n > 255) {this.TEX.Error("RGB values must be between 0 and 255")} |
| 145 | + n = n.toString(16); if (n.length < 2) {n = "0"+n} |
| 146 | + RGB += n; |
| 147 | + } |
| 148 | + return RGB; |
| 149 | + }, |
| 150 | + |
135 | 151 | /*
|
136 | 152 | * Get a gray-scale value
|
137 | 153 | */
|
|
0 commit comments