有没有办法使用 Open Type 字体在纯 HTML/CSS 中呈现 TeX 公式?

有没有办法使用 Open Type 字体在纯 HTML/CSS 中呈现 TeX 公式?

有没有一种方法可以将 TeX 文档转换为 HTML,而不是依赖 JavaScript、SVG、HTML Canvas 或图像来渲染公式,而仅仅依赖 HTML、CSS 和 OTF 字体?

[有哪些 OpenType Math 字体可用?]列出的许多字体都带有数学符号和字形,但是是否有任何 OTF 智能字体可以使用连字、变体、大写字母、花饰,或许借助一些额外的 CSS 等,将其渲染$\sum_i^j为 $\sum_i^j$ 或$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$$\sum_{i=0}^ni^2 = \frac{(n^2+n)(2n+1)}{6}$?

答案1

是的,使用该dvisvgm工具,您可以将 TeX 的 DVI 输出渲染为 SVG。例如

\documentclass{article}
\pagestyle{empty}
\begin{document}
\[ R_{\mu\nu} - \frac{1}{2} R g_{\mu\nu} + \Lambda g_{\mu\nu} = \frac{8 \pi G}{c^4} T_{\mu\nu} \]
\end{document}

然后运行

$ pdflatex --output-format=dvi test.tex
$ dvisvgm --font-format=woff test.dvi

这将为您提供以下 SVG 输出。字体已以 base 64 子集嵌入。

<?xml version='1.0' encoding='UTF-8'?>
<!-- This file was generated by dvisvgm 2.6.3 -->
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='142.407868pt' height='20.381467pt' viewBox='162.170942 73.723525 142.407868 20.381467'>
<style type='text/css'>
<![CDATA[
@font-face{font-family:cmsy10;src:url(data:application/x-font-woff;base64,d09GRgABAAAAAAPQAA0AAAAABRQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABoAAAAchZ9Z609TLzIAAAFMAAAAQwAAAFZ2Q39nY21hcAAAAZAAAAA+AAABQgAPJb1jdnQgAAAB0AAAAAQAAAAEACEBnWdhc3AAAAHUAAAACAAAAAj//wADZ2x5ZgAAAdwAAACJAAAAkMWFZmpoZWFkAAACaAAAADIA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jYGRgYABiz6Xr4+L5bb4ycDO/AIow3PhiuxJOK/7XYmpjmgXkcjAwgUQBYuIMbwAAAHjaY2BkYGCa9V+LIYppGwPD/49MbQxAERTACgCFKAVXAWwAIQAAAAABTQAAArYAMgI8AEkAAAAqACoAKgCMANB42mNgZGBgYGVwZ2BiAAEQycgAEnNg0AMJAAAKwwDCAHjaRY1LCsIwGIQ/rW9BXInLXKClLRTRlSsP4MKFO5FYCn1A1JXH8AAewEs6LQETfub7yWQGmHCjR3v6jFl6DjCcPQ+Z8/Y80vbVa28wlX/ROVsO2LP2PGTFy/OIGR+OWHKelFxwcLT5s7wIDjTUPDp1cli1pkTE0p3mSqVbsPF7RthNKkfCVgFN/Tg0LrcmjWKzM9eqKjbSLMzCNE7kOCnUcVdIW2X0rY3nZN29aGqTRFr+NXQB/AAlxyYUeNpjYGLAD1iBmJGBiWE6IxNTXikABdkBigAAAA==) format('woff');}
@font-face{font-family:cmr7;src:url(data:application/x-font-woff;base64,d09GRgABAAAAAAP4AA0AAAAABTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABoAAAAchZ9Z609TLzIAAAFMAAAAQAAAAFZVWl7OY21hcAAAAYwAAABBAAABQgAPBt9jdnQgAAAB0AAAAAQAAAAEACECeWdhc3AAAAHUAAAACAAAAAj//wADZ2x5ZgAAAdwAAAC4AAAAuCNJHkxoZWFkAAAClAAAADEAAAA2Ezi+2WhoZWEAAALIAAAAHgAAACQFDgI+aG10eAAAAugAAAAQAAAAEAarAEhsb2NhAAAC+AAAAAoAAAAKAIYAVG1heHAAAAMEAAAAHwAAACAASABRbmFtZQAAAyQAAAC6AAABEZ36PrZwb3N0AAAD4AAAABYAAAAqAB4AA3jaY2BgYGQAgsvb7s0A0Te+2K6E0QBcNQhlAAB42mNgZLJknMDAysDA1MW0h4GBoQdCMz5gMGRkAooysHIywAAjAxIISHNNAVImDCZM7/6zMUQxLUKoAQC6ZAnUeNpjYGBgZoBgGQZGBhCwAfIYwXwWBgUgzQKEIL7J//8Q8v95qEoGRjYGGJOBkQlIMDGgAkYGrICZYfgAAHjKBvEAAAAAIQJ5AAAAAf//AAIAAgAhAAABKgKaAAMABwAusQEALzyyBwQA7TKxBgXcPLIDAgDtMgCxAwAvPLIFBADtMrIHBgH8PLIBAgDtMjMRIREnMxEjIQEJ6MfHApr9ZiECWAAAAgAnAAACEQKiABwAHwAAJTUjETQuASMiBwEVIRUUBisBFTYzMhc1IyImPQEDESECEW8CCQsQCv61ASYYORtkMjNkGzkYTv74pCQBvgwKBg7+NCRSHBIkBAQkEhxSAZL+kgAAeNpjYGRgYABi6cdtB+P5bb4ycDO/AIow3PhiuxJOKzIwMAkyLQJyORiYQKIAVxoLIwAAAHjaY2BkYGBaxMDAEMVkCSQZmAQZGBlQAQsAJOgBUwAAAjkAIQAAAAACOQAAAjkAJwAAACoAKgAqAFwAAHjaY2BkYGBgYVBgYGIAARDJyAASc2DQAwkAAAbZAJoAeNo1jc0KglAQhT9T+yGIVtGu+wKKCiK1aNkDuIi2ETcR/IGrQo/RA7TuORvldmE439w5ZwZY8sRhfDMWbC27HLhZ9lnztjzH4ytTx1uJfzM5R3Y5s7fss+NleS77P+RoCgYq7hjIdTFUd4ELLQ39pEYcGkVCSCR6knpQy39mu5RgqkTmMUeJt01/aU2hVRJG6qQetclE0iANkigWw1U2GjrK6Y6S1LibqzZd2TYqDqX532BM8wMldiRuAAB42mNgYkAGjAzogAUsysQgDgAA3QAiAAA=) format('woff');}
@font-face{font-family:cmmi10;src:url(data:application/x-font-woff;base64,d09GRgABAAAAAAeQAA0AAAAACbwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABoAAAAchZ9Z609TLzIAAAFMAAAARQAAAFZWumKTY21hcAAAAZQAAABpAAABagwjBq1jdnQgAAACAAAAAAQAAAAEACECeWdhc3AAAAIEAAAACAAAAAj//wADZ2x5ZgAAAgwAAAP2AAAE7Cv45SRoZWFkAAAGBAAAADIAAAA2FA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LA03NrpRGFQZCSkMjfSJ2qpCv3b5MRtZ7LRrMXCNreddaVRWZKqjTrVdaU95HEeZ6kWSSG+jqv4+DQl/3wChXHXyjZKJ3L5T+LrwQcByCbSAAB42mNgYsAPOIGYkYGJQYvBlMGcwY3Bi2E2AAlxAdAAAA==) format('woff');}
text.f0 {font-family:cmsy10;font-size:9.96264px}
text.f1 {font-family:cmmi10;font-size:9.96264px}
text.f2 {font-family:cmmi7;font-size:6.973848px}
text.f3 {font-family:cmr10;font-size:9.96264px}
text.f4 {font-family:cmr7;font-size:6.973848px}
]]>
</style>
<g id='page1'>
<text class='f1' x='162.170942' y='87.271122'>R</text>
<text class='f2' x='169.735473' y='88.765503'>µν</text>
<text class='f0' x='181.750627' y='87.271122'>−</text>
<text class='f3' x='192.908754' y='80.531321'>1</text>
<rect x='192.908754' y='84.581212' height='0.398484' width='4.981335'/>
<text class='f3' x='192.908754' y='94.104992'>2</text>
<text class='f1' x='199.085603' y='87.271122'>R<tspan x='206.7271'>g</tspan>
</text>
<text class='f2' x='211.478968' y='88.765503'>µν</text>
<text class='f3' x='223.494123' y='87.271122'>+<tspan x='233.456736'>Λ</tspan>
</text>
<text class='f1' x='240.375248' y='87.271122'>g</text>
<text class='f2' x='245.127116' y='88.765503'>µν</text>
<text class='f3' x='257.695737' y='87.271122'>=<tspan x='269.407331' y='80.531321'>8</tspan>
</text>
<text class='f1' x='274.38867' y='80.531321'>π<tspan x='280.425087'>G</tspan>
</text>
<rect x='269.407331' y='84.581212' height='0.398484' width='18.850864'/>
<text class='f1' x='274.442389' y='94.104992'>c</text>
<text class='f4' x='278.753786' y='91.226899'>4</text>
<text class='f1' x='289.453708' y='87.271122'>T</text>
<text class='f2' x='295.275639' y='88.765503'>µν</text>
</g>
</svg>

相关内容