[英]How would I add custom SVG shapes to an equation generated with MathJax?
I'd like to use MathJax to write various equations that include SVG shapes along the lines of the following: 我想使用MathJax编写包含以下内容的各种方程,其中包括SVG形状:
(2 * [red box]) + [red box] = [three red boxes]
Where each item in brackets would be a custom SVG element defined in the HTML ranging from simple (a single box) to more complex (multiple shapes). 括号中的每个项目都是HTML中定义的自定义SVG元素,范围从简单(单个框)到更复杂(多个形状)。 The reason for needing this is that I want to use MathJax's ability to format math equations while replacing some symbols with SVG shapes.
之所以需要这样做,是因为我想使用MathJax的功能来格式化数学方程式,同时用SVG形状替换一些符号。 I may need to specify other HTML as well.
我可能还需要指定其他HTML。
I suspect this can be achieved by using MathJax's HTML snippets but I don't know how to take the sample code they provide and make it work for any given equation. 我怀疑这可以通过使用MathJax的HTML代码段来实现,但我不知道如何获取它们提供的示例代码并使之适用于任何给定的方程式。
Any help would be greatly appreciated. 任何帮助将不胜感激。
If you are using MathML input, you can use the <mglyph>
element to include an svg image into your expression, as in: 如果使用的是MathML输入,则可以使用
<mglyph>
元素在表达式中包含svg图像,如下所示:
<math>
<mglyph src="dice.svg" height="42px" width="42px" valign="-14px" alt="Dice showing five dots"></mglyph>
</math>
or even 甚至
<math>
<mglyph src='data:image/svg+xml,
<svg xmlns="http://www.w3.org/2000/svg" height="42px" width="42px">
<rect stroke="black" fill="none" x="1px" y="1px" stroke-width="2px" rx="5px" width="40px" height="40px"></rect>
<circle stroke="black" fill="black" cy="30px" cx="30px" r="5px"></circle>
<circle stroke="black" fill="black" cy="30px" cx="10px" r="5px"></circle>
<circle stroke="black" fill="black" cy="20px" cx="20px" r="5px"></circle>
<circle stroke="black" fill="black" cy="10px" cx="30px" r="5px"></circle>
<circle stroke="black" fill="black" cy="10px" cx="10px" r="5px"></circle>
</svg>'
valign="-14px"
alt="Dice showing five dots">
</mglyph>
</math>
If you are using TeX input, you can create the mglyph using the \\mmlToken
macro: 如果使用的是TeX输入,则可以使用
\\mmlToken
宏创建\\mmlToken
:
\mmlToken{mglyph}[src="dice.svg" width="42px" height="42px" valign="-14px" alt="Dice showing five dots"]{}
You can also use the "img" extension from the third-party extension library. 您也可以使用第三方扩展库中的“ img”扩展名。 This defines an
\\img
macro that makes loading the image a bit easier: 这定义了一个
\\img
宏,它使加载图像更加容易:
\img[-14px][42px][42px]{dice.svg}
I think you should be able to do what you want using one of those. 我认为您应该能够使用其中之一来做您想做的事情。 (This is my response to the cross-post on the MathJax User's Forum )
(这是我对MathJax用户论坛上的交叉帖子的回复)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.