在SVG文件中渲染MathJax [英] Render MathJax in an SVG file

查看:106
本文介绍了在SVG文件中渲染MathJax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了几天的时间,没有高兴.

I have spent a few days on the following with no joy.

我希望将Mathjax渲染为SVG文件.我没有问题,可以使用 https://groups.google.com/forum/#!topic/mathjax-users/_UMt3C7TIpQ/discussion ,但我无法在svg文件中使用它.

I wish to render Mathjax in an SVG file. I have no problem including it in a html file in an svg element using a foreignObject from the examples at https://groups.google.com/forum/#!topic/mathjax-users/_UMt3C7TIpQ/discussion, but I cannot get it to work in an svg file.

我正在尝试的代码如下:-

The code I am trying is as follows :-

<svg width="1960" height="1080" xmlns="http://www.w3.org/2000/svg">
<script type="text/javascript" src="MathJax-master/MathJax.js?config=TeX-AMS_HTML-SVG"></script>
<g>
<title>Layer 1</title>
<text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="50" id="svg_1" y="223" x="636" stroke-opacity="0.8" stroke-width="0" stroke="#007FFF" fill="#000000">Hello World</text>
<foreignObject x="100" y="100" width="100" height="100">
   <body xmlns="http://www.w3.org/2000/svg">
     <div>
       \(\displaystyle{x+1\over y-1}\)
     </div>
   </body>
 </foreignObject>
</g>
</svg>

任何帮助将不胜感激.我确实怀疑问题出在声明body元素的行上.

Any help would be much appreciated. I do suspect the problem is with the line declaring the body element.

推荐答案

< div> 标记为html,因此< body> 标记应位于html名称空间 xmlns ="http://www.w3.org/1999/xhtml" 而不是svg名称空间.

A <div> tag is html so the <body> tag should be in the html namespace xmlns="http://www.w3.org/1999/xhtml" rather than the svg namespace.

您的另一个错误是您正在对脚本标记使用html语法.SVG脚本标签使用xlink:href而不是src属性.解决问题的方法:

Your other mistake is that you're using html syntax for the script tag. SVG script tags use xlink:href instead of a src attribute. Fixing that gets us here:

<svg width="1960" height="1080" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<script xlink:href="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<g>
<title>Layer 1</title>
<text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="50" id="svg_1" y="223" x="636" stroke-opacity="0.8" stroke-width="0" 

stroke="#007FFF" fill="#000000">Hello World</text>
<foreignObject x="100" y="100" width="100" height="100">
   <body xmlns="http://www.w3.org/1999/xhtml">
     <div>
       \(\displaystyle{x+1\over y-1}\)
     </div>
   </body>
 </foreignObject>
</g>
</svg>

但是,当我们这样做时,我们在mathjax库中遇到了一个错误.似乎希望在文档中找到html节点(请检查Firefox错误控制台).您必须联系mathjax开发人员,并让他们修复其错误才能进一步发展.

But when we do that we run into a bug in the mathjax library. It seems it expects to find html nodes in the document (check the Firefox Error Console). You'd have to contact the mathjax developers and get them to fix their bug to progress further.

这篇关于在SVG文件中渲染MathJax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆