Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

   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
up vote 3 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 by front end. To see what the expression looks like to Mathematica, you can do

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

which just gives

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


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.