## WeBWorK Problems

by tim Payer -
Number of replies: 2
Hello All,

I would like to inserted some latex code into the "correct answer" displays for the student for a multiple drop down radio answer.

And while the Latex expressions render well in the choices of selections for the drop down menu, their brackets are displayed in the answer preview and correct answer displays.

Is there a better way to enter these expressions?

I am using probability notation and Latex within the double quotes of the radio pull down selections. For example the following possible answers are displayed nicely in the drop down menu:

"P(VN   $\cap$  NV  $\cap$  VV)"

"P(VN  U  NV  U  NN)"

But if these answers are selected their display will look like this:
(with "n" substituted for the sign of intersection for this message)

"P(VN   $n$  NV  $n$  VV)"

"P(VNUNVUNN)"

The red braces and brackets, and the missing spaces I are a bit troubling.

Can I enter Latex in a different way to enable the displays of the "Correct answer" and "Answer Preview" to display correctly?

I have tried the \lbrace  and \rbrace, but this not help either.

Most appreciated.....Thanks,  Tim

by Davide Cervone -

It is not clear whether you mean a pop-up menu or a radio button group, but it sounds more like a pop-up menu to me,so I'm going with that. There are two different kinds of pop-up menus, MathObject ones via parserPopup.pl and the PopUp() command, or traditional ones using new_pop_up_select_list(), or one of the similar macros from PGchoicemacros.pl. Given your code posted to another question, I'm going to assume PopUp(). (In the future, however, it would be helpful to be more explicit about the situation, and it is always best to include at least a code snippet, if not an entire problem (reduced to the minimum needed to show your problem).

In any case, for your question, the first this to note is that you can not use LaTeX notation within a pop-up menu. See the PopUp documentation for details. This is because pop-up menus are handled through the <select> HTML tag, which uses the browser's native menus, and those can only include text, not HTML markup. Since math is not just plain text, you can't put math inside a pop-up menu. So your use of $...$ within the menu is not allowed (and probably should have been $$...$$ in any case).

On the other hand, you can use Unicode characters within menus, so for simple expressions like yours, you can use the Unicode characters for the symbols you need. For example,

    "P(VN ~~x{2229} NV ~~x{222A} VV)"

for a cap (U+2229) and a cup (U+222A). Not quite as convenient, but certainly doable.

Davide

by tim Payer -
Hello Again,

I have tried your suggestion of using unicode characters instead of Latex code in
PopUp( ) answers, But I am running into some big problems.

Either my execution is wrong or perhaps version 10 does not handle unicode very well?

Any pointers would be much appreciated.

The block of code is below and the errors are removed if I take the unicode characters out.

# DESCRIPTION  11
# Probability
# WeBWorK problem written by Tim payer, <tsp1@humboldt.edu>
# ENDDESCRIPTION

## DBsubject(Probability)
## DBchapter(??)
## DBsection(??)
## Institution(Humboldt State University)
## Author(Tim Payer)

DOCUMENT();
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserFormulaUpToConstant.pl",
"niceTables.pl",
"PGunion.pl",
"parserPopUp.pl",
);

Context("Numeric");
Context()->flags->set(
tolerance => 0.0001,
tolType => "absolute",
);

# \{row("Income $", @z)\} # Table data generation: # To switch off the algorithmic table data un-comment the following 5 lines: # and then Comment (#) the random assignments. #$r[4] = 12;
# $u[4] = 150; #$m[4] = 200;
# $l[1] = 200; #$p[1] = 50;
$r[4] = random(12, 18,1);$r[3] = $r[4] + 50;$r[2] = $r[4]*10 + 6;$r[1] = $r[4]*30 - 7;$r[0] = $r[4]*55 + 22;$rsum = $r[4]+$r[3]+$r[2]+$r[1]+$r[0];$u[4] = random(121, 161,1);
$u[3] =$u[4] + 121;
$u[2] =$u[4]*4 + 6;
$u[1] =$u[4]*17 - 7;
$u[0] =$u[4]*5 + 22;
$usum =$u[4]+$u[3]+$u[2]+$u[1]+$u[0];

$m[4] = random(191, 211,1);$m[3] = $m[4]*4 + 22;$m[2] = $m[4]*10 + 17;$m[1] = $m[4]*6 - 24;$m[0] = $m[4]*2 + 51;$msum = $m[4]+$m[3]+$m[2]+$m[1]+$m[0];$l[0] = random(181, 213,2);
$l[1] =$l[0]*2 + 89;
$l[2] =$l[0]*3 + 17;
$l[3] =$l[0]*10 + 24;
$l[4] =$l[0]*3 + 51;
$lsum =$l[4]+$l[3]+$l[2]+$l[1]+$l[0];

$p[0] = random(41, 58,1);$p[1] = $p[0] + 22;$p[2] = $p[0]*2 + 17;$p[3] = $p[0]*3 - 15;$p[4] = $p[0]*6 + 51;$psum = $p[4]+$p[3]+$p[2]+$p[1]+$p[0]; # Column sums:$c0 = $p[0]+$l[0]+$m[0]+$u[0]+$r[0];$c1 = $p[1]+$l[1]+$m[1]+$u[1]+$r[1];$c2 = $p[2]+$l[2]+$m[2]+$u[2]+$r[2];$c3 = $p[3]+$l[3]+$m[3]+$u[3]+$r[3];$c4 = $p[4]+$l[4]+$m[4]+$u[4]+$r[4];$grand = $c0+$c1+$c2+$c3+$c4 +$psum+$lsum+$msum+$usum+$rsum;

$popup1 = PopUp( ["probability notation", "P(86-88)", "P(A)", "P(B)", "P(C)", "P(D)","P(E)"], "P(B)");$ans1 =$c1/$grand;

$popup2 = PopUp( ["probability notation", "P(B U F)", "P(BF)", "P(B ~~x{2229} F)", "P(B + F)", "P(B x F)"], "P(B ~~x{2229} F)");$ans2 =$p[1]/$grand;

# Apparently the unicode wont work here?  "~~x{2229}" wont render

BEGIN_TEXT

$PAR 4.2) Recent census data has correlated life expectancy with one's income bracket.$BR
Given a small town of $$grand$$ individuals, that is loosely based upon the US census data, determine the following probabilities using correct probability notation. Answer with fourth decimal accuracy and use the event variables declared below:
$PAR Where:$BR
$PAR$BLEFT
\{ begintable(7) \}
\{ row( "Life Expectancy", "89-95", "86-88", "81-85","77-80","74-76" ,"Row Sums") \}
\{ row( "Rich:", $r[0],$r[1],$r[2],$r[3], $r[4],$rsum ) \}
\{ row( "Upper Middle Class", $u[0],$u[1],$u[2],$u[3], $u[4],$usum) \}
\{ row( "Middle Class", $m[0],$m[1],$m[2],$m[3], $m[4],$msum) \}
\{ row( "Lower Middle Class", $l[0],$l[1],$l[2],$l[3], $l[4],$lsum) \}
\{ row( "Poor", $p[0],$p[1],$p[2],$p[3], $p[4],$psum) \}
\{ row( "Column Sums:", $c0,$c1,$c2,$c3, $c4,$grand) \}
\{ endtable() \}
$ELEFT$PAR
$$A$$ = Event that an individual has a life expectancy of 89 - 95 years. $BR $$B$$ = Event that an individual has a life expectancy of 86 - 88 years.$BR
$$C$$ = Event that an individual has a life expectancy of 81 - 85 years. $BR $$D$$ = Event that an individual has a life expectancy of 77 - 80 years.$BR
$$E$$ = Event that an individual has a life expectancy of 75 - 76 years. $BR $$R$$ = Event that an individual is rich.$BR
$$S$$ = Event that an individual of the upper middle class $BR $$M$$ = Event that an individual is of the middle class.$BR
$$L$$ = Event that an individual is of the lower middle class.$BR $$F$$ = Event that an individual is poor.$BR
END_TEXT

BEGIN_PGML

4.2a)  Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years:

[_____]{$popup1} = [______]{$ans1}

4.2b)  Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years and is poor:

[_____]{$popup2} = [______]{$ans2}

END_PGML

BEGIN_PGML_SOLUTION
*SOLUTION*
To simplify the expression to a single term with a rational denominator we first start by splitting the root between the numerator and denominator. Then find a common denominator and rationalize the denominator.

[\begin{aligned}&\\
[$c]-\sqrt{\frac{[$am] x}{[$bm]}} &=[$c] -\sqrt{\frac{[$m]\cdot[$a] x}{[$m]\cdot[$b]}} = [$c] -\frac{\sqrt{[$a] x}}{\sqrt{[$b]}} && \text{Cancel the common factor and then split the root.}\\ &=\frac{[$c]\sqrt{[$b]}}{ \sqrt{[$b]}}-\frac{\sqrt{[$a] x}}{\sqrt{[$b]}} && \text{Create a common denominator.}\\
&=\frac{[$c]\sqrt{[$b]} -\sqrt{[$a] x}}{\sqrt{[$b]}} && \text{Combine in to a single fraction.}\\
&=\frac{\left([$c]\sqrt{[$b]} -\sqrt{[$a] x}\right)\sqrt{[$b]}}{\sqrt{[$b]}\cdot\sqrt{[$b]}} && \text{Multiply the numerator and denominator by the denominator.}\\
&=\frac{\left([$c]\sqrt{[$b]\cdot [$b]}-\sqrt{[$a] \cdot [$b] x}\right)}{[$b]} && \text{Distribute through the numerator and reduce the denominator.}\\
&=\frac{\left([$c] \cdot [$b] -\sqrt{[$ab] x}\right)}{[$b]} && \text{Reduce the square root factors.}\\
&=\frac{[$cb] - \sqrt{[$ab] x}}{[\$b]} && \text{Combine numerator factors.}
\end{aligned}]

END_PGML_SOLUTION

ENDDOCUMENT();