I am trying to implement a function that takes a Graphics
instruction as its argument and then duplicated it in a new InputCell
. I'm aware about the render of Graphics
is typesetting process as explained here. And use the techniques in that post I came up with the following
Unprotect@Hold;
mk : MakeBoxes[Blank[Hold], _] /; ! TrueQ[$hldGfx] ^:=
Block[{$hldGfx = True, Graphics, Graphics3D}, mk];
Protect@Hold;
SetAttributes[printGraphics, HoldFirst];
printGraphics[graphics_] :=
CellPrint[Cell[BoxData[RowBox[{
ToBoxes[Hold[graphics]]
}]], "Input"]]
RunningprintGraphics@Graphics[{Red, Disk[]}]
will create a cell with Hold[Graphics[{Red, Disk[]}]]
.
My question is that if it's possible to create a cell without Hold
.
If you are interested in the reason I need this, here is the functionality I'm working on: see Section Minimal example in here (Github: PrettyColorize). Plot
, Plot3D
or other plotting function can be easily printed while Graphics
and Graphics3D
are a little tricky and I'm not sure how to get over.
Unevaluated
instead ofHold
when callingToBoxes
. That should be all you need. $\endgroup$MakeBoxes
is probably a bit more than you want if you can control thePrint
$\endgroup$