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 eb74401
Show file tree
Hide file tree
Showing 2 changed files with 33 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()
}
}
}
14 changes: 14 additions & 0 deletions tests/integration/latex_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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)

assert_solara_snapshot(page_session.locator(".test-class").screenshot())
slider.description = r"$\alpha$"
slider.add_class("test-changed-class")
assert_solara_snapshot(page_session.locator(".test-changed-class").screenshot(), postfix="-changed")

0 comments on commit eb74401

Please sign in to comment.