Short question: 

Is is possible for a variable access its name? (maybe this is a perl 
question..) 

Say: may I define a virtual method so that  [%a.name%] prints a ? 

-----------------------------------------------------------------

Probably my approach is wrong, anyhow here it is the problem: 

I'm developing a plugin (Lcalc) for making computations using Latex 
syntax. 

The first step is to define a variable, 

[% s = Lcalc.def('\frac{1}{2} a t^2', units=>'\metre') %]

(a and t may be other variables defined using Lcalc or standard variables. 
They do not need to be defined at this step).

Lcalc.def returns an hash with a numer of methods defined, s.v, s.f, 
etc..., see later

At a certain point I need to print the actual value (i.e. computed using 
the actual value of a and t) of s

[% s.v %] gives the full precision, say 0.456344531222

I may need to roud it to a certain precision, so I defined 

[% s.f %] which gives the "formatted" value of s, the format being "%5.2f% 
by default, and it may be changed at definition or when used
[%s.f('%8.2f')%]

Now the problem: I found myself writing often things like 

... and so the result is
\[
 s = \frac{1}{2} a t^2 \simeq [%s.f%]~\metre.
\]

and since repetitions are bad, I defined [% s.l%] which returns the 
original latex definition of s and [%s.u%] which returns the units, so 
I write

 s = [%s.l%] \simeq [%s.f%]~[$s.u%].

or 

[%"s = ${s.l} \\simeq ${s.f} ~ ${s.u}."%]
    
\______ ________________________________/
       V
Now, this                         is just a template,  and I would 
like to store it in the variable, just like the format:

[% s.t %]

since I need to print for instance a set of variables: 

[FOREACH x = parameters %]
[% x.t %]
[% END %]

but the problem is: how can a variable know its name? 
I do not want to explicitly set the template for each variables, just use 
a default template. 

It works to to use a "fixed name" variable, say $x, and define 
the template as :

[%"$x = ${$x.l} \\simeq ${$x.f} ~ ${$x.u}."%]

so that it is easy to write

[% Lcalc.t(a) %] 

(just set x=a), 

and even 

[%Lcalc.t(parameters)%] 

(where parameter is a vector) 

but I do not see any way of using a syntax like [%a.t%]. Hints?


-- 
Franco Bagnoli (franchino) <[EMAIL PROTECTED]> ([EMAIL PROTECTED])
virtual location: Dipartimento di Energetica "S. Stecco"
ultra-virtual affiliation: Centro Dinamiche Complesse (CSDC-Firenze)
real location: Dip. Matematica Applicata "G. Sansone", Universita' Firenze,
Via S. Marta, 3 I-50139 Firenze, Italy. Tel. +39 0554796422, fax: +39 055471787


_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to