# Edges when exporting a graphic

I use a graphics primitive:

  square = Graphics[{EdgeForm[], Rectangle[{-1, -1}, {1, 1}]},
ImageSize -> 10]


And export it:

Export["square.pdf", square]


The resulting graphic in the pdf consists of both a rectangle and an edge (see image), which can be seperated in a vector-graphics software:

This leads to strange effects. Circles and Squares with the same Diameter/Edgelength are not equally big anymore. This also produces problems with Edges, as can be seen in the following example:

square = Graphics[{EdgeForm[{Red, AbsoluteThickness[1]}], Rectangle[{-1, -1}, {1, 1}]},
ImageSize -> 10]


So how can I stop mathematica from producing the Edge?

• On what operating system and what Mathematica version do you observe these problems? Commented Oct 27, 2022 at 8:26
• I use Mathematica 12.1 on Windows 10 Commented Oct 28, 2022 at 9:05
• I guess WL forgets to remove the default edge. I think this is a bug, as the issue has been fixed in some 13.2's beta testing versions. Commented Dec 6, 2022 at 8:49
• Any ideas for a workaround? A circle does not have this issue. Commented Dec 8, 2022 at 14:47

The issue seems to have been fixed in upcoming 13.2. Meanwhile, for versions with the issue, replacing Rectangle with FilledCurve seems to be a sufficient workaround.

\$Version
(*Out[]= 13.1.0 for Microsoft Windows (64-bit) (June 16, 2022)*)

orig = Graphics[{
{EdgeForm[{Red, Thickness[.1]}], Orange, Rectangle[{-2, -2}, {2, 2}]}
, {EdgeForm[{Blue, Thickness[.2]}], Cyan, Rectangle[{-1, -1} + .5, {1, 1} + .6]}
, {EdgeForm[], Gray, Rectangle[{-1, -1} - .6, {1, 1} - .3]}
}, ImageSize -> 10]

fixed = orig /. Rectangle[{xm_, ym_}, {xM_, yM_}] :>
FilledCurve[Line@{{xm, ym}, {xM, ym}, {xM, yM}, {xm, yM}}]


Exporting orig directly does exhibit the extra edge (as extra JoinedCurve) issue:

orig // RightComposition[
ExportString[#, "PDF"] &
, ImportString[#, {"PDF", "PageGraphics"}] &
, Cases[#, FilledCurve | JoinedCurve, \[Infinity], Heads -> True] &
, Tally
]
(*Out[]= {{FilledCurve, 3}, {JoinedCurve, 5}}*)


Exporting fixed seems to work:

fixed // RightComposition[
ExportString[#, "PDF"] &
, ImportString[#, {"PDF", "PageGraphics"}] &
, Cases[#, FilledCurve | JoinedCurve, \[Infinity], Heads -> True] &
, Tally
]
(*Out[]= {{FilledCurve, 3}, {JoinedCurve, 1}}*)


Double check in Inkscape:

Export["rect_to_FilledCurve.pdf", fixed, "PDF"]


In my case (Mathematica 13.1, Windows 10) it helps to specify the PlotRangeClipping and the PlotRangePadding:

square = Graphics[{EdgeForm[{Red, AbsoluteThickness[1]}], Rectangle[{-1,
-1}, {1, 1}]}, ImageSize -> 50, PlotRangeClipping -> True, PlotRangePadding
-> None]

• If I open the exported pdf with a vector graphics program, the issue is the same. But thank you for the effort! Commented Dec 8, 2022 at 14:46