mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
MathJax: Fix equation refs not scrolling to the correct position in flow mode. Also handle multiple mathjax config script tags.
This commit is contained in:
parent
bb70db2755
commit
ebbfda816d
@ -23,24 +23,21 @@ class MathJax
|
|||||||
this.pending_cfi = null
|
this.pending_cfi = null
|
||||||
this.hub = null
|
this.hub = null
|
||||||
|
|
||||||
load_mathjax: (script) ->
|
load_mathjax: (user_config) ->
|
||||||
if this.base == null
|
if this.base == null
|
||||||
log('You must specify the path to the MathJax installation before trying to load MathJax')
|
log('You must specify the path to the MathJax installation before trying to load MathJax')
|
||||||
return null
|
return null
|
||||||
|
|
||||||
created = false
|
script = document.createElement('script')
|
||||||
if script == null
|
|
||||||
script = document.createElement('script')
|
|
||||||
created = true
|
|
||||||
|
|
||||||
script.type = 'text/javascript'
|
script.type = 'text/javascript'
|
||||||
script.src = 'file://' + this.base + '/MathJax.js'
|
script.src = 'file://' + this.base + '/MathJax.js'
|
||||||
|
script.text = user_config + '''
|
||||||
script.text = script.text + '''
|
MathJax.Hub.signal.Interest(function (message) {if (String(message).match(/error/i)) {console.log(message)}});
|
||||||
MathJax.Hub.Config({
|
MathJax.Hub.Config({
|
||||||
positionToHash: false,
|
positionToHash: false,
|
||||||
showMathMenu: false,
|
showMathMenu: false,
|
||||||
extensions: ["tex2jax.js","asciimath2jax.js","mml2jax.js"],
|
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: {
|
TeX: {
|
||||||
extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]
|
extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]
|
||||||
@ -50,9 +47,7 @@ class MathJax
|
|||||||
MathJax.Hub.Register.StartupHook("End", window.mathjax.load_finished);
|
MathJax.Hub.Register.StartupHook("End", window.mathjax.load_finished);
|
||||||
window.mathjax.hub = MathJax.Hub
|
window.mathjax.hub = MathJax.Hub
|
||||||
'''
|
'''
|
||||||
|
document.head.appendChild(script)
|
||||||
if created
|
|
||||||
document.head.appendChild(script)
|
|
||||||
|
|
||||||
load_finished: () =>
|
load_finished: () =>
|
||||||
log('MathJax load finished!')
|
log('MathJax load finished!')
|
||||||
@ -67,14 +62,17 @@ class MathJax
|
|||||||
this.math_present = false
|
this.math_present = false
|
||||||
this.math_loaded = false
|
this.math_loaded = false
|
||||||
this.pending_cfi = null
|
this.pending_cfi = null
|
||||||
|
user_config = ''
|
||||||
for c in document.getElementsByTagName('script')
|
for c in document.getElementsByTagName('script')
|
||||||
if c.getAttribute('type') == 'text/x-mathjax-config'
|
if c.getAttribute('type') == 'text/x-mathjax-config'
|
||||||
|
if c.text
|
||||||
|
user_config += c.text
|
||||||
script = c
|
script = c
|
||||||
break
|
c.parentNode.removeChild(c)
|
||||||
|
|
||||||
if script != null or document.getElementsByTagName('math').length > 0
|
if script != null or document.getElementsByTagName('math').length > 0
|
||||||
this.math_present = true
|
this.math_present = true
|
||||||
this.load_mathjax(script)
|
this.load_mathjax(user_config)
|
||||||
|
|
||||||
after_resize: () ->
|
after_resize: () ->
|
||||||
if not this.math_present or this.hub == null
|
if not this.math_present or this.hub == null
|
||||||
|
@ -334,6 +334,16 @@ class PagedDisplay
|
|||||||
elem = elems[0]
|
elem = elems[0]
|
||||||
if not elem
|
if not elem
|
||||||
return
|
return
|
||||||
|
if window.mathjax?.math_present
|
||||||
|
# MathJax links to children of SVG tags and scrollIntoView doesn't
|
||||||
|
# work properly for them, so if this link points to something
|
||||||
|
# inside an <svg> tag we instead scroll the parent of the svg tag
|
||||||
|
# into view.
|
||||||
|
parent = elem
|
||||||
|
while parent and parent?.tagName?.toLowerCase() != 'svg'
|
||||||
|
parent = parent.parentNode
|
||||||
|
if parent?.tagName?.toLowerCase() == 'svg'
|
||||||
|
elem = parent.parentNode
|
||||||
elem.scrollIntoView()
|
elem.scrollIntoView()
|
||||||
if this.in_paged_mode
|
if this.in_paged_mode
|
||||||
# Ensure we are scrolled to the column containing elem
|
# Ensure we are scrolled to the column containing elem
|
||||||
|
Loading…
x
Reference in New Issue
Block a user