Assuming each odd line is input I would like the even lines to be the output of the following lines.
In the above the Graphics
are inside Hold
/HoldForm
therefore IMO it doesn't make sense to have Mathematica try and render such expressions. For example Hold[Graphics[{Red, Circle[]}]]
throws an error because built in colors don't get replaced.
How might I prevent Graphics
from being rendered and instead print the Graphics code?
The following code works at reassigning Graphics inside Hold/HoldForm, but it prints something like Graphics[{Circle[{0, 0}]}]
without the HoldForm
/Hold
.
Unprotect[Graphics]
Graphics /: HoldForm[Graphics[x___]] := (
InputForm[Graphics[x]]
);
Graphics /: Hold[Graphics[x___]] := (
InputForm[Graphics[x]]
);
Ideally the code should be generalized to work with irregular constructs like HoldForm["a",Graphics[{Circle[{0, 0}]}]]
. More importantly, how might you insure HoldComplete
doesn't render Graphics either. As rm-rf pointed out the Villegas–Gayley trick will likely be needed.
Simplifying John Fultz's answer slightly, you get the following:
Map[
(
Unprotect[#];
# /: MakeBoxes[#[expr_], fmt : StandardForm | TraditionalForm] :=
Block[{Graphics, Graphics3D},
RowBox[{ToString[#], "[", MakeBoxes[expr, fmt], "]"}]
];
Protect[#]
) &, {Hold, HoldForm, HoldComplete}
]
ToString[#, InputForm] &@Graphics[{Red, Circle[]}]
$\endgroup$ – Kuba♦ Sep 14 '13 at 0:32graphics
instead ofGraphics
and replace when it's time to render. $\endgroup$ – ssch Sep 14 '13 at 0:39Graphics
. As I see it, solving your problem requires changing the way the fonte end's output printer works. I don't have a clue on to do that. $\endgroup$ – m_goldberg Sep 14 '13 at 1:50