From bf9c6f6c0c8b36bad22345ed5300c66c60744826 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 22 Jun 2018 10:30:54 +0200 Subject: [PATCH] A better interface for setting colors --- test.tex | 4 ++-- ucwmac.tex | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/test.tex b/test.tex index 26ecbd8..f4ebe8a 100644 --- 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 diff --git a/ucwmac.tex b/ucwmac.tex index 6c7a5de..d4b4e3d 100644 --- a/ucwmac.tex +++ b/ucwmac.tex @@ -322,11 +322,22 @@ %%% 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 %%% -- 2.39.2