Skip to content

Commit

Permalink
fix: re-render latex support
Browse files Browse the repository at this point in the history
When a description changed, update the latex rendering.

Similar to voila-dashboards/voila#531
  • Loading branch information
maartenbreddels committed Jun 15, 2023
1 parent 1b34a5b commit c1727e9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/solara-widget-manager/src/mathjax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ RegisterHTMLHandler(browserAdaptor());

// Override dynamically generated fonts in favor
// of our font css that is picked up by webpack.
// @ts-ignore
class emptyFont extends TeXFont {
readonly defaultFonts = {};
// @ts-ignore
static defaultFonts = {};
}

const chtml = new CHTML({
Expand Down Expand Up @@ -57,3 +59,19 @@ export function renderMathJax(): void {
.updateDocument()
.reset();
}
// this makes it compatible with the old MathJax
// see https://github.com/voila-dashboards/voila/pull/531
// @ts-ignore
window.MathJax = {
Hub: {
// @ts-ignore
Queue: ([_ignore, _ignore2, node]) => {
html.findMath({ elements: [node] })
.compile()
.getMetrics()
.typeset()
.updateDocument()
.reset()
}
}
}
20 changes: 20 additions & 0 deletions tests/integration/latex_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import ipywidgets as widgets
import playwright.sync_api
from IPython.display import display


def test_widget_button_solara(solara_test, page_session: playwright.sync_api.Page, assert_solara_snapshot):
slider = widgets.FloatSlider(description=r"$E \sim mc^2$")
slider.add_class("test-class")
display(slider)

page_session.locator(".test-class >> .mjx-c1D438").wait_for()
page_session.evaluate("document.fonts.ready")
page_session.wait_for_timeout(100)
assert_solara_snapshot(page_session.locator(".test-class").screenshot())
slider.description = r"$\alpha$"
slider.add_class("test-changed-class")
page_session.locator(".test-changed-class >> .mjx-c1D6FC").wait_for()
page_session.evaluate("document.fonts.ready")
page_session.wait_for_timeout(100)
assert_solara_snapshot(page_session.locator(".test-changed-class").screenshot(), postfix="-changed")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c1727e9

Please sign in to comment.