MathJax: Re-render on viewer resize to workaround lack of dynamic reflow with SVG output

This commit is contained in:
Kovid Goyal 2012-08-19 11:23:05 +05:30
parent 5dbbf145af
commit 253a5ed165
3 changed files with 16 additions and 2 deletions

Binary file not shown.

View File

@ -21,6 +21,7 @@ class MathJax
this.math_present = false
this.math_loaded = false
this.pending_cfi = null
this.hub = null
load_mathjax: (script) ->
if this.base == null
@ -35,15 +36,19 @@ class MathJax
script.type = 'text/javascript'
script.src = 'file://' + this.base + '/MathJax.js'
script.text = '''
script.text = script.text + '''
MathJax.Hub.Config({
positionToHash: false,
showMathMenu: false,
extensions: ["tex2jax.js","asciimath2jax.js","mml2jax.js"],
jax: ["input/TeX","input/MathML","input/AsciiMath","output/SVG"]
jax: ["input/TeX","input/MathML","input/AsciiMath","output/SVG"],
TeX: {
extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]
}
});
MathJax.Hub.Startup.onload();
MathJax.Hub.Register.StartupHook("End", window.mathjax.load_finished);
window.mathjax.hub = MathJax.Hub
'''
if created
@ -71,6 +76,14 @@ class MathJax
this.math_present = true
this.load_mathjax(script)
after_resize: () ->
if not this.math_present or this.hub == null
return
# SVG output does not dynamically reflow on resize, so we manually
# rerender, this is slow, but neccessary for tables and equation
# numbers.
this.hub.Queue(["Rerender",this.hub])
if window?
window.mathjax = new MathJax()

View File

@ -280,6 +280,7 @@ class Document(QWebPage): # {{{
if self.in_paged_mode:
self.setPreferredContentsSize(QSize())
self.switch_to_paged_mode(onresize=True)
self.javascript('window.mathjax.after_resize()')
def switch_to_fullscreen_mode(self):
self.in_fullscreen_mode = True