PREP 2015 Question Authoring - Archived

Solution Displays

Solution Displays

by tim Payer -
Number of replies: 3
I have two questions about cleaning up the solution display of a problem.

1.)  Horizontal spacing between TeX and text.
When entering the steps for a solution line by line I would like to include a brief description on the same line that explains to the student what work is being done on each line beside the TeX. For example " Taking the derivative",  or "pulling the common factor", etc...
While I can place these descriptive phrases of text beside the TeX displays, I can not give them any horizontal spacing. The two forms seem destined to be jammed together and the solution would be a lot more readable if I could just place about a half dozen horizontal spaces between the line of work and the description of that work. I see no indication of how to do this in PGML worksheet. This seems an easy fix, but I am unclear of how to do it.

I have attached a jpeg to help clarify.

2.)  Expanding parentheses to enclose enlarged contents.

The second problem in the jpeg shows an input of a fraction with a horizontal fraction bar for a given function. This fraction is not quite enclosed within the parentheses of the function. Can these parentheses be enlarged or the contents be reduced so that the presentation is in proportion? This is in TeX.

Thanks
Attachment Solution_Payer_HW1_PRB1.jpg
In reply to tim Payer

Re: Solution Displays

by tim Payer -
Okay, I am answering my own question here, but the answer has to do with using Tex correctly.

1.)  For Horizontal spacing between Tex and text on a single line simply include \quad within your line of TeX.

For Example: 

Change this line

[``P'(x) = A^2(e^{-Ax} + xe^{-Ax}(-A))``]    Take the derivative.

into this:

[``P'(x) = A^2(e^{-Ax} + xe^{-Ax}(-A)) \quad``]    Take the derivative.

2.)  For self adjusting parentheses:

Just include the escape on the left and right parentheses.

Change this line of code:

[``P(\frac{1}{A}) = A^2\frac{1}{A}e^{-A\frac{1}{A}}``] 


[``P\left(\frac{1}{A}\right) = A^2\frac{1}{A}e^{-A\frac{1}{A}}``] 

Thanks to Tim Lauck...
In reply to tim Payer

Re: Solution Displays

by Paul Pearson -
Hi Tim,

You are writing your solution in list format, so why not use a list?  In the code below are several examples of lists (an indented list, a bulleted list, and an enumerated list).  The enumerated list seems to me like it would be the best fit for what you want.  

I would discourage you from manual formatting, such as manually inserting several spaces, for a few reasons:
  1. Manual formatting is often an indication that you are not following proper writing style guidelines.

  2. As Davide Cervone pointed out last Monday, when manual formatting is necessary it is often a local and temporary fix for something that should be fixed globally and permanently by upgrading document templates (which are provided by macros, style sheets, etc.).  If the manual formatting is left in a problem after a global solution has been implemented, the problem will "look bad" and need to be edited to remove the manual formatting you added.  So, adding manual formatting now may mean more work for you later to remove it.
I think that your desire for manual formatting in this situation is an indication that you are not following proper writing guidelines.  When writing, ask yourself, "Is this how it would be written in a good math textbook?"  If the answer is no, then you're probably not following proper style guidelines.  In your case, I think you should outline the steps of the solution using a list, and your list items should be complete sentences instead of a mathematical expression followed by a descriptive phrase that is not a complete sentence.

For the issue with the parentheses, there are commands \left and \right that you can put in front of symbols so that they are proportional to the other symbols around them.  In particular, you should use [`` \left( \frac{a}{b} \right) ``] to get parentheses of the appropriate size for display-style math.

One last thing about webwork forum etiquette: Please post your code (all of it -- not just snippets).  This makes it much easier for us to test your code and make suggestions.  I have included some PG code below my signature that addresses your questions.  (And, I had to spend time writing this code from scratch instead of copying your code and modifying it.)  Also, it is good etiquette to have public discussions on the forum (rather than private ones via email) since forum discussions persist and are accessible to people who may have similar problems in the future.

Best regards,

Paul Pearson


#################### BEGIN PG CODE ##################

DOCUMENT();  

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGchoicemacros.pl",
"PGML.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

Context("Numeric");



###########################
#  Main text

BEGIN_PGML
Click the solution link to see more.
END_PGML


############################
#  Answer evaluation

install_problem_grader(~~&std_problem_grader);

$showPartialCorrectAnswers = 0;

#ANS( checkbox_cmp( $mc->correct_ans() ) );


############################
#  Solution

BEGIN_PGML_SOLUTION
To find the age for the most likely mayfly life span, we maximize the 
function [` P(x) = A^2 x e^{-Ax} `] by finding its critical points and 
determining which, if any, provide the maximum value of the function.

    First, factor the constant [`A^2`] to obtain [` P(x) = A^2 (x e^{-Ax}) `] .

    Second, calculate the derivative using the product rule and chain rule to obtain
[`P'(x) = A^2(x' e^{-Ax} + x (e^{-Ax})') = A^2(e^{-Ax} - Ax e^{-Ax}) `].

- First, factor the constant [`A^2`] to obtain [` P(x) = A^2 (x e^{-Ax}) `] .

- Second, calculate the derivative using the product rule and chain rule to obtain
[`P'(x) = A^2(x' e^{-Ax} + x (e^{-Ax})') = A^2(e^{-Ax} - Ax e^{-Ax}) `].

1. Factor the constant [`A^2`] to obtain [` P(x) = A^2 (x e^{-Ax}) `] .

2. Calculate the derivative using the product rule and chain rule to obtain
[`P'(x) = A^2(x' e^{-Ax} + x (e^{-Ax})') = A^2(e^{-Ax} - Ax e^{-Ax}) `].

Notice the difference between [`` P(\frac{1}{A}) ``] and [`` P\left( \frac{1}{A} \right) ``].
END_PGML_SOLUTION

COMMENT('MathObject version. Uses PGML.');

ENDDOCUMENT();

###################### END PG CODE ##################
In reply to tim Payer

Re: Solution Displays

by Davide Cervone -
Paul's suggestions, here, are good ones; but I do understand the desire for a list of equalities that have reasons aligned toward the right. Unfortunately, PGML currently doesn't have a table syntax (it needs one), but there are LaTeX environments that could serve your purpose. For example,
BEGIN_PGML
[``
\begin{aligned}
P(t)  &= A^2xe^{-Ax} \\
      &= A^2(xe^{-Ax}) && \text{First pull out the constant of $A^2$} \\
\\
P'(t) &= A^2\left(x'e^{-Ax}+xe^{-Ax}(-Ax')\right) && \text{Product rule and chain rule} \\
      &= A^2\left(e^{-Ax}+xe^{-Ax}(-A)\right) && \text{Since $x' = 1$} \\
      &= A^2e^{-Ax}(1-Ax) && \text{Pull out common factor}
\end{aligned}
``]
END_PGML
will produce a layout that has equations on the left and explanations on the right. Note the use of \text{} to get the explanations, and also the use of $...$ within the text to get back to math mode.

The downside of this is that the text is not in the same font as the surrounding text. But perhaps the layout is more important.

I've attached an image of the resulting alignment.

Attachment alignment.jpg