Skip to main content
added 357 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

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 do FrontEnd`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]

screenshot

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 do FrontEnd`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 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], 
      "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

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 do FrontEnd`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]], "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]

screenshot

added 399 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

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 do FrontEnd`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 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], 
      "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

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 do FrontEnd`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 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], 
      "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

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 do FrontEnd`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 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], 
      "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
added 24 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

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 do FrontEnd`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 13.18.0.4 on Windows 10 x64 show that FrontEnd returns a non-raterized version. The exact forms of the expressionexpressions returned differ between versions, but in the bothall cases it returnsis a Graphics containing graphics directive RGBColor[1, 0.33, 0.33] as the first element of two expressionssuccessive sublists on the first level. Hence we can write a test:

hasErrorBoxQ[expr_] := 
 MatchQ[ToExpression[
    FrontEndExecute[
     FrontEnd`ExportPacket[Cell[BoxData@ToBoxes[expr], CellOpen -> False], 
      "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

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 do FrontEnd`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 12.3.1 and 13.1.0 show that FrontEnd returns a non-raterized version. The exact forms of the expression returned differ between versions, but in the both cases it returns a Graphics containing graphics directive RGBColor[1, 0.33, 0.33] as the first element of two expressions on the first level. Hence we can write a test:

hasErrorBoxQ[expr_] := 
 MatchQ[ToExpression[
    FrontEndExecute[
     FrontEnd`ExportPacket[Cell[BoxData@ToBoxes[expr], CellOpen -> False], 
      "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

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 do FrontEnd`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 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], 
      "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
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading