MathGroup Archive 1999

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

Search the Archive

Re: creating input cell with unevaluated expression -- answers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20181] Re: creating input cell with unevaluated expression -- answers
  • From: Aaron Gross <aaron+usenet at bfr.co.il>
  • Date: Sun, 3 Oct 1999 21:07:45 -0400
  • Organization: speaking for myself here
  • References: <7suv3g$21l@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Many thanks to all who responded to my question in article
<7suv3g$21l at smc.vnet.net>.  I thought I would summarize the responses
sent in by e-mail and to the newsgroup, for those who may be
interested.

Some people pointed out that my second unsuccessful try, wrapping the
argument to StylePrint in a call to Unevaluated[], does indeed work in
Mathematica 4.0 but not in Mathematica 3.0.  I'm using 3.0.

In any case, I used P. J. Hinton's suggestion, but with a minor
modification to take the box form and cell style as arguments:

createCell[expr_,form_,style_] := (
  SelectionMove[EvaluationNotebook[], After, EvaluationCell];
  NotebookWrite[
    EvaluationNotebook[], 
    Cell[BoxData[ToBoxes[Unevaluated[expr], form]], style]
  ]
)
SetAttributes[createCell, HoldFirst]

The function he gave me is especially appropriate, in that it solves
the question that I meant to ask and not just the one that I did ask.
I used the vague term "current position in the front-end" (I'm a
newbie to Mathematica), and what I really meant was "after the
evaluation cell".

One person suggested (with a warning of "caveat emptor") giving
StylePrint the attribute HoldAllComplete.  I'm not familiar with
Mathematica, but setting attributes of built-in functions seems like a
Bad Thing to me.

Others suggested using RowBox with string arguments representing the
expression.  However, it seems to me that it's preferable to avoid
going down into the guts of the representation unless absolutely
necessary.  Besides, while this solution is reasonably simple for my
"1+1" example, I want to print many input cells containing expressions
which I'll generate automatically by Map-ing some function.

Thanks again to all those who took the time to respond to my
question.


  • Prev by Date: Re: Mathematica programming language
  • Next by Date: Follow-Up Question to
  • Previous by thread: Re: Rebuilding polygon from CoefficientList?
  • Next by thread: Follow-Up Question to