#!/usr/bin/perl -w ## This perl script converts the X11 rgb.txt file into latex commands ## suitable for use with the \color command from pstricks. Make sure ## that the value of $rgbfile is correct and run the script. It takes ## no arguments and writes out rgb.tex, which is to be \input-ed in ## your latex document, and colors.tex, which is a latex documents ## using rgb.tex and demonstarting each color defined. Don't forget ## to put \usepackage{pstricks, pstcol} in the preamble of your ## document. $rgbfile = '/usr/X11R6/lib/X11/rgb.txt'; $styfile = 'rgb.tex'; $texfile = 'colors.tex'; open(RGB, $rgbfile) || die "could not find $rgbfile\n"; open(STY, ">".$styfile) || die "could not find $styfile for writing\n"; open(TEX, ">".$texfile) || die "could not find $styfile for writing\n"; # headers print TEX "\\documentclass{article}\n", "\\usepackage{pstricks, pstcol}\n", "\\begin{document}\n\n", "\\twocolumn\n\n", "\\input{rgb.tex}\n\n"; print STY ' %% rgb.tex %% this file defines the X11 rgb color names for use with pstricks %% put \usepackage{pstricks, pstcol} in the preamble of your document %% the put \input{rgb.tex} in the body of your document. %% Color in pstricks works like a switch. If you enter %% The text will become \color{red}red. %% Then all text after the \color command will printed in red in the %% postscript file. You can restrict the range of the red text in this %% manner %% One {\color{red}some text} will be red. %% The color will NOT show up in the dvi file, only in the .ps file! %% %% this file was created by rgb2tex.pl %% rgb2tex.pl is by Bruce Ravel %% -------------------------------------------------------------------------- '; while () { # convert rgb.tex next if (/^!/) ; next if (/^[ \t]*$/) ; chomp; @line = split; next if ($#line >= 4); # only keep colors with one-word names $line[3] =~ tr/[A-Z]/[a-z]/; # canonicalize to lower case $key = $line[0] . $line[1] . $line[2]; next if ($name{$key}); # no repeats! $name{$key} = $line[3]; $r = $line[0]/255.0; # the rgb values to 2 sig figs $g = $line[1]/255.0; $b = $line[2]/255.0; $color = $line[3].'}'; # one entry for each color in each file printf STY "\\definecolor {%-20s {rgb}{%4.2f,%4.2f,%4.2f}\n", $color, $r, $g, $b; print TEX "{\\color{$color This is {$color }\n\n"; } print TEX '\end{document}', "\n"; # all done!