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.

When you're looking at some help pages, they may have cells containing images which can be shifted within the cell by left-clicking and dragging the mouse.

Here is a sample:

tutorial/StylesAndTheInheritanceOfOptionSettings

Using Ctrl + Shift + E to make the cell expression visible.

And we can see such images are stored in some kind of compressed data.

However, that seems not to be the same as that produced by Compress.

So how can I generate the same kind of cell to make an image shiftable which placed in the cell?

Is there any references about GraphicsData?

Here is a sample data different from that in help pages.

Cell[GraphicsData["PostScript", "\<\
%!
%%Creator: Mathematica
%%AspectRatio: 1 
MathPictureStart
/Mabs {
Mgmatrix idtransform
Mtmatrix dtransform
} bind def
/Mabsadd { Mabs
3 -1 roll add
3 1 roll add
exch } bind def
%% Graphics
%%IncludeResource: font Courier
%%IncludeFont: Courier
/Courier findfont 10  scalefont  setfont
% Scaling calculations
0.5 0.135135 0.5 0.135135 [
[ 0 0 0 0 ]
[ 1 1 0 0 ]
] MathScale
% Start of Graphics
1 setlinecap
1 setlinejoin
newpath
0 0 m
1 0 L
1 1 L
0 1 L
closepath
clip
newpath
0 g
.002 w
[ ] 0 setdash
newpath
.09459 .09459 .08446 0 365.73 arc
s
newpath
.09459 .22973 .03378 0 365.73 arc
s
newpath
.09459 .36486 .08446 0 365.73 arc
s
newpath
.09459 .5 .03378 0 365.73 arc
s
newpath
.09459 .63514 .08446 0 365.73 arc
s
newpath
.09459 .77027 .03378 0 365.73 arc
s
newpath
.09459 .90541 .08446 0 365.73 arc
s
newpath
.22973 .09459 .03378 0 365.73 arc
s
newpath
.22973 .22973 .08446 0 365.73 arc
s
newpath
.22973 .36486 .03378 0 365.73 arc
s
newpath
.22973 .5 .08446 0 365.73 arc
s
newpath
.22973 .63514 .03378 0 365.73 arc
s
newpath
.22973 .77027 .08446 0 365.73 arc
s
newpath
.22973 .90541 .03378 0 365.73 arc
s
newpath
.36486 .09459 .08446 0 365.73 arc
s
newpath
.36486 .22973 .03378 0 365.73 arc
s
newpath
.36486 .36486 .08446 0 365.73 arc
s
newpath
.36486 .5 .03378 0 365.73 arc
s
newpath
.36486 .63514 .08446 0 365.73 arc
s
newpath
.36486 .77027 .03378 0 365.73 arc
s
newpath
.36486 .90541 .08446 0 365.73 arc
s
newpath
.5 .09459 .03378 0 365.73 arc
s
newpath
.5 .22973 .08446 0 365.73 arc
s
newpath
.5 .36486 .03378 0 365.73 arc
s
newpath
.5 .5 .08446 0 365.73 arc
s
newpath
.5 .63514 .03378 0 365.73 arc
s
newpath
.5 .77027 .08446 0 365.73 arc
s
newpath
.5 .90541 .03378 0 365.73 arc
s
newpath
.63514 .09459 .08446 0 365.73 arc
s
newpath
.63514 .22973 .03378 0 365.73 arc
s
newpath
.63514 .36486 .08446 0 365.73 arc
s
newpath
.63514 .5 .03378 0 365.73 arc
s
newpath
.63514 .63514 .08446 0 365.73 arc
s
newpath
.63514 .77027 .03378 0 365.73 arc
s
newpath
.63514 .90541 .08446 0 365.73 arc
s
newpath
.77027 .09459 .03378 0 365.73 arc
s
newpath
.77027 .22973 .08446 0 365.73 arc
s
newpath
.77027 .36486 .03378 0 365.73 arc
s
newpath
.77027 .5 .08446 0 365.73 arc
s
newpath
.77027 .63514 .03378 0 365.73 arc
s
newpath
.77027 .77027 .08446 0 365.73 arc
s
newpath
.77027 .90541 .03378 0 365.73 arc
s
newpath
.90541 .09459 .08446 0 365.73 arc
s
newpath
.90541 .22973 .03378 0 365.73 arc
s
newpath
.90541 .36486 .08446 0 365.73 arc
s
newpath
.90541 .5 .03378 0 365.73 arc
s
newpath
.90541 .63514 .08446 0 365.73 arc
s
newpath
.90541 .77027 .03378 0 365.73 arc
s
newpath
.90541 .90541 .08446 0 365.73 arc
s
1 0 0 r
.001 w
.58446 .5 m
.60135 .5 L
s
1 .156 0 r
.60135 .5 m
.58446 .5 L
s
1 .312 0 r
.58446 .5 m
.60135 .5 L
s
1 .468 0 r
.60135 .5 m
.58446 .5 L
s
1 .624 0 r
.58446 .5 m
.60135 .5 L
s
1 .78 0 r
.60135 .5 m
.58446 .5 L
s
1 .936 0 r
.58446 .5 m
.60135 .5 L
s
.908 1 0 r
.60135 .5 m
.58446 .5 L
s
.752 1 0 r
.58446 .5 m
.60135 .5 L
s
.596 1 0 r
.60135 .5 m
.58446 .5 L
s
.44 1 0 r
.58446 .5 m
.60135 .5 L
s
.284 1 0 r
.60135 .5 m
.58446 .5 L
s
.128 1 0 r
.58446 .5 m
.60135 .5 L
s
0 1 .028 r
.60135 .5 m
.58446 .5 L
s
0 1 .184 r
.58446 .5 m
.60135 .5 L
s
0 1 .34 r
.60135 .5 m
.58446 .5 L
s
0 1 .496 r
.58446 .5 m
.60135 .5 L
s
0 1 .652 r
.60135 .5 m
.58446 .5 L
s
0 1 .808 r
.58446 .5 m
.60135 .5 L
s
0 1 .964 r
.60135 .5 m
.58446 .5 L
s
0 .88 1 r
.58446 .5 m
.60135 .5 L
s
0 .724 1 r
.60135 .5 m
.58446 .5 L
s
0 .568 1 r
.58446 .5 m
.60135 .5 L
s
0 .412 1 r
.60135 .5 m
.58446 .5 L
s
0 .256 1 r
.58446 .5 m
.60135 .5 L
s
0 .1 1 r
.60135 .5 m
.58446 .5 L
s
.056 0 1 r
.58446 .5 m
.60135 .5 L
s
.212 0 1 r
.60135 .5 m
.58446 .5 L
s
.368 0 1 r
.58446 .5 m
.60135 .5 L
s
.524 0 1 r
.60135 .5 m
.58446 .5 L
s
% End of Graphics
MathPictureEnd
\
\>"], "Graphics",
 ImageSize->{322, 322},
 ImageMargins->{{243, 0}, {0, 79}},
 AnimationDisplayTime->0.28561,
 AnimationCycleOffset->1,
 AnimationCycleRepetitions->Infinity]
share|improve this question
2  
i noticed that if you hold Ctrl, a crosshairs appears and you can shoot tiny bullet holes into the cell (they look like points, but i know bullet holes when i see them). and if you right-click copy and paste, you get the {x,y} coordinates of the bullet holes. it looks like some internal EventHandler construction that dynamically updates the ImageMargins. not hard to do yourself if that's all you're after. e.g. Graphics[Disk[], ImageSize -> {50, 50}, ImageMargins -> {Dynamic[MousePosition["CellContentsAbsolute"]] - 25, {0, 0}}]. –  amr May 5 '13 at 5:21
    
@amr you are careful, I've tried many times without noticed this thing. When FullForm the image, comes Graphics[List[List[GrayLevel[1],Polygon[List[List[0,219],List[800,219],List[800‌​,‌​0],List[0,0]]]],Raster[List[List[List[1,1,1],List[1,1,1],List[1,1,1],List[1,1,‌​1],‌​List[1,1,1],List[1,1,1],<<522>>,List[1,1,1],List[1,1,1],List[1,1,1],List[1,1‌​,1],L‌​ist[1,1,1]],<<144>>,<<1>>]... –  HyperGroups May 5 '13 at 5:38
    
You can see that it is a postscript file -- this is a graphics format, something like pdf. Here's a tutorial that talks about GraohicsData: reference.wolfram.com/mathematica/tutorial/… –  bill s May 19 '13 at 17:13
add comment

2 Answers

up vote 9 down vote accepted

Mathematica's abbreviated PostScript

What you see after pressing Ctrl + Shift + E in this case is Mathematica's abbreviated PostScript code. You can find some information about it in MathGroups archives:

Mathematica abbreviated PostScript

This is the PostScript that is understood by the notebook front end and is generated by the Mathematica kernel when it is asked to display a graphic. It contains a lot of abbreivated PostScript operators to reduce the size of the PostScript string stored by the front end. In order for PostScript interpreters to understand Mathematica-generated PostScript, some translation must be done that adds all of the macro definitions. In the old days, this was done by the shell script psfix and the DOS program RASTERPS.EXE. Nowadays, both the front end and the kernel have ways of doing this directly.

In Mathematica versions prior to v.8 it was possible to generate Mathematica's abbreviated PostScript code by exporting to "APS" or "MPS" format, but starting from v.8 they are not recognized anymore by ExportString and DisplayString. DisplayString still converts Graphics to EPS although axes are lost in the rendered graphic:

CellPrint@
 Cell[GraphicsData["PostScript", 
   DisplayString[Plot[Sin[x], {x, -Pi, Pi}]]]]

screenshot

The same is applicable to exporting to EPS:

CellPrint@
 Cell@GraphicsData["PostScript", 
   ExportString[Plot[Sin[x], {x, -Pi, Pi}], "EPS"]]

One can try to fix this by converting axes to exact graphical primitives:

fix = First[ImportString[ExportString[#, "PDF"], "PDF"]] &;
CellPrint@
 Cell@GraphicsData["PostScript", 
   ExportString[fix@Plot[Sin[x], {x, -Pi, Pi}], "EPS"]]

screenshot

But as one can see FrontEnd renders the EPS code incorrectly.

In Mathematica prior to v.6 it was also possible to convert any Cell to Mathematica's abbreviated PostScript by the FrontEnd menu entry Cell -> Convert To -> PostScript. Starting from v.6 it is still possible to do it programmatically:

Plot[Sin[x], {x, -Pi, Pi}]
SelectionMove[EvaluationNotebook[], Previous, CellContents];
FrontEndExecute[
  FrontEndToken[EvaluationNotebook[], "SelectionConvert", 
   "PostScript"]];

screenshot

Fortunately, now everything is rendered nicely!

Metafile (under Windows) and PDF (under OS X)

Some other formats supported by GraphicsData are "MetaFile" (only under Windows) and "PDF" (only under OS X). You can convert any Graphics to one of these formats by selecting it and choosing the corresponding FrontEnd menu entry under Cell -> Convert To. The Metafile graphics produced is movable as PostScript. Note however that such graphics will be rendered only under OS which supports it.

share|improve this answer
    
I hope you get a Necromancer badge for this. –  Mr.Wizard Sep 23 '13 at 9:48
    
I see that you did. –  Mr.Wizard Sep 25 '13 at 16:40
add comment

I think the coding you are seeing is the pdf encoding of the image, not a property of the cell. If you take an image (like a png) and do a "Save Image As" to the pdf format, then when you drag it back in, it can be moved with the mouse.

I guessed this by looking at the FullForm of one of the images in the tutorial page, which starts out:

RawBoxes[Cell[GraphicsData["PDF", .... 
share|improve this answer
    
strange, in my Mathematica, FullForm the images in the tutorial cell gives a grapihcs structure. Graphics[List[List[GrayLevel[1],Polygon[List[List[0,219],List[800,219],List[800,‌​0],List[0,0]]]],Raster[List[List[List[1,1,1],List[1,1,1],List[1,1,1],List[1,1,1],‌​List[1,1,1],List[1,1,1],<<522>>,List[1,1,1],List[1,1,1],List[1,1,1],List[1,1,1],L‌​ist[1,1,1]],<<144>>,<<1>>]... when I dragged pdf in the cell, its a {image} but still can't be moved –  HyperGroups May 5 '13 at 5:35
    
Interesting... maybe it's version dependent? I'm using 9.01 with mac os 10.6.8. BTW -- the image I got the pdf form for was the very top one that starts out "First Section"... –  bill s May 5 '13 at 6:29
    
Here's exactly what I did. Click on the image and copy (command c). Go to a new notebook and type FullForm[ ] in an empty cell. Now paste (command v) the graphic into the FullForm and evaluate the cell. The output of this operation is the line above with the "PDF" and then a long text string with stuff that starts out "9E14ARda;S@:9@00... –  bill s May 5 '13 at 6:58
    
Well, it may be caused by the difference of the enviroment, mine are windows 8 x64 –  HyperGroups May 5 '13 at 8:59
add comment

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.