agrbin / svgtex

Using MathJax and PhantomJS to create SVGs on server side with minimum overhead.
MIT License
70 stars 59 forks source link

repeated xlink:href on 'use' elements #12

Open tiarno opened 9 years ago

tiarno commented 9 years ago

The SVG result contains 'use' elements that have duplicate xlink:href elements. That is, using two terminal windows (this is win7)

  1. phantomjs.exe main.js
  2. wget http://localhost:16000/?q=x+e -O test.svg

The resulting SVG has 'use' elements like this:

<use xlink:href="#MJMATHI-78" x="0" y="0" xlink:href="#MJMATHI-78">

What I did to fix it was to replace line 73 in engine.js, which inserts the attribute, with this conditional block:

  if (uses[k]["href"] === undefined) {
      uses[k].setAttribute("xlink:href", id);
  }
agrbin commented 9 years ago

Hello tiarno, thanks for the heads up. Would you mind sending me a pull request for this change, so I can just approve it?

tiarno commented 9 years ago

hi agrbin, I will send a pull request soon; my fork has some issues right now but I'll be back in touch soon, and it will have just the one fix. thx.

stroobandt commented 9 years ago

This "fix" has caused a major regression and rendered svgtex completely useless on GNU/Linux (Xubuntu LTS 14.04). On all my browsers (Firefox, Chrome, etc.), I now only see one or more horizontal lines instead of any formula. Reverting https://github.com/agrbin/svgtex/commit/baacbe9c990fd8d73f357e849acae92c4ed8b23e fixes the problem.

tiarno commented 9 years ago

Sorry for the trouble and glad you could revert. I will follow up after some research. I was validating the elements according to http://www.w3.org/TR/SVG11/struct.html#UseElementHrefAttribute which worked on my windows box. It doesn't make sense to me for an xlink to have multiple hrefs; once I have a fix that works for linux as well I'll repost for consideration.

tiarno commented 9 years ago

As far as I can tell, it is an error to have multiple hrefs. http://www.w3.org/TR/xlink11/ With @serge-stroobandt's results, my guess is that the code I submitted creates another error while fixing the multiple href problem.

stroobandt commented 9 years ago

@tiarno You are welcome. I have no problem at all with sticking to standards, but it has to work. Unfortunately, I am not an expert at all on SVG nor xlink. So, I am afraid I cannot really tell you what is going wrong, apart from not seeing any formulas at all in my browsers, only a few horizontal lines despite a succesful svgtex run. Do you have capability for testing on Linux?

tiarno commented 9 years ago

@serge-stroobandt : no argument here--working is the first thing the code has to do regardless of validation. I cannot test on Linux, but I can on Mac and Windows. I will play around with it and make sure it will work on all platforms before another pull request. Sorry for the trouble.