如何让MathJax方程在href中正确渲染?

问题描述 投票:0回答:1

我想创建一个包含方程式的超链接。我使用 MathJax 来计算方程。包含方程的链接部分没有下划线。

这是一个最小的例子:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

</head>
<body>
<a href="some link">Hello world \(2 + 2 =4\) (note that the equation is not underlined)</a>
</body>
</html>

它是这样的:

html css href mathjax mathml
1个回答
0
投票

在数学方程下划线并不容易,因为如果它们包含下标,它们可能会低于基线很多。浏览器仅在排版了链接的其余部分后才排版方程,因此它还不知道在绘制下划线时方程将低于基线多少。为了安全起见,它根本不强调方程。 (请注意,下划线也有一个间隙,其中“q”下降到基线以下。)

您可以根据具体情况决定下划线降低多少。以下示例通过使用填充和底部边框来实现此目的(您可能需要

a:visited
使用不同的颜色来指示链接是否已被访问)。

a { text-decoration: none; padding-bottom: 2px; border-bottom: solid 1px blue; }
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<a href="some link">Hello world \(\log_2(2 + 2) = 2\) (note that the equation is now underlined)</a>

© www.soinside.com 2019 - 2024. All rights reserved.