0

I have no real question but rather some observations about declaring shadings in pgf.

First strange thing is that parameterless shadings are declared globally while shadings with parameters are declared locally. For instance, if one says

\begingroup
  \pgfdeclareverticalshading{myshading1}{1cm}{color(0cm)=(red);color(1cm)=(blue)}
  \pgfdeclareverticalshading[mycolor]{myshading2}{1cm}{color(0cm)=(mycolor);color(1cm)=(mycolor!20)}
\endgroup

then

\pgfuseshading{myshading1}

works because myshading1 was actually declared globally, while

\colorlet{mycolor}{red}
\pgfuseshading{myshading1}

does not because myshading2 was declared locally.

However, when a shading with parameters is used, a specific instance is declared globally if not already declared. For instance, after

\begingroup
  \pgfdeclareverticalshading[mycolor]{myshading2}{1cm}{color(0cm)=(mycolor);color(1cm)=(mycolor!20)}
  \colorlet{mycolor}{red}
  \pgfuseshading{myshading2}
\endgroup

the shading myshading2,1,0,0 is declared globally (red=rgb(1,0,0)), and one may use

\pgfuseshading{myshading2,1,0,0}

although myshading2 is not defined anymore.

Another problem is that redefining a shading with parameters is impossible or at least may produce strange results. In the following example, myshading2 is first declared as a vertical shading and used with mycolor=red. Afterwards it is redeclared as a radial shading and used first with mycolor=green which works as expected and then with mycolor=red which uses falsely the vertical shading: since myshading2,1,0,0 was already declared, it is not redefined.

\pgfdeclareverticalshading[mycolor]{myshading2}{1cm}{color(0cm)=(mycolor);color(1cm)=(mycolor!20)}
\colorlet{mycolor}{red}
\pgfuseshading{myshading2}
\pgfdeclareradialshading[mycolor]{myshading2}{\pgfpointorigin}{color(0cm)=(mycolor!20);color(.5cm)=(mycolor)}
\colorlet{mycolor}{green}
\pgfuseshading{myshading2}% correct
\colorlet{mycolor}{red}
\pgfuseshading{myshading2}% incorrect: uses the vertical shading 'myshading2[red]'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.