Tugboat, Volume 38 (2017), No. 1 41 How to Use Basic Color Models In
Total Page:16
File Type:pdf, Size:1020Kb
TUGboat, Volume 38 (2017), No. 1 41 How to use basic color models in LATEX where model is gray, rgb or cmyk and specifi- cation is described in §§ 4, 6, 7. Behzad Salimi 2. Global definition: use the \definecolor com- Abstract mand: This article provides a quick reference guide for new \definecolor{color1 }{rgb}{n1,n2,n3} or experienced users on how to use the five basic \definecolor{color2 }{cmyk}{n1,n2,n3,n4} LATEX color models. We describe the color packages, then use these custom colors with the syntax the primary syntax, and examples of how to include above: colored text (or objects) in a document. In this ar- {\color{color1 }text in color1} ticle, we do not attempt to include a comprehensive \textcolor{color2 }{text in color2} coverage of all the options and features in the basic See examples in the next section. color models; instead, the intent is to help the in- terested authors start learning (and using) the color 3 Basic color model syntax in the shortest time possible. The predefined colors for the basic color model are used without any model specification. The eight pre- 1 Basic color models defined color names are black, blue, cyan, green, The default basic color models supplied with stan- magenta, red, white, yellow. Syntax: dard LATEX installation provide an extensive range \textcolor{red}{\textbf{Sample text in red}} of colors that are easy to use for colored text or re- Sample text in red verse color highlighted text. {\color{cyan}\textbf{Sample text in cyan}} The five standard color models in LATEX are: Sample text in cyan § model color names must load Another example: 3 basic predefined a or b {\color{magenta} color changes 4 gray gray a or b \textcolor{blue}{can be nested 5 usenames predefined b \textcolor{red}{in all} } {\color{green}color models.}} 6 RGB arbitrary a or b 7 CMYK arbitrary a or b color changes can be nested in all color models. a: \usepackage{color} 4 Gray scale model b: \usepackage[usenames]{color} The gray scale model is a variable scale gray and it In the basic and usenames color models, colors takes only one number from 0=black to 1=white (as and their corresponding names are predefined, so they appear on white paper). only those predefined color names are available. In The base color name in this package is fixed as the rgb and cmyk models, a custom color of user- gray; however, various shades can be defined using specified name with infinite variation of color hue the base name gray. For example: can be specified (mixed). In the gray model, shades \newcommand{\gry}[1]{\textcolor[gray]{0.70}{#1}} of gray are specified. \definecolor{gray1}{gray}{0.50} 2 Syntax for colored text Syntax: The syntax for using colored text in all color models \gry{Sample text in 0.75 gray} above is one of two equivalent forms: Sample text in 0.75 gray \textcolor{gray1}{Next text in 0.50 gray} 1. {\color{name}text in color} Next text in 0.50 gray 2. \textcolor{name}{text in color} where name is either a predefined or user-specified 5 ‘usenames’ color model color name in one of the color models. The \color In the LATEX usenames color model, there are 68 pre- command may make extra vertical space in some defined color names; see Table 1. This color package environments such as tabular; in such cases, use must be loaded with the ‘usenames’ option: \textcolor command. \usepackage[usenames]{color} To specify a user-defined color in gray, rgb or Syntax: cmyk color models, the syntax may be a local or \textcolor{BrickRed}{text color in BrickRed} global definition: text color in BrickRed 1. Local definition: {\color{RoyalPurple} text in RoyalPurple} \textcolor[model]{specification}{text} text in RoyalPurple How to use basic color models in LATEX 42 TUGboat, Volume 38 (2017), No. 1 \colorbox{Fuchsia}{\textcolor{white}{% colors can be “mixed” in any proportion; each pa- colorbox Fuchsia}} rameter must be between 0.0 and 1.0 but they need colorbox Fuchsia not add to 1.0. The three base colors themselves You can create an alias for a predefined color name, can be selected with red={1,0,0}, green={0,1,0}, for example: blue={0,0,1}. \definecolor{ogrn}{named}{OliveGreen} The syntax is \textcolor{ogrn}{ogrn is OliveGreen} 1. Define a color locally, usually for one-time use: ogrn is OliveGreen {\color[rgb]{n1,n2,n3}text} \textcolor[rgb]{n1,n2,n3}{text} Table 1: The 68 standard colors known to dvips Example: (not pdfLATEX). {\color[rgb]{0.8,0.1,0.8} Sample rgb color} Apricot Aquamarine Sample rgb color Bittersweet Black 2. Define a new color name: Blue BlueGreen \definecolor{color1}{rgb}{n1,n2,n3} BlueViolet BrickRed {\color{color1}text} Brown BurntOrange Example: CadetBlue CarnationPink \definecolor{teal}{rgb}{0.0,0.5,0.5} Cerulean CornflowerBlue \textcolor{teal}{Sample teal in rgb model} Cyan Dandelion Sample teal in rgb model DarkOrchid Emerald ForestGreen Fuchsia 7 CMYK color model Goldenrod Gray The subtractive primaries cyan, magenta, and yellow Green GreenYellow are the complements of red, green, and blue, respec- JungleGreen Lavender tively; that is, they are subtracted (like filters) from LimeGreen Magenta rgb for the range of full light (white) {0,0,0,0} to no Mahogany Maroon light (black) {1,1,1,1}. The cmyk (cyan-magenta- Melon MidnightBlue yellow-black) model is a more complex color model Mulberry NavyBlue that takes four parameters — one value for each of OliveGreen Orange cyan, magenta, yellow, black. The four colors OrangeRed Orchid can be “mixed” in any proportion; each parame- Peach Periwinkle ter must be between 0.0 and 1.0 but they need not PineGreen Plum add up to 1.0. The four base colors themselves are ProcessBlue Purple selected with cyan={1,0,0,0}, magenta={0,1,0,0}, RawSienna Red yellow={0,0,1,0}, black={0,0,0,1}. RedOrange RedViolet The syntax is analogous to that in §6: Rhodamine RoyalBlue RoyalPurple RubineRed 1. Define a color locally, usually for one-time use: Salmon SeaGreen {\color[cmyk]{n1,n2,n3,n3} text } Sepia SkyBlue \textcolor[cmyk]{n1,n2,n3,n3}{text} SpringGreen Tan Example: TealBlue Thistle {\color[cmyk]{0.2,0.7,0.1,0.2} Turquoise Violet Sample cmyk text} VioletRed White Sample cmyk text WildStrawberry Yellow 2. Define a new color name: YellowGreen YellowOrange \definecolor{clr1}{cmyk}{n1,n2,n3,n4} {\color{clr1}text} Example: 6 RGB color model \definecolor{brk}{cmyk}{0.2,0.7,0.3,0.3} In the rgb (red-green-blue) color model, the pri- \textcolor{brk}{Sample cmyk color model} maries are additive; that is, the contribution of each Sample cmyk color model base color is added to obtain the range from black (no light) {0,0,0} to white (full light) {1,1,1}. The 8 Advanced, specialized color models rgb color model takes three parameters — one value The basic color models mentioned above generally for each of the red, green, blue colors. The three suffice for most basic (and some complicated) color Behzad Salimi TUGboat, Volume 38 (2017), No. 1 43 applications in text or text objects. If you need (or Even a brief discussion of xcolor’s capabilities is want) to use a more specialized color feature not beyond the scope of this article, so we refer the in- easily done in basic color models, you can browse terested reader to the full xcolor documentation. the description of the color packages on the CTAN My favorite graphics and plotting package to page http://ctan.org/topic/colour which lists use in LATEX, pstricks, loads the xcolor package over 40 different packages for special applications; automatically. Need we say more? some of these applications extend the basic models, 9 Concluding remarks and suggestions some introduce new capabilities. Perhaps the most versatile and advanced pack- The command \pagecolor changes the background age based on the LATEX basic color model is the color of the entire page until another \pagecolor xcolor package, which extends the capabilities of command is seen. Use \nopagecolor to change the color with a variety of shades, tones, tints, and background color back to normal. There are a num- arbitrary mixes of colors, plus additional features. ber of additional color packages available to color Among the many capabilities of xcolor are: specific environments or create special effects. Color, when used sparingly and effectively, can • arbitrary tints of predefined (custom) colors make a significant impression on the reader (or con- • complete tools for transformation between eight sumer) in technical publications (or advertisements). color models However, it is counterproductive if used improperly • complement color specification (−red=not red) or excessively. The only exception is perhaps color • color by wavelength used for “art”. While it is tempting (and fun) to use a multi- • define color series tude of colors in a paper or document, it may be • alternating row colors in tables wise to bear in mind the following facts and ideas: • global/local color definitions (to save memory) • Ask yourself, is it necessary to use color? • invoke color specification within pstricks op- • The appearance of color is different on a moni- tions, e.g., tor vs. paper, on different monitors and printers, \psset{linecolor=[rgb]{0.3,0.5,0.7}} and to different or color-impaired viewers. • Pastel colors just never look nice on a white To load the xcolor package, you must include in background. your document: \usepackage[options]{xcolor} • What looks nice on the author’s printer may not look as nice on the reader’s printer.