1
$\begingroup$

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:

enter image description here

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]

enter image description here

So how can I stop mathematica from producing the Edge?

$\endgroup$
4
  • $\begingroup$ On what operating system and what Mathematica version do you observe these problems? $\endgroup$ Oct 27, 2022 at 8:26
  • $\begingroup$ I use Mathematica 12.1 on Windows 10 $\endgroup$ Oct 28, 2022 at 9:05
  • $\begingroup$ 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. $\endgroup$
    – Silvia
    Dec 6, 2022 at 8:49
  • $\begingroup$ Any ideas for a workaround? A circle does not have this issue. $\endgroup$ Dec 8, 2022 at 14:47

2 Answers 2

3
+50
$\begingroup$

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"]

Double checking in Inkscape

$\endgroup$
1
$\begingroup$

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]
$\endgroup$
1
  • 1
    $\begingroup$ If I open the exported pdf with a vector graphics program, the issue is the same. But thank you for the effort! $\endgroup$ Dec 8, 2022 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.