在元素附加到DOM之前排版MathJax [英] Typeset MathJax before element attaching to DOM

查看:149
本文介绍了在元素附加到DOM之前排版MathJax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我使用BackboneJs框架来呈现html视图.包含MathML代码的html元素需要某种方式由MathJax进行排版,以便在附加到DOM之前获取HTML-CSS代码.

Due to the fact I use the BackboneJs framework to render html views. The html elements containing the MathML codes somehow need to be used by MathJax to typeset in order to get the HTML-CSS code before attaching to the DOM.

我尝试在元素绑定到DOM之前进行类型集设置,但是效果并不理想.即使MathJax正在处理未附加的html元素,元素中的mathml出现在DOM中也无法呈现.

I have tried to do the typesets before the elements attching to the DOM, but it didn't work quite well. Even the MathJax was processing the unattached html elements, the mathml inside the elements couldn't be rendered after appeared in the DOM.

在将目标元素附加到DOM之后,我是否必须对MathML进行排版? 还是有一些解决方法可以在附加到DOM之前进行类型设置?

Do I have to do the Typeset for the MathML after the target elements were attached to the DOM? Or there are workarounds to do the typesets before attaching to the DOM?

推荐答案

元素必须附加到DOM. MathJax需要能够测量各种子表达式(以便可以布置分数等),并且为此,数学的容器元素必须位于活动的DOM中. (未附加到DOM的元素没有计算出offsetWidth之类的内容,因此MathJax无法确定它们的大小.)

The elements must be attached to the DOM. MathJax needs to be able to measure the various subexpressions (so it can lay out things like fractions, etc.) and in order to do that, the container element for the mathematics must be in an active DOM. (Elements that aren't attached to the DOM don't have things like offsetWidth calculated, so MathJax can't tell how big they are.)

如果要在元素显示前设置数学排版,可以将其附加到DOM并设置visibility:noneposition:absolute,然后调用MathJax对元素进行排版,然后删除可见性和位置设置.不要使用display:none,因为这也会阻止MathJax测量元素.

If you want to have the mathematics typeset in an element before it is displayed, you can attach it to the DOM and set visibility:none and position:absolute, then call MathJax to typeset the element, and then remove the visibility and position settings. Don't use display:none, as that also prevents MathJax from measuring elements.

请参见示例摘自2013年1月的联合数学会议上我对此的演讲.

See the examples from a talk I gave about this at the Joint Math Meetings in January 2013.

这篇关于在元素附加到DOM之前排版MathJax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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