Skip to content

Commit

Permalink
try a different approach
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl committed Oct 10, 2023
1 parent c52e9cd commit 388c782
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
14 changes: 13 additions & 1 deletion packages/controls/src/widget_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ export class DescriptionView extends DOMWidgetView {
}

typeset(element: HTMLElement, text?: string): void {
this.displayed.then(() => typeset(element, text));
this.displayed.then(() => {
if ((window as any).MathJax) {
return typeset(element, text);
}
const widget_manager: any = this.model.widget_manager;
const latexTypesetter = widget_manager.rendermime?.latexTypesetter;
if (latexTypesetter) {
if (text !== void 0) {
element.textContent = text;
}
latexTypesetter.typeset(element);
}
});
}

updateDescription(): void {
Expand Down
23 changes: 1 addition & 22 deletions python/jupyterlab_widgets/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ReadonlyPartialJSONValue } from '@lumino/coreutils';

import { INotebookModel } from '@jupyterlab/notebook';

import type { IRenderMime, IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';

import { Kernel, KernelMessage, Session } from '@jupyterlab/services';

Expand Down Expand Up @@ -224,12 +224,6 @@ export abstract class LabWidgetManager
if (!cls) {
throw new Error(`Class ${className} not found in module ${moduleName}`);
}
if (
moduleName === '@jupyter-widgets/controls' &&
this._rendermime.latexTypesetter
) {
void this._patchTypeset(this._rendermime.latexTypesetter);
}
return cls;
}

Expand Down Expand Up @@ -321,21 +315,6 @@ export abstract class LabWidgetManager
await this.handle_comm_open(oldComm, msg);
};

/**
* Patch typesetting in `@jupyter-widgets/controls` to use the rendermime's typesetter.
*/
protected async _patchTypeset(
latexTypesetter: IRenderMime.ILatexTypesetter
): Promise<void> {
const controls = await import('@jupyter-widgets/controls/lib/utils');
controls.typeset = (element: HTMLElement, text?: string): void => {
if (text !== void 0) {
element.textContent = text;
}
latexTypesetter.typeset(element);
};
}

protected _restored = new Signal<this, void>(this);
protected _restoredStatus = false;
protected _kernelRestoreInProgress = false;
Expand Down

0 comments on commit 388c782

Please # to comment.