3
$\begingroup$

The problem

Please run this in the Cloud:

StringJoin[
  ExportString[{},"SVG"]
, "<br>"
, ExportString[Plot[Sin[x],{x,0,6}],"SVG"]
]//EmbeddedHTML

enter image description here

Notice that x-axis 1 and 2 ticks were replaced with {}.

Probable cause

That is because they they are referenced within svg with e.g.:

<use xlink:href="#glyph0-2" x="130.22449" y="118.975691"></use>

and this glyph0-2 id is defined in <defs> for both svgs. Since ids are supposed to be unique only the very first one found is used in both images.

How to deal with this?

$\endgroup$
3
$\begingroup$

Do not know how general it is but works for me atm:

UniqueSVGExport[expr_]:= Module[{uniqueRef}
, uniqueRef[s_String]:=uniqueRef[s] = CreateUUID[s]
; ExportString[expr, "SVG"] // 
    StringReplace[
      g : ("glyph" ~~ DigitCharacter .. ~~ "-" ~~ DigitCharacter ..) :> uniqueRef@g
    ]
]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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