Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Formatting Input Cells within a NotebookWrite[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg129966] Re: Formatting Input Cells within a NotebookWrite[]
  • From: W Craig Carter <ccarter at mit.edu>
  • Date: Thu, 28 Feb 2013 21:25:42 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <28570999.54463.1361952463756.JavaMail.root@m06> <20130228044414.B992B687A@smc.vnet.net>

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 in-class 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 "break-points" where I ask them to solve a sub-problem on their own; the rest of the seminar depends on the solution.  The students are supposed to struggle a bit on their own--or at least appreciate the nuance of a solution when they see.  After the sub-problem 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 easy-click-available, 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 at 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 written---which 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"]]
>
> (*examples---these "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"]]
>
> (*examples---these 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
>
>


  • Prev by Date: Mathematica + ZEMAX
  • Next by Date: Re: how to set initial values to symbolic variable array?
  • Previous by thread: Re: Formatting Input Cells within a NotebookWrite[]
  • Next by thread: Re: Logic and Truth Tables with Mathematica?