Skip to content

Commit

Permalink
try patching mathjax if missing from window
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl committed Oct 10, 2023
1 parent 52663ac commit 1703ba3
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion 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 { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import type { IRenderMime, IRenderMimeRegistry } from '@jupyterlab/rendermime';

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

Expand Down Expand Up @@ -224,6 +224,12 @@ 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 @@ -315,6 +321,21 @@ 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 1703ba3

Please sign in to comment.