I would have thought something using
FrontEnd`ExportPacket[BoxData@ToBoxes[...]],"InputForm"]
would work (as used here), but the front-end just returns a default image size. If you doFrontEnd`ExportPacket[BoxData@ToBoxes[Graphics[Inset[...]]]],"InputForm"]
instead, you do kind of get the pink boxes back, but the whole thing is rasterized. Maybe someone can come up with a robust way of identifying rasterized pink boxes? – Lukas Lang
My experiments with versions 13.1.0, 12.3.1 and 8.0.4 on Windows 10 x64 show that in the most cases FrontEnd returns a non-raterized version. The exact forms of the expressions returned differ between versions, but in all cases it is a Graphics
containing graphics directive RGBColor[1, 0.33, 0.33]
as the first element of two successive sublists on the first level. Hence we can write a test:
hasErrorBoxQ[expr_] :=
MatchQ[ToExpression[
FrontEndExecute[
FrontEnd`ExportPacket[Cell[BoxData@ToBoxes[expr], CellOpen -> False]FrontEnd`ExportPacket[Cell[BoxData@ToBoxes[expr]],
"InputForm"]]][[1, 1]],
{___, {RGBColor[1, 0.33, 0.33], _Opacity, ___, (_Polygon | _FilledCurve)}, ___}]
hasErrorBoxQ[cell_Cell] :=
MatchQ[ToExpression[FrontEndExecute[FrontEnd`ExportPacket[cell, "InputForm"]]][[1, 1]],
{___, {RGBColor[1, 0.33, 0.33], _Opacity, ___, (_Polygon | _FilledCurve)}, ___}]
Testing:
hasErrorBoxQ@Framed[x, FrameMargins -> fish]
hasErrorBoxQ@Framed[x, FrameMargins -> 1]
True
False
hasErrorBoxQ@Image[RandomImage[10], ImageSize -> x]
hasErrorBoxQ@Image[RandomImage[10], ImageSize -> 1]
True
False
hasErrorBoxQ@Cell[BoxData[SuperscriptBox["1", "2", "3"]], "Output"]
hasErrorBoxQ@Cell[BoxData[SuperscriptBox["1", "2"]], "Output"]
True
False
There are cases when this approach fails, apparently because for some reason FrontEnd doesn't display the pink box, but only the pink banner, which isn't exported:
Graphics[Polygon[{{-1, 0}, {1, 0}, {0, Sqrt[3]}}, VertexColors -> {Red, Green, Blue}],
ImageSize -> x]