Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #13620
| From | W Craig Carter <ccarter@MIT.EDU> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Formatting Input Cells within a NotebookWrite[] |
| Date | 2013-02-27 08:03 +0000 |
| Message-ID | <kgkel7$4c1$1@smc.vnet.net> (permalink) |
| Organization | Time-Warner Telecom |
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
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Formatting Input Cells within a NotebookWrite[] W Craig Carter <ccarter@MIT.EDU> - 2013-02-27 08:03 +0000
csiph-web