In Mathematica 11.3 we have the new Iconize function. Say I create an iconized image grabbed from the web, like this:

 hawkings = WebImageSearch["Stephen Hawking", "MaxItems" -> 5];
 pic = Iconize[URLExecute[hawkings[[3]]["ImageHyperlink"]], "Stephen Hawking"]

If I now evaluate input such as...


... where the-actual-icon is the icon just created, then I'll get the image as output. However, if I evaluate instead...


...then I just get the icon object again, not the actual image.

How can I get the image by using the name pic for the icon rather than the iconized object itself?


Iconize is not meant to be used this way. Do not assign the result to a variable.

Above, you are assigning the output to a variable, i.e. storing it in kernel memory.

The purpose of Iconize is to be able to store expressions in a notebook without having them take up a lot of visual space. The icon can be copied around within the notebook, and inserted into input cells, where it will behave as if you had typed the expression it represents.

Normally, you would create an icon either by selecting an expression, right-clicking, and choosing Iconize from the menu (this method does not evaluate), or by typing Iconize[something], selecting it, then evaluating it in place (Command-Enter on Mac).

To sum up: one would not normally use the return value of the Iconize function. Instead, one would use the icon (a visual object within the notebook) that it created. It's useful only in relation with notebooks.

Before Iconize was available, I showed a very similar concept in this blog post, which in turn was inspired by a much older MathGroup post by John Fultz. Looking at this blog post may clarify the intended use of Iconize too.

  • 5
    $\begingroup$ Because if the icon were the same thing as the expression, it would format as the expression, not as an icon. What's returned by Iconize must be different from the expression in order for the magic where it looks like one thing but formats as another. And I would point out that this question is directly addressed by the Possible Issues example on the ref page. In fact, I think your description of the documentation is entirely unfair. 4 notes and 11 examples? That's a reasonable amount, especially for such a tiny function. What do you think isn't addressed by the documentation? $\endgroup$ Mar 15 '18 at 21:46
  • 3
    $\begingroup$ @ItaiSeggev To be fair, the behaviour I tried to describe in the two comments above can be quite confusing, and I have no idea how to explain it clearly and concisely ... people get confused about Defer all the time, and don't understand the difference between it and HoldForm. Personally I love Iconize and I'm glad that this was implemented. $\endgroup$
    – Szabolcs
    Mar 15 '18 at 21:53
  • 3
    $\begingroup$ @Szabolcs Do you mean spcifically the 4th slot, or the big surrounding pink rectangle? Either will be hard/impossible to fix, and we decide to ship without solving the problem. The basic issue is that we can't ship updates to "Core" via paclets, so a function which requires a new TemplateBox style can't be supported (it would be nice to fix that one day, but there are more pressing issues...). Note that only the 4th argument inside the brackets is actually error pink. The big pink rectangle is "TemplateBox with no know DisplayFunction pink", a less hazzardous & currently unfixable problem. $\endgroup$ Mar 15 '18 at 22:51
  • 1
    $\begingroup$ @murray That is the meaning of "The formatted output of Iconize[expr] will evaluate to expr when it is supplied as input." Maybe I'm too much in the weeds of the box language to appreciate what it is and is not communicating to someone who is not an expert. $\endgroup$ Mar 16 '18 at 22:21
  • 3
    $\begingroup$ @murray To me, you might as well be asking "Why don't you state f is continuous??" after I have stated that f is differentiable. If the formatted output evaluates to expr, how can that output (and therefore the notebook) not contain expr? (In point of fact, the output doesn't evaluate to expr, it parses to expr. That is shown via the example involving unevaluated expression, but was deemed overly technical to put in the notes.) $\endgroup$ Mar 18 '18 at 2:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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