我在我的网站上使用MathJax,我想添加一些语义支持。
目前,我的MathJax配置是采用TeX输入并吐出HTML-CSS输出(遗憾的是MathML在Chrome中不能很好地工作)。我还有一个jQuery函数,它接受任何.latex
类的html并将其转储到title
属性中。
以下HTML ...
<div class="latex">\[ a^2 + b^2 = c^2 \]</div>
使用以下脚本...
/* jQuery */
$('.latex').attr('title', function() {
return $(this).html();
})
将输出......
<div class="latex" title="\[ a^2 + b^2 = c^2 \]">
<div class="MathJax_Display">a2+b2=c2</div> <!-- becomes prettyprint in browser -->
</div>
显然div.MathJax_Display
的内容将采用一系列跨度,类和风格进行设计。我只是不打算在这里打字。无论如何,在渲染数学后,用户可以将鼠标悬停在div.latex
上以查看工具提示中的TeX命令。
现在,我想要做的是在我的MJ配置中定义一个新的宏,它将为新创建的HTML-CSS输出范围添加title
属性,给定一些TeX输入。我们称之为宏\title[2]
。这是我想要输入的内容:
<div class="latex">\[ a^2 + b^2 = \title{c}{'hypotenuse'}^2 \]</div>
这就是我想要输出的内容:
<div class="latex" title="\[ a^2 + b^2 = \title{c}{'hypotenuse'}^2 \]">
<div class="MathJax_Display">a2+b2=<span title="hypotenuse">c</span>2</div> <!-- prettyprint -->
</div>
如果发生这种情况,将鼠标悬停在数学c
上的用户将获得一个显示“斜边”的工具提示,但将鼠标悬停在数学的任何其他区域并获得原始输入。
这是我对算法的想法:
//pseudo-code: given the TeX input '\title{mathstr}{titlestr}': var thespan = document.createElement('span'); $(thespan).attr('title', titlestr).html(mathstr); somehow put this into the MJ output at the right place
答案 0 :(得分:1)
为什么不使用定义action
和\texttip
的{{1}}扩展名来将工具提示附加到子表达式?有关详细信息,请参阅MathJax documentation。