Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to get my head around NotebookWrite for the last few days. I can't understand why

NotebookWrite[nb,
  Cell[
   StringForm["some text = ``", 3]
  , "Text"
   ]]

doesn't seem to produce what I would expect:

some text = 3

in the newly defined notebook nb.

Why is this? How can this be achieved? Thanks all, once again!

share|improve this question
    
This is not a problem of NotebookWrite but of Cell with StringForm. Check out Cell-s documentation under Details and "The contents of cells can be the following". As you will see, StringForm is not listed, so you either have to convert it to a normal string (e.g. using ToString@3) or to some xxxData object. –  István Zachar Sep 8 '13 at 7:33

1 Answer 1

up vote 2 down vote accepted

Istvan Zachar's comment is correct, but I think it does not cover your main confusion. The key observation here is that even though it seems like your StringForm expression evaluates to a string, it actually gets displayed that way be front end. To see what the expression looks like to mathematica, you can do

StringForm["some text = ``", 3] // FullForm

which just gives

(*output*)
StringForm["some text = ``",3]

So Mathematica sees this expression with head StringForm, rather than a string. So if we do for example

Head[StringForm["some text = ``",3]]

we get StringForm, whereas if we do

Head["some text = 3"]

we get String.

Note that it is possible to use ToString on an expression with Head StringForm to get a real String. Also, as mentioned in another answer of mine in a question of yours, you should considered using boxes rather than just strings inside your 'Cell's

Closely related: how to convert string output into executable commands

share|improve this answer
    
Thanks for the comment, I'll take a look a the link! –  Gabriel Sep 13 '13 at 13:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.