]> mj.ucw.cz Git - ucwmac.git/commitdiff
A better interface for setting colors
authorMartin Mares <mj@ucw.cz>
Fri, 22 Jun 2018 08:30:54 +0000 (10:30 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 22 Jun 2018 08:30:54 +0000 (10:30 +0200)
test.tex
ucwmac.tex

index 26ecbd8a3440a2ba3243c366600ee27832bbe9ec..f4ebe8aae9151863a358a245918ec10d044a8995 100644 (file)
--- a/test.tex
+++ b/test.tex
@@ -34,9 +34,9 @@
 \:It is an {\I important and popular fact} that things are not always what
 they seem.  For instance, on the planet Earth, man had always assumed
 that he was more intelligent than dolphins because he had achieved so
-much -- the wheel, New York, wars and so on -- whilst all the dolphins
+much -- the wheel, {\colorlocal\rgb{1 0 0}New York}, wars and so on -- whilst all the dolphins
 had ever done was muck about in the water having a good time.  But
-conversely, the dolphins had always believed that they were far more
+conversely, the \colorpush\rgb{0 0 1}dolphins\colorpop{} had always believed that they were far more
 intelligent than man -- for precisely the same reasons.
 \:Curiously enough, the dolphins had long known of the impending
 destruction of the of the planet Earth and had made many attempts to
index 6c7a5dec709091f01ec3e7ebf9c0ff9b65bfe290..d4b4e3d60c93c448f34053da0dea477ed63a1b0e 100644 (file)
 
 %%% Colors %%%
 
+% Use of pdfTeX color stack:
+% \colorpush\rgb{1 0 0} puts a new color on the stack
+% \colorset\rgb{1 0 0} replaces the top color on the stack
+% \colorpop pops the top color
+% \colorlocal\rgb{1 0 0} set a color locally until the end of the current group
 \chardef\colorstk=\pdfcolorstackinit page direct{0 g 0 G}
-\def\colorpush#1{\pdfcolorstack\colorstk push{#1 rg #1 RG}}
-\def\colorpushgray#1{\pdfcolorstack\colorstk push{#1 g #1 G}}
-\def\colorpushcmyk#1{\pdfcolorstack\colorstk push{#1 k #1 K}}
+\def\colorset#1{\pdfcolorstack\colorstk set #1}
+\def\colorpush#1{\pdfcolorstack\colorstk push #1}
 \def\colorpop{\pdfcolorstack\colorstk pop}
+\def\colorlocal{\aftergroup\colorpop\colorpush}
+
+% Different ways of describing colors: \rgb{R G B}, \gray{G}, \cmyk{C M Y K}
+% (all components are real numbers between 0 and 1)
+\def\rgb#1{{#1 rg #1 RG}}
+\def\gray#1{{#1 g #1 G}}
+\def\cmyk#1{{#1 k #1 K}}
 
 %%% Localization %%%