Forum archive 2000-2006

Blake Thornton - BEGIN_TEXT versus TEXT(EV2(

Blake Thornton - BEGIN_TEXT versus TEXT(EV2(

by Arnold Pizer -
Number of replies: 0
inactiveTopicBEGIN_TEXT versus TEXT(EV2(<<EOT)); topic started 8/30/2004; 2:53:12 PM
last post 8/30/2004; 6:54:24 PM
userBlake Thornton - BEGIN_TEXT versus TEXT(EV2(<<EOT));  blueArrow
8/30/2004; 2:53:12 PM (reads: 1424, responses: 9)
In Webwork 1.9, I tried to exclusively use the BEGIN_TEXT construction, but in webwork 2, it doesn't seem to work correctly whereas the TEXT(EV2(<<EOT)); construction seems fine. From what I can tell, the problem exists when I try to embed variables into the problem in tex mode.

Specifically, if you try the following pg file, I get errors, but it works fine if the the TEXT(EV2(<<EOT)); for is used:

 


DOCUMENT();        # This should be the first executable line in the problem.



loadMacros(
PG.pl,
PGbasicmacros.pl,
PGchoicemacros.pl,
PGanswermacros.pl,
PGauxiliaryFunctions.pl
);



TEXT(&beginproblem);
$showPartialCorrectAnswers = 1;



$a1 = random(1,4,1);



$b1 = random(2,5,1);



$x1 = random(1,5,1);



$m1 = $b1/(2*($a1+$b1*$x1)**.5);



BEGIN_TEXT



Let \[ f(x) = \sqrt { $a1 + $b1 x } \]



$PAR



\( f'( $x1 ) = \) \{ans_rule(20) \}



$BR



END_TEXT



$ans = $m1;



&ANS(std_num_cmp($ans));



ENDDOCUMENT(); # This should be the last executable line in the problem.

<| Post or View Comments |>


userBlake Thornton - Re: BEGIN_TEXT versus TEXT(EV2(<<EOT));  blueArrow
8/30/2004; 5:27:14 PM (reads: 1635, responses: 0)
Okay, I narrowed this down a bit after reading more docs. It seems like bizarre behavior to me, but here is what happens.

This works:

TEXT(EV2(<<EOT));

But this fails:

TEXT(EV2(<<'EOT'));

Note the single quotes.

I'm confused.

<| Post or View Comments |>


userMichael Gage - Re: BEGIN_TEXT versus TEXT(EV2(<<EOT));  blueArrow
8/30/2004; 5:47:47 PM (reads: 1617, responses: 0)
I haven't been able to duplicate this problem yet.

 

BEGIN_TEXT is exactly equivalent to



TEXT(EV3(<<'END_TEXT'));



The details are given at http://webhost.math.rochester.edu/webworkdocs/docs/pglanguage/tutorial/problemtext

The difference between

TEXT(EV2(<<EOT));
TEXT(EV3(<<'EOT'));

is that in the first case the $variables are evaluated first, before anything else. In the second, the $variables are evaluated after the \{ .... \} code has been evaluated.

See also http://webwork.math.rochester.edu/docs/docs/pglanguage/pod/pgbasicmacros.html#ev2

 

<| Post or View Comments |>


userJohn Jones - Re: BEGIN_TEXT versus TEXT(EV2(<<EOT));  blueArrow
8/30/2004; 5:52:54 PM (reads: 1611, responses: 0)
pg problems get read by perl, and perl has different kinds of quotes. Double quotes substitute variable values, whereas single quotes give the literal value. So, '$x1' is the string $x1, but "$x1" is the value of $x1.

Offhand, I don't see why BETIN_TEXT/END_TEXT should fail above. What error messages are generated?

John

<| Post or View Comments |>


userBlake Thornton - Re: BEGIN_TEXT versus TEXT(EV2(<<EOT));  blueArrow
8/30/2004; 5:52:54 PM (reads: 1605, responses: 1)
Thanks for checking this out.

Are these differences the same as for the constructions for EV3 below :

SOLUTION(EV3(<<'EOT'));

and

SOLUTION(EV3(<<EOT));

?????????????

Thanks! Blake

<| Post or View Comments |>


userBlake Thornton - Re: BEGIN_TEXT versus TEXT(EV2(<<EOT));  blueArrow
8/30/2004; 6:35:54 PM (reads: 1602, responses: 0)
Okay, I am getting more confused in some ways, but less in others. I have read the documentation on EV2 vs EV3 and single quotes versus no quotes. In any case, I think the error are definitely related this this. I have tons more questions, but it seems that if I do a permutation of changing the EV3 to EV2 or with/without single quotes, I can get it to work.

If you are interested, I am happy to post the exact files and details of all the errors, but my guess is that everyone's time is better spent elsewhere.

In any case, here is the example of one of the errors:

 


 

% ERROR in :EV3, PGbasicmacros.pl:  % There is an error occuring in the following code: 

Solution:

a) The point crosses the x-axis when the y-coordinate is zero.
This happens when .
Plugging these in: .
% % Unrecognized escape p passed through at (eval 18125) line 1.
% % %

 


In any case, thanks to those who pointed me in the right direction!!

<| Post or View Comments |>


userMichael Gage - Re: BEGIN_TEXT versus TEXT(EV2(<<EOT));  blueArrow
8/30/2004; 6:41:55 PM (reads: 1822, responses: 0)
Yes. In general the first construction is the correct one, but either might work depending on what occurs before the EOT.

<| Post or View Comments |>


userMichael Gage - Re: BEGIN_TEXT versus TEXT(EV2(<<EOT));  blueArrow
8/30/2004; 6:42:44 PM (reads: 1627, responses: 0)
Please post the contents of this problem. I can probably diagnose this problem from a distance.

For the original problem (which I have been unable to reproduce here.) Do you get the same result if you replace BEGIN_TEXT by

TEXT(EV3(<<'END_TEXT'))

<| Post or View Comments |>


userMichael Gage - Re: BEGIN_TEXT versus TEXT(EV2(<<EOT));  blueArrow
8/30/2004; 6:49:22 PM (reads: 1600, responses: 0)
As to single and double quotes and EV2 and EV3:

EV2 is meant to be used with double quotes:

EV2(<<"EOT")); or EV2(<<EOT)

(no quotes defaults to double quotes)

while EV3 is not:

EV3(<<'EOT'));

If you use double quotes with EV3 then the $variables will be interpolated (evaluated) first. If you use single quotes with EV2 then there is a good chance that the $variables will not be interpolated at all.

For many simple problems the two produce the same results, since the order of interpolating, vs evaluating the \{ \} segments doesn't matter.

<| Post or View Comments |>


userBlake Thornton - Re: BEGIN_TEXT versus TEXT(EV2(<<EOT));  blueArrow
8/30/2004; 6:54:24 PM (reads: 1603, responses: 0)
Thanks Mike and John! This is exactly the problem and I think I understand now. Doesn't make perfect sense yet, but I can find the right thing to do. No need to post the problem now, but you can find it here:

www.math.wustl.edu/~blake/pg/

Thanks again!

(Oh, and the problem I posted above seems to work.)

<| Post or View Comments |>