Difference between revisions of "User:Malcolm/wip/Sage WW Notes"
m |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | Notes on embedding Sage into WW problems using the Sage cell server - May/June 2012 |
+ | ==Notes on embedding Sage into WW problems using the Sage cell server - May/June 2012== |
+ | |||
+ | ===Passing Functions - Don't use Contexts=== |
||
When passing functions to Sage, if the function is defined as a math object problems can occur since it can happen that none of |
When passing functions to Sage, if the function is defined as a math object problems can occur since it can happen that none of |
||
Line 21: | Line 21: | ||
** <tt>[x-(-2)]*(x-2)*(x-4)</tt> in <tt>normalStrings</tt> |
** <tt>[x-(-2)]*(x-2)*(x-4)</tt> in <tt>normalStrings</tt> |
||
** <tt>\left(x-\left(-2\right)\right)\!\left(x-2\right)\!\left(x-4\right)</tt> in <tt>texStrings</tt> |
** <tt>\left(x-\left(-2\right)\right)\!\left(x-2\right)\!\left(x-4\right)</tt> in <tt>texStrings</tt> |
||
+ | None of theses are suitable for passing to Sage. |
||
+ | |||
Possible solution: |
Possible solution: |
||
# Use a construction like |
# Use a construction like |
||
Line 26: | Line 28: | ||
#: <source> $f = Compute($f_raw); </source> |
#: <source> $f = Compute($f_raw); </source> |
||
And use <tt>$f_raw</tt> to pass to Sage and <tt>$f</tt> to work with in WW. |
And use <tt>$f_raw</tt> to pass to Sage and <tt>$f</tt> to work with in WW. |
||
− | # TODO investigate using <tt>string()</tt>, but setting some flags noparen |
+ | # <s>TODO investigate using <tt>string()</tt>, but setting some flags noparen </s> |
+ | * After |
||
+ | *: <source> Context("Numeric"); </source> |
||
+ | *: <source> $g = Compute("(x-(-2))*(x-2)*(x-4)"); </source> |
||
+ | *: <tt> $g->with(showExtraParens=>0)->string()</tt> produces <tt>[x-(-2)]*(x-2)*(x-4)</tt> |
||
+ | *: <tt>$g->with(showExtraParens=>0)->stringify()</tt> produces <tt>[x-(-2)]*(x-2)*(x-4)</tt> in <tt>normalStrings</tt> |
||
+ | * But after |
||
+ | *: <source>Context()->flags->set(showExtraParens=>0);</source> |
||
+ | *: <tt>$g->stringify()</tt> produces <tt>(x--2)*(x-2)*(x-4)</tt> which is in the right direction. |
||
+ | |||
+ | === Two problems with MathJax === |
||
+ | The '''Sage Cell Server''' uses '''MathJax''' for pretty display, but configures MathJax to be compatible with jsMath. There are two problems with the way things work presently: |
||
+ | # When using display modes ''images'' or ''jsMath'' in WW, everything displays correctly, but the MathJax displayed math in the cell server output is not copy/pastable. (tested only in FF 12.0) |
||
+ | # When using display mode ''MathJax'' in WW, the WW page displays properly (using MathJax), but the MathJax in the cell server portion brreaks - it looks like close to raw TeX. (again tested only in FF 12.0) |
||
+ | The '''good news''' is that this problem will go away in about six months when the jsMath dependency is removed from the Cell Server so that the Cell Server can use a very vanilla version of the Math Jax config wich will work with the WW version. |
||
+ | |||
+ | == To Do == |
||
+ | * Add a link to a Sage Cell Server to the WW configuration files to be used by WW problems |
||
+ | * Find a way to obfuscate the Sage code passed to the SCS |
||
+ | * Find a way to pass Sage answers into WW |
||
+ | ** <s>TOTRY - Use a hidden form field to replace the webwork answer box.</s> |
||
+ | *: This works with some caveats. See [[User:Malcolm/wip/Answers_from_Sage|here]] |
Latest revision as of 12:27, 13 June 2012
Contents
Notes on embedding Sage into WW problems using the Sage cell server - May/June 2012
Passing Functions - Don't use Contexts
When passing functions to Sage, if the function is defined as a math object problems can occur since it can happen that none of <source lang="perl"> $f $f->string() $f->stringify() $f->TeX() </source> return the orginal string used to define the function.
For example with the set up: <source lang="perl"> Context("Numeric"); $f = Compute("(x-(-2))*(x-2)*(x-4)"); </source> then
- $f->string() produces [x-(-2)]*(x-2)*(x-4)
- $f->TeX() produces \left(x-\left(-2\right)\right)\!\left(x-2\right)\!\left(x-4\right)
- $f->stringify() produces:
- [x-(-2)]*(x-2)*(x-4) in normalStrings
- \left(x-\left(-2\right)\right)\!\left(x-2\right)\!\left(x-4\right) in texStrings
None of theses are suitable for passing to Sage.
Possible solution:
- Use a construction like
- <source> $f_raw = "(x-(-2))*(x-2)*(x-4)";</source>
- <source> $f = Compute($f_raw); </source>
And use $f_raw to pass to Sage and $f to work with in WW.
TODO investigate using string(), but setting some flags noparen
- After
- <source> Context("Numeric"); </source>
- <source> $g = Compute("(x-(-2))*(x-2)*(x-4)"); </source>
- $g->with(showExtraParens=>0)->string() produces [x-(-2)]*(x-2)*(x-4)
- $g->with(showExtraParens=>0)->stringify() produces [x-(-2)]*(x-2)*(x-4) in normalStrings
- But after
- <source>Context()->flags->set(showExtraParens=>0);</source>
- $g->stringify() produces (x--2)*(x-2)*(x-4) which is in the right direction.
Two problems with MathJax
The Sage Cell Server uses MathJax for pretty display, but configures MathJax to be compatible with jsMath. There are two problems with the way things work presently:
- When using display modes images or jsMath in WW, everything displays correctly, but the MathJax displayed math in the cell server output is not copy/pastable. (tested only in FF 12.0)
- When using display mode MathJax in WW, the WW page displays properly (using MathJax), but the MathJax in the cell server portion brreaks - it looks like close to raw TeX. (again tested only in FF 12.0)
The good news is that this problem will go away in about six months when the jsMath dependency is removed from the Cell Server so that the Cell Server can use a very vanilla version of the Math Jax config wich will work with the WW version.
To Do
- Add a link to a Sage Cell Server to the WW configuration files to be used by WW problems
- Find a way to obfuscate the Sage code passed to the SCS
- Find a way to pass Sage answers into WW
TOTRY - Use a hidden form field to replace the webwork answer box.
- This works with some caveats. See here