6
$\begingroup$

In Latex, using the following code before \begin{document}, one can define different colours as in the shared images.

    \usepackage{xcolor,color}
    
    \definecolor{lgreen} {RGB}{180,210,100}
    \definecolor{dblue}  {RGB}{20,66,129}
    \definecolor{ddblue} {RGB}{11,36,69}
    \definecolor{lred}   {RGB}{220,0,0}
    \definecolor{nred}   {RGB}{224,0,0}
    \definecolor{norange}{RGB}{230,120,20}
    \definecolor{nyellow}{RGB}{255,221,0}
    \definecolor{ngreen} {RGB}{98,158,31}
    \definecolor{dgreen} {RGB}{78,138,21}
    \definecolor{nblue}  {RGB}{28,130,185}
    \definecolor{jblue}  {RGB}{20,50,100}
    
    
    \definecolor{GreenYellow}       {RGB}{217, 229, 6}      % GreenYellow  Approximate PANTONE 388
    \definecolor{Yellow}            {RGB}{254, 223, 0}      % Yellow  Approximate PANTONE YELLOW
    \definecolor{Goldenrod}         {RGB}{249, 214, 22}     % Goldenrod  Approximate PANTONE 109
    \definecolor{Dandelion}         {RGB}{253, 200, 47}     % Dandelion  Approximate PANTONE 123
    \definecolor{Apricot}           {RGB}{255, 170, 123}    % Apricot  Approximate PANTONE 1565
    \definecolor{Peach}             {RGB}{255, 127, 69}     % Peach  Approximate PANTONE 164
    \definecolor{Melon}             {RGB}{255, 129, 141}    % Melon  Approximate PANTONE 177
    \definecolor{YellowOrange}      {RGB}{240, 171, 0}      % YellowOrange  Approximate PANTONE 130
    \definecolor{Orange}            {RGB}{255, 88, 0}       % Orange  Approximate PANTONE ORANGE-021
    \definecolor{BurntOrange}       {RGB}{199, 98, 43}      % BurntOrange  Approximate PANTONE 388
    \definecolor{Bittersweet}       {RGB}{189, 79, 25}      % Bittersweet  Approximate PANTONE 167
    \definecolor{RedOrange}         {RGB}{222, 56, 49}      % RedOrange  Approximate PANTONE 179
    \definecolor{Mahogany}          {RGB}{152, 50, 34}      % Mahogany  Approximate PANTONE 484
    \definecolor{Maroon}            {RGB}{152, 30, 50}      % Maroon  Approximate PANTONE 201
    \definecolor{BrickRed}          {RGB}{170, 39, 47}      % BrickRed  Approximate PANTONE 1805
    \definecolor{Red}               {RGB}{255, 0, 0}        % Red  Approx PANTONE LUMINOUS VIVID RED
    \definecolor{BrilliantRed}      {RGB}{237, 41, 57}      % Red  VERY-Approx PANTONE RED
    \definecolor{OrangeRed}         {RGB}{231, 58, 0}       % OrangeRed  No PANTONE match (TRIED PANTONE VIVID ORANGE RED)
    \definecolor{RubineRed}         {RGB}{202, 0, 93}       % RubineRed  Approximate PANTONE RUBINE-RED
    \definecolor{WildStrawberry}    {RGB}{203, 0, 68}       % WildStrawberry  Approximate PANTONE 206
    \definecolor{Salmon}            {RGB}{250, 147, 171}    % Salmon  Approximate PANTONE 183
    \definecolor{CarnationPink}     {RGB}{226, 110, 178}    % CarnationPink  Approximate PANTONE 218
    \definecolor{Magenta}           {RGB}{255, 0, 144}      % Magenta  Approximate PANTONE PROCESS-MAGENTA
    \definecolor{VioletRed}         {RGB}{215, 31, 133}     % VioletRed  Approximate PANTONE 219
    \definecolor{Rhodamine}         {RGB}{224, 17, 157}     % Rhodamine  Approximate PANTONE RHODAMINE-RED
    \definecolor{Mulberry} {RGB}{163, 26, 126}  % Mulberry  Approximate PANTONE 241
    \definecolor{RedViolet} {RGB}{161, 0, 107}      % RedViolet  Approximate PANTONE 234
    \definecolor{Fuchsia}   {RGB}{155, 24, 137}     % Fuchsia  Approximate PANTONE 248
    \definecolor{Lavender}  {RGB}{240, 146, 205}    % Lavender  Approximate PANTONE 223
    \definecolor{Thistle}           {RGB}{222, 129, 211}    % Thistle  Approximate PANTONE 245
    \definecolor{Orchid}            {RGB}{201, 102, 205}    % Orchid  Approximate PANTONE 252
    \definecolor{DarkOrchid}        {RGB}{153, 50, 204}     % DarkOrchid  No PANTONE match
    \definecolor{Purple}            {RGB}{182, 52, 187}     % Purple  Approximate PANTONE PURPLE
    \definecolor{Plum}              {RGB}{79, 50, 76}       % Plum  VERY-Approx PANTONE 518
    \definecolor{Violet}            {RGB}{75, 8, 161}       % Violet  Approximate PANTONE VIOLET
    \definecolor{RoyalPurple}       {RGB}{82, 35, 152}      % RoyalPurple  Approximate PANTONE 267
    \definecolor{BlueViolet}        {RGB}{33, 7, 106}       % BlueViolet  Approximate PANTONE 2755
    \definecolor{Periwinkle}        {RGB}{136, 132, 213}    % Periwinkle  Approximate PANTONE 2715
    \definecolor{CadetBlue}         {RGB}{95, 158, 160}     % CadetBlue  Approximate PANTONE (534+535)/2, Could not find get on my own so used PANTONE-CADET BLUE
    \definecolor{CornflowerBlue}    {RGB}{99, 177, 229}     % CornflowerBlue  Approximate PANTONE 292
    \definecolor{MidnightBlue}      {RGB}{0, 65, 101}       % MidnightBlue  Approximate PANTONE 302
    \definecolor{NavyBlue}          {RGB}{0, 70, 173}       % NavyBlue  Approximate PANTONE 293
    \definecolor{RoyalBlue}         {RGB}{0, 35, 102}       % RoyalBlue  No PANTONE match
    \definecolor{Blue}              {RGB}{0, 24, 168}       % Blue  Approximate PANTONE BLUE-072
    \definecolor{Cerulean}          {RGB}{0, 122, 201}      % Cerulean  Approximate PANTONE 3005
    \definecolor{Cyan}              {RGB}{0, 159, 218}      % Cyan  Approximate PANTONE PROCESS-CYAN
    \definecolor{ProcessBlue}       {RGB}{0, 136, 206}      % ProcessBlue  Approximate PANTONE PROCESS-BLUE
    \definecolor{SkyBlue}           {RGB}{91, 198, 232}     % SkyBlue  Approximate PANTONE 2985
    
    \definecolor{Turquoise}         {RGB}{0, 255, 239}      % Turquoise  Approximate PANTONE (312+313)/2, Could not find get on my own so used PANTONE-TURQUOISE
    
    \definecolor{TealBlue}          {RGB}{0, 124, 146}      % TealBlue  Approximate PANTONE 3145
    \definecolor{Aquamarine}        {RGB}{0, 148, 179}      % Aquamarine  Approximate PANTONE 3135
    \definecolor{BlueGreen}         {RGB}{0, 154, 166}      % BlueGreen  Approximate PANTONE 320
    \definecolor{Emerald}           {RGB}{80, 200, 120}     % Emerald  No PANTONE match
    \definecolor{JungleGreen}       {RGB}{0, 115, 99}       % JungleGreen  Approximate PANTONE 328
    \definecolor{SeaGreen}          {RGB}{0, 176, 146}      % SeaGreen  Approximate PANTONE 3268
    \definecolor{Green}             {RGB}{0, 173, 131}      % Green  VERY-Approx PANTONE GREEN
    \definecolor{ForestGreen}       {RGB}{0, 105, 60}       % ForestGreen  Approximate PANTONE 349
    \definecolor{PineGreen}         {RGB}{0, 98, 101}       % PineGreen  Approximate PANTONE 323
    \definecolor{LimeGreen}         {RGB}{50, 205, 50}      % LimeGreen  No PANTONE match
    \definecolor{YellowGreen}       {RGB}{146, 212, 0}      % YellowGreen  Approximate PANTONE 375
    \definecolor{SpringGreen}       {RGB}{201, 221, 3}      % SpringGreen  Approximate PANTONE 381
    \definecolor{OliveGreen}        {RGB}{135, 136, 0}      % OliveGreen  Approximate PANTONE 582
    \definecolor{RawSienna}         {RGB}{149, 82, 20}      % RawSienna  Approximate PANTONE 154
    \definecolor{Sepia}             {RGB}{98, 60, 27}       % Sepia  Approximate PANTONE 161
    \definecolor{Brown}             {RGB}{134, 67, 30}      % Brown  Approximate PANTONE 1615
    \definecolor{Tan}               {RGB}{210, 180, 140}    % Tan  No PANTONE match
    \definecolor{Gray}              {RGB}{139, 141, 142}    % Gray  Approximate PANTONE COOL-GRAY-8
    
    \definecolor{Black}             {RGB}{30, 30, 30}       % Black  Approximate PANTONE PROCESS-BLACK
    \definecolor{White}             {RGB}{255, 255, 255}    % White  No PANTONE match

enter image description here enter image description here

One way to get these colours in Mathematica is by using DominantColors[]

enter image description here

As one can see, there are $20$ colours in the image, but Mathematica only extracts $12$ from it. Therefore, it is ineffective. Besides that, it is cumbersome and hectic to get each colour with multiple screenshots.

Is there any better way to get these colours in Mathematica?

RGBColor[] is an alternative, but how do I get the exact number for RGB? Copying the Latex number ends up in a white colour box.

(LimeGreen) RGBColor[50, 205, 50]

$\endgroup$
6
  • $\begingroup$ Just out of curiosity, why not use ColorSlider instead? You can manually pick from the colour wheel there. $\endgroup$
    – codebpr
    Commented Mar 4 at 17:20
  • $\begingroup$ This seems related too. $\endgroup$
    – codebpr
    Commented Mar 4 at 17:31
  • 6
    $\begingroup$ The arguments to RGBColor must be in the interval {0, 1}. convert[r_, g_, b_] := RGBColor @@ ({r, g, b}/255.); convert[50, 205, 50] $\endgroup$
    – Bob Hanlon
    Commented Mar 4 at 17:36
  • $\begingroup$ @BobHanlon, This is magic. Thank you so much. Just out of curiosity, why $255$ ?? Is that because in latex {RGB} numbers are between $0$ to $255$ which must be in analogous with Mathematica RGBColor in the interval {0,1}? $\endgroup$
    – user444
    Commented Mar 4 at 17:57
  • 1
    $\begingroup$ Yes, they are just rescaled. $\endgroup$
    – Bob Hanlon
    Commented Mar 4 at 18:01

3 Answers 3

8
$\begingroup$

In RGBColor you need to use values in the range $[0,1]$ instead of $[0,255]$. So just divide the numbers you have by 255, that's all.

You can get many nice named colours, some identical to the classic dvips colours, using ColorData["Legacy"]. Try these:

ColorData["Legacy", "ColorRules"]
ColorData["Legacy", "Panel"]

enter image description here

ColorData["Legacy"]["RoyalBlue"]
$\endgroup$
5
$\begingroup$

It's not as cumbersome as you think. The hex-codes of all popular colours are easily available on the net, for example here.

Now, you just need to use HexToColor resource function of Mathematica.

As an illustration, let us say you want PineGreen whose hex code is "#01796f", all you need to do is,

ResourceFunction["HexToColor"]["#01796f"]

which gives you the desired colour, which you can easily use further in your work.

Or thanks to @Syed, even simpler:

RGBColor["#01796f"]

Or even direct HTML names:

RGBColor["IndianRed"]

Edit: Clarifying doubt of OP

The reason why there is a difference between RGB option in $\LaTeX$ and the default hex-codes is basically because of the colour models used in the xcolor package. If you look at it's documentation, you will find mention of 12 colour models:

color-models

It is clearly visible that the parameter range for rgb color model is [0,1] and for RGB is {0,255}. So while defining your colours if you use the rgb model, it will be basically the same as the one you use in MMA (even cmyk and hsb color models are available in MMA). You can even play around with different colours based on names mentioned in $Page-38$ of the package documentation like dvipsnames, svgnames or even the grand x11names.

The hexcodes for these too are easily available, as an example for x11names:

x-11

Edit2

The decimal code for PineGreen is actually {RGB}{1, 121, 111}. To verify:

RGBColor["#01796f"] // InputForm

(*RGBColor[0.00392156862745098, 0.4745098039215686, 0.43529411764705883]*)

convert[1, 121, 111] // InputForm

(*RGBColor[0.00392156862745098, 0.4745098039215686, 0.43529411764705883]*)
$\endgroup$
3
  • 1
    $\begingroup$ Try: RGBColor["#01796f"] $\endgroup$
    – Syed
    Commented Mar 4 at 18:59
  • $\begingroup$ @Syed, ah I forgot that even hex codes work in RGBColor too. Thanks for pointing that out! $\endgroup$
    – codebpr
    Commented Mar 4 at 19:02
  • $\begingroup$ ResourceFunction["HexToColor"]["#01796f"] // InputForm and RGBColor["#01796f"]// InputForm are same but they are different from convert[0, 98, 101] // InputForm. Why is that? $\endgroup$
    – user444
    Commented Mar 4 at 19:03
2
$\begingroup$

Based on @BobHanlon's suggestion(comment), I tried to make a database of colours.

Latex RGB colour codes:

 d = {{180, 210, 100}, {20, 66, 129}, {11, 36, 69}, {220, 0, 0}, {224, 
        0, 0}, {230, 120, 20}, {255, 221, 0}, {98, 158, 31}, {78, 138, 
        21}, {28, 130, 185}, {20, 50, 100}, {217, 229, 6} , {254, 223, 
        0}, {249, 214, 22}, {253, 200, 47}, {255, 170, 123}, {255, 127, 
        69} , {255, 129, 141} , {240, 171, 0}, {255, 88, 0}, {199, 98, 
        43} , {189, 79, 25}, {222, 56, 49} , {152, 50, 34}, {152, 30, 
        50}, {170, 39, 47}, {255, 0, 0} , {237, 41, 57} , {231, 58, 
        0} , {202, 0, 93} , {203, 0, 68}, {250, 147, 171} , {226, 110, 
        178}, {255, 0, 144} , {215, 31, 133}, {224, 17, 157} , {163, 26, 
        126} , {161, 0, 107}, {155, 24, 137} , {240, 146, 205} , {222, 
        129, 211}, {201, 102, 205}, {153, 50, 204}, {182, 52, 187} , {79, 
        50, 76} , {75, 8, 161} , {82, 35, 152}, {33, 7, 106}, {136, 132, 
        213} , {95, 158, 160} , {99, 177, 229}, {0, 65, 101}, {0, 70, 
        173}, {0, 35, 102}, {0, 24, 168} , {0, 122, 201}, {0, 159, 
        218}, {0, 136, 206} , {91, 198, 232} , {0, 255, 239} , {0, 124, 
        146}, {0, 148, 179}, {0, 154, 166}, {80, 200, 120} , {0, 115, 
        99} , {0, 176, 146} , {0, 173, 131} , {0, 105, 60}, {0, 98, 
        101}, {50, 205, 50}, {146, 212, 0}, {201, 221, 3} , {135, 136, 
        0}, {149, 82, 20}, {98, 60, 27} , {134, 67, 30}, {210, 180, 
        140}, {139, 141, 142} , {30, 30, 30}, {255, 255, 255}};

To covert Latex values to Mathematica:

convert[r_, g_, b_] := RGBColor @@ ({r, g, b}/255.);

{lgreen, dblue, ddblue, lred, nred, norange, nyellow, ngreen, dgreen, 
  nblue, jblue, GreenYellow, Yellow1, Goldenrod, Dandelion, Apricot, 
  Peach, Melon, YellowOrange, Orange1, BurntOrange, Bittersweet, 
  RedOrange, Mahogany, Maroon, BrickRed, Red1, BrilliantRed, 
  OrangeRed, RubineRed, WildStrawberry, Salmon, CarnationPink, 
  Magenta1, VioletRed, Rhodamine, Mulberry, RedViolet, Fuchsia, 
  Lavender, Thistle, Orchid, DarkOrchid, Purple1, Plum, Violet, 
  RoyalPurple, BlueViolet, Periwinkle, CadetBlue, CornflowerBlue, 
  MidnightBlue, NavyBlue, RoyalBlue, Blue1, Cerulean, Cyan1, 
  ProcessBlue, SkyBlue, Turquoise, TealBlue, Aquamarine, BlueGreen, 
  Emerald, JungleGreen, SeaGreen, Green1, ForestGreen, PineGreen, 
  LimeGreen, YellowGreen, SpringGreen, OliveGreen, RawSienna, Sepia, 
  Brown1, Tan1, Gray1, Black1, White1} = 
 Table[convert[d[[n]][[1]], d[[n]][[2]], d[[n]][[3]]], {n, 1, 
   Length[d]}]

enter image description here

$\endgroup$
1
  • 7
    $\begingroup$ your Table[convert[d[[n]][[1]], d[[n]][[2]], d[[n]][[3]]], {n, 1, Length[d]}] can be shortened to convert @@@ d $\endgroup$
    – Bob Hanlon
    Commented Mar 4 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.