Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Suppose I have a Mathematica graphic such as

g = Graphics[{Disk[{-1, 0}, 1/2], Rectangle[]}]

square and circle

I would like to be able to export this graphic from Mathematica as a SVG file. I also want to set attributes for the SVG elements that represent the circle and the square. Is this possible?

I create my SVG file with

ExportString[g, "SVG"]
<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>
  <g transform='translate(-74.000000, -13.000000)'>
    <g transform='matrix(1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000)' clip-path='url(#cp1)'>
      <clipPath id='cp1'>
        <polygon points='-2.2518e+15,-2.2518e+15 -2.2518e+15,2.2518e+15 2.2518e+15,2.2518e+15 2.2518e+15,-2.2518e+15 '/>
      <rect fill='rgb(100%,100%,100%)' stroke='none' x='74' y='13' width='360' height='222' />
    <g transform='matrix(1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000)' clip-path='url(#cp2)'>
      <clipPath id='cp2'>
        <polygon points='74,13 74,235 434,235 434,13 '/>
      <ellipse fill='rgb(0%,0%,0%)' opacity='1' stroke='none' cx='150' cy='158' rx='68.928' ry='68.928' />
      <polygon stroke='none' opacity='1' fill-rule='evenodd' fill='rgb(0%,0%,0%)' points='287.964,157.749 287.964,19.8928 425.82,19.8928 425.82,157.749 ' />

I would like the ability to insert an id attribute in the <polygon> and <ellipse> tags. I have already tried using the Annotation but that didn't produce any difference in the result.

My real application has many more graphical objects that I plan to control from JavaScript.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.