<<

TUGboat, Volume 38 (2017), No. 1 41

How to use basic 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 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 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 , , , , The default basic color models supplied with stan- , , , . 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 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{}{\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} 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} BurntOrange Example: CadetBlue CarnationPink \definecolor{}{rgb}{0.0,0.5,0.5} 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 tively; that is, they are subtracted (like filters) from LimeGreen Magenta rgb for the range of full (white) {0,0,0,0} to no light (black) {1,1,1,1}. The cmyk (cyan-magenta- Melon MidnightBlue yellow-black) model is a more complex color model NavyBlue that takes four parameters — one value for each of OliveGreen cyan, magenta, yellow, black. The four colors OrangeRed can be “mixed” in any proportion; each parame- ter must be between 0.0 and 1.0 but they need not PineGreen add up to 1.0. The four base colors themselves are ProcessBlue 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: 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 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 } 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 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/ 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. • 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 may not look as nice on the reader’s printer. The base (predefined) set of named colors in • Most color graphs or charts reproduce badly on xcolor is: a printer or copier; therefore, they black blue brown cyan darkgray gray lose their effectiveness. green lightgray magenta • Color effects, if included, should be used mini- orange purple red teal violet mally to enhance clarity only, and to aid in com- white yellow munication of detailed, complex information. Additional color names can be loaded with package • In most professional publications, all special ef- options. fects including color should be used sparingly. The color definition syntax in xcolor is similar • If you are compelled to use colored text to aid to that in color, but with extended syntax allowing the reader, first consider using other “normal” for expressions. One of the commands to assign a text formats such as enumerate, itemize, italics, name to a custom color specification is: bold face; even these formats should be used \definecolor[type]{name}{model-list}{spec-list} sparingly and consistently. Example: • Standard LATEX “documentclass” styles provide \definecolor{red}{rgb/cmyk}{1,0,0/0,1,1,0} automatic (and appropriate) font selection for defines color name red in rgb or cmyk model de- all title, sectioning, and text environments. pending on which model is currently set. Two of the packages related to xcolor: ⋄ Behzad Salimi xcolor-material Defines the 256 colors from Ridgecrest, CA USA the Google Material Color Palette. quadratures (at) gmail dot com xcolor-solarized Defines the 16 colors from https://sites.google.com/site/ Ethan Schoonover’s Solarized palette. quadratures/

How to use basic color models in LATEX