On Tue, 5 Feb 2002, Andy Wardley wrote:
> The Math plugin would be the best idea, though. It would be trivially
> easy to write.... in fact, here you go, I've attached a fledgling Math
> plugin (and associated test script, of course :-). I'd be more than
> happy for you or anyone else to flesh this out with more functionality
> and I'll distribute it as a core plugin.
Thank you very much for the suggestion. This solves partially the problem.
I think I can contribute to the plugin, but not before 10 days. I have to
write the problems for the next test :)
Anyhow, for my users, I would like to allow 'normal' syntax, instead of
using temporary variables.
Let me show a practical example (badly translated to English).
----------------------------------------------------------------------
[% BLOCK motion1d %]
[%
DEFAULT m=3 h = 5 g = 10;
check_range('m', 1, 'INF');
check_range('h', 1, 'INF');
%]
\begin{problem}
A body of mass $m=[%m%] \u{kg}$ is falling down from a height
of $h=[%h%] \u{m}$.
\ask{How much is its velocity $v$ when it reaches the ground?}
[% # answers
r1 = 'sqrt(2*$stash->get("g")*$stash->get("h"))'| perl;
w1 = 'sqrt(2*$stash->get("m")*$stash->get("g")*$stash->get("h"))' |
perl;
w2 = 'sqrt(2*$stash->get("g")*$stash->get("m"))' | perl;
w3 = 'sqrt($stash->get("g")*$stash->get("h"))' | perl;
ans.r = [r1];
ans.w = [w1,w2,w3] ;
check_duplicate(ans, "m=$m, h=$h")
%]
[% FOREACH r = ans.r %]
\right{ $v \simeq [% r | format('%5.2f') %] \u{m/s} $.}
[% END %]
[% FOREACH w = ans.w %]
\wrong{$v \simeq [% w | format('%5.2f')%] \u{m/s} $.}
[% END %]
\end{problem}
[% END %]
------------------------------------------------------------------
which is used as
[% INCLUDE motion1d m=7.2 FOREACH h = [1.7,2.3,5.7] %]
(and then processed by a perl program I'm developing)
Now, I need to simplify it as much as possible, in order that even a
mathematical professor can use it. First of all, I would like to avoid the
$stash->get, which can be done by means of your plugin, but I would
like also to be able to write
r1 = Math.calc('sqrt(2*g*h)')
or even better
r1 = Math.calc('sqrt(2 g h)')
or, possibly, distributing Math.calc
ans = Math.calc({ r => ['sqrt(2 g h)'],
w => ['sqrt(2 m h)','sqrt(g h)',...]})
which would indeed be the best solution.
------------------------------
To simplify the "answers" part, I think that a simple printf-like
plugin/macro
[% print_answers(ans, '$v \\simeq %5.2f \\u{m/s}$.' %]
would be sufficient and readable, except for the annoying part of
doubling the backslashes.
Comments and suggestions are welcome.
--
Franco Bagnoli (franchino) <[EMAIL PROTECTED]>
virtual location: Dipartimento di Energetica "S. Stecco"
real location: Dip. Matematica Applicata "G. Sansone", Universita' Firenze,
Via S. Marta, 3 I-50139 Firenze, Italy. Tel. +39 0554796422, fax: +39 055471787
GPG Key fingerprint = 169D 9EA5 8FD3 7EDA E43A 9830 255F BCEC 0D63 3728