Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Formatting Input Cells within a NotebookWrite[]
Posted:
Mar 2, 2013 2:34 AM


Hello David, I'm glad you asked "why" I wish to solve this odd FrontEnd problem (have a NotebookWrite[] not interpret my input, but just place it as is in an InputCell).
The purpose is to improve a teaching method that can be used for either inclass or distance education.
Currently, I'm running a series of 4 hour master classes at different universities, in which I take long and involved problems in Materials Science and solve them more or less completely with Mathematica methods and its graphics and interactivity.
The master classes have frequent "breakpoints" where I ask them to solve a subproblem on their own; the rest of the seminar depends on the solution. The students are supposed to struggle a bit on their ownor at least appreciate the nuance of a solution when they see. After the subproblem is posed, I wait an appropriate amount of time, and then I give them a "key" that I have used to encode a .m file. Get[]ing that file puts up a series of text cells and input cells which the students can read, execute and then proceed with the rest of the seminar. The effect is that all the students can keep up, even if they become stuck early on. Pedagogically, it works. However, my current implementation with CellPrint[] doesn't work perfectly.
One might ask why I don't just embed the exemplary solutions in a closed cell. I find that the students need some barrier to attempt to solve the problems on their own. If the solution is easyclickavailable, they take that easy route and don't solve the problems and thus don't learn very much.
The method may be useful to other educators who use Mathematica as a teaching tool.
I've been stuck on this for a while and come back to it every few weeks. John Fultz and Mark McClure have been helpful, but I fear that I am testing John's patience....
Thanks, as always, Craig
On Feb 27, 13, at 23:44 PM, djmpark wrote:
> Craig, > > If you wanted to get things exactly as you typed them you might type them, > expose the underlying expression and them copy that box structure into your > NotebookWrite. For example: > > NotebookWrite[EvaluationNotebook[], > RowBox[{"Integrate", "[", > RowBox[{RowBox[{"x", " ", RowBox[{"y", "^", "2"}]}], ",", > RowBox[{"{", RowBox[{"y", ",", "1", ",", "2"}], "}"}]}], "]"}]] > > This is a bit of work if you want to do much of it. > > But how are you using this that it is so important that it be exactly as > typed? > > > From: W Craig Carter [mailto:ccarter@MIT.EDU] > > > Hello Mathgroup, > > I'd like to have NotebookWrite[] create an input cell *exactly* as I have > typed that input cell. I'm trying to create set of tutorials with exercises > and worked solutions. > > Here are two *almost working* method, however they don't reproduce the code > as it is writtenwhich is what I'm trying to do. I'm stuck. > > (*Method 1*) > SetAttributes[expressionCell, HoldAll]; > > expressionCell[expr_] := > NotebookWrite[EvaluationNotebook[], > Cell[Block[{BoxForm`$UseTextFormattingWhenEvaluating = True}, > RawBoxes[MakeBoxes[expr]]], "Input", > LanguageCategory > "Mathematica"]] > > (*examplesthese "almost" work, but the FrontEnd converts to StandardForm > 2d form and removes indentation. I'm trying to make it look more like > InputForm*) > > expressionCell[Integrate[x y^2, {y, 1, 2}]] > > expressionCell[ > Manipulate[x y^2, > {y, 1, 2}] > ] > > expressionCell[ > Module[{x, y, z}, > x y z > ] > ] > > (*Method 2, wrap expr in > InputForm*) > > Clear[expressionCell] > SetAttributes[expressionCell, HoldAll]; > > expressionCell[expr_] := > NotebookWrite[EvaluationNotebook[], > Cell[Block[{BoxForm`$UseTextFormattingWhenEvaluating = True}, > RawBoxes[MakeBoxes[InputForm[expr]]]], "Input", > LanguageCategory > "Mathematica"]] > > (*examplesthese work, but I am trying to indicate to students what I am > typing, and so wish to eliminate the explicit *multiplication, and I'd like > to keep my line returns and indentation on the Module example > *) > > expressionCell[Integrate[x y^2, {y, 1, 2}]] > > expressionCell[Manipulate[x y^2, {y, 1, 2}]] > > expressionCell[ > Module[{x, y, z}, > x y z > ] > ] > > > This is a follow on question to "Re: Using Defer on Dynamic Expressions?" > which was answered by John Fultz and by Mark Maclure on the Wolfram > community site. > > W Craig Carter > Professor of Materials Science, MIT > >



