[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] string variable in pic
From: |
Heinz-Jürgen Oertel |
Subject: |
Re: [Groff] string variable in pic |
Date: |
Sun, 11 Dec 2005 15:20:22 +0100 |
User-agent: |
KMail/1.8.3 |
Am Sonntag, 11. Dezember 2005 15:02 schrieb Ted Harding:
> On 11-Dec-05 Heinz-Jürgen Oertel wrote:
> > Hello,
> > I'm searching for a way to put strings in pic variable,
> > but found no way doing it.
> > What I like to do is something like:
> >
> > .PS
> > bcolor = "red"
> >
> > define cbox {
> > box wid $1 color bcolor
> > }
> > .PE
> >
> > .PS
> > cbox(1) "this is red"
> > bcolor "yellow"
> > cbox(1) "this is yellow"
> > .PE
>
> I *think* (but am not absolutely sure) that the reason your
> approach does not work is that the assignment "=" has the syntax
>
> variable = expression
>
> and, as far as I can tell, "expression" in pic can only be numeric
> (or logical), so that there is no such thing as a string-valued
> expression (or variable). More generally, a string (either quoted
> literally or as returned by 'sprintf') is an object, like 'box'.
>
> However, it is possible to do what you want by macro substitution:
>
> .PS
> define cbox {
> box wid $1 color $2
> }
> .PE
>
> .PS
> bcolor="red"
> cbox(1,"red") "this is red"
> cbox(1,"yellow") "this is yellow"
> .PE
>
> This does not evaluate any expressions: When (e.g.) "red" is
> encountered in 'cbox(1,"red")' it is substituted for $2 in
> the definition of 'cbox', i.e. it effectively re-writes 'cbox'.
>
> Hoping this helps!
> Ted.
Thanks Ted,
The reason for placing some values in a "global" variable is avoiding a
large number of macro arguments having always the same value. Like with the
variable "slant" in my example.
Look at the example I'm just trying:
----------------
.fam H
.PS
slant = .2
define arrowbox { [
box xslanted -slant color $1 $3
box xslanted slant color $2 $3 \
with .ne at last box.se + ( -slant, 0)
# place a box centered above both slanted boxes
box ht 2*boxht invisible \
with .ne at 1st box.ne + ( -(slant/2),0)
] }
.PE
.PS
arrowbox("darkgreen", "darkgreen") \
"\m[white]1st" "first" "colored" "box"
arrowbox("darkgreen", "darkgreen") \
"2nd" "second" "colored" "box"
arrowbox("darkgreen", "darkgreen") \
"3rd" "third" "colored" "box"
arrowbox("darkgreen", "darkgreen") \
"4th" "fourth" "colored" "box"
.PE
.PS
slant = .3
arrowbox("tomato", "tomato") \
"\m[black]1st" "first" "colored" "box"
move -0.2
arrowbox("tomato", "tomato") \
"2nd" "second" "colored" "box"
move -0.2
arrowbox("tomato", "tomato", outline "white") \
"3rd" "third" "colored" "box"
move -0.2
arrowbox("tomato", "red") \
"4th" "fourth" "colored" "box"
.PE
---------------------
The result is attached.
Is the only way extending pic to accept strings in expressions, or at least
in variable assignments?
Regards
Heinz
>
> > Another interesting feature would be if
> > \n[.M] could return the numerical values of the color components.
> > In this case one could define a new color which is sometimes darker or
> > more
> > bright, or "more red" etc. This can be used to produce shaded colored
> > boxes
> > in pic.
> >
> > Hope I get help
> > Regards
> > Heinz
> >
picarrows.pdf
Description: Adobe PDF document