Skip to content

Commit

Permalink
start backport of jupyterlab#15230 and jupyterlab#15214
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl committed Oct 6, 2023
1 parent 6a39d36 commit 09019c5
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 70 deletions.
15 changes: 15 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,18 @@ nodeLinker: node-modules
npmRegistryServer: "https://registry.yarnpkg.com"

yarnPath: ./jupyterlab/staging/yarn.js

# these messages provide no actionable information, and make non-TTY output
# almost unreadable, masking real dependency-related information
# see: https://yarnpkg.com/advanced/error-codes
logFilters:
- code: YN0006 # SOFT_LINK_BUILD
level: discard
- code: YN0007 # MUST_BUILD
level: discard
- code: YN0008 # MUST_REBUILD
level: discard
- code: YN0013 # FETCH_NOT_CACHED
level: discard
- code: YN0019 # UNUSED_CACHE_ENTRY
level: discard
14 changes: 10 additions & 4 deletions binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ dependencies:
- ipykernel
- jinja2 >=3.0.3
- jupyter_core
- jupyter_server >=2.0.1,<3
- jupyter_server >=2.4.0,<3
- jupyter-lsp >=2.0.0
- jupyterlab_server >=2.19.0,<3
- notebook-shim >=0.2
- packaging
- tornado >=6.2.0
- traitlets
- traitlets >=5.10.1
# test
- coverage
- pytest >=7.0
Expand All @@ -48,12 +48,18 @@ dependencies:
- ruff
# demo
- jupyter-server-proxy
- jupyterlab-link-share >=0.2
- matplotlib-base
- notebook >=7.0.4
- numpy
- vega_datasets
- xeus-python
# extra conda stuff
- jsonschema-with-format-nongpl
# jupyter-collaboration 1.2.0
- jupyter_ydoc >=1.0.1,<2.0.0
- ypy-websocket >=0.12.1,<0.13.0
- jupyter_events >=0.7.0
- jupyter_server_fileid >=0.7.0,<1
- pip:
- jupyter-collaboration >=1.0.0a5
# can't be installed with `conda` in binder, due to `jupyterlab-link-share``
- jupyter-collaboration ==1.2.0
4 changes: 2 additions & 2 deletions binder/postBuild
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ mkdir _reports_
# hoist report to where a reviewer might see it
mv dev_mode/static/webpack-bundle-analyzer.html _reports_/

# assume best-effort versions from conda-forge for all deps
(time pip install -vv -e .[dev] --no-build-isolation) 2>&1 | tee _reports_/02_pip_install.txt
# overload best-effort versions from conda-forge for all deps
(time pip install -v -e .[dev] --no-build-isolation) 2>&1 | tee _reports_/02_pip_install.txt

# copy configuration to well-known location
mkdir -p ~/.jupyter
Expand Down
12 changes: 2 additions & 10 deletions examples/example.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { ConsoleMessage, expect, test } from '@playwright/test';

const URL = process.env['BASE_URL'];
const URL = `${process.env['BASE_URL']}`;

test.setTimeout(120000);

Expand All @@ -22,15 +22,7 @@ test('should load the example', async ({ page }) => {
const text = msg.text();
console.log(msg.type(), '>>', text);

if (
msg.type() === 'error' &&
// Ignore 404 for MathJax fonts
msg
.location()
.url.match(
/js\/output\/chtml\/fonts\/tex-woff-v2\/MathJax_(Zero|Math-Italic|Main-Regular)\.woff$/
) === null
) {
if (msg.type() === 'error') {
errorLogs += 1;
}

Expand Down
1 change: 1 addition & 0 deletions packages/mathjax-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"dependencies": {
"@jupyterlab/application": "^4.0.6",
"@jupyterlab/rendermime": "^4.0.6",
"@lumino/coreutils": "^2.1.2",
"mathjax-full": "^3.2.2"
},
"devDependencies": {
Expand Down
134 changes: 80 additions & 54 deletions packages/mathjax-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @module mathjax-extension
*/

import { PromiseDelegate } from '@lumino/coreutils';

import {
JupyterFrontEnd,
JupyterFrontEndPlugin
Expand Down Expand Up @@ -36,61 +38,10 @@ namespace CommandArgs {
*/
export class MathJaxTypesetter implements ILatexTypesetter {
protected async _ensureInitialized() {
if (this._initialized) {
return;
if (!this._initialized) {
this._mathDocument = await Private.ensureMathDocument();
this._initialized = true;
}

await import('mathjax-full/js/input/tex/require/RequireConfiguration');
const { mathjax } = await import('mathjax-full/js/mathjax');
const { CHTML } = await import('mathjax-full/js/output/chtml');
const { TeX } = await import('mathjax-full/js/input/tex');
const { TeXFont } = await import('mathjax-full/js/output/chtml/fonts/tex');
const { AllPackages } = await import(
'mathjax-full/js/input/tex/AllPackages'
);
const { SafeHandler } = await import('mathjax-full/js/ui/safe/SafeHandler');
const { HTMLHandler } = await import(
'mathjax-full/js/handlers/html/HTMLHandler'
);
const { browserAdaptor } = await import(
'mathjax-full/js/adaptors/browserAdaptor'
);
const { AssistiveMmlHandler } = await import(
'mathjax-full/js/a11y/assistive-mml'
);

mathjax.handlers.register(
AssistiveMmlHandler(SafeHandler(new HTMLHandler(browserAdaptor())))
);

class EmptyFont extends TeXFont {
defaultFonts = {};
}

const chtml = new CHTML({
// Override dynamically generated fonts in favor of our font css
font: new EmptyFont()
});

const tex = new TeX({
packages: AllPackages.concat('require'),
inlineMath: [
['$', '$'],
['\\(', '\\)']
],
displayMath: [
['$$', '$$'],
['\\[', '\\]']
],
processEscapes: true,
processEnvironments: true
});

this._mathDocument = mathjax.document(window.document, {
InputJax: tex,
OutputJax: chtml
});
this._initialized = true;
}

/**
Expand Down Expand Up @@ -157,3 +108,78 @@ const mathJaxPlugin: JupyterFrontEndPlugin<ILatexTypesetter> = {
};

export default mathJaxPlugin;

/**
* A namespace for module-private functionality.
*/
namespace Private {
let _loading: PromiseDelegate<MathDocument<any, any, any>> | null = null;

export async function ensureMathDocument(): Promise<
MathDocument<any, any, any>
> {
if (!_loading) {
_loading = new PromiseDelegate();

void import('mathjax-full/js/input/tex/require/RequireConfiguration');

const [
{ mathjax },
{ CHTML },
{ TeX },
{ TeXFont },
{ AllPackages },
{ SafeHandler },
{ HTMLHandler },
{ browserAdaptor },
{ AssistiveMmlHandler }
] = await Promise.all([
import('mathjax-full/js/mathjax'),
import('mathjax-full/js/output/chtml'),
import('mathjax-full/js/input/tex'),
import('mathjax-full/js/output/chtml/fonts/tex'),
import('mathjax-full/js/input/tex/AllPackages'),
import('mathjax-full/js/ui/safe/SafeHandler'),
import('mathjax-full/js/handlers/html/HTMLHandler'),
import('mathjax-full/js/adaptors/browserAdaptor'),
import('mathjax-full/js/a11y/assistive-mml')
]);

mathjax.handlers.register(
AssistiveMmlHandler(SafeHandler(new HTMLHandler(browserAdaptor())))
);

class EmptyFont extends TeXFont {
protected static defaultFonts = {} as any;
}

const chtml = new CHTML({
// Override dynamically generated fonts in favor of our font css
font: new EmptyFont()
});

const tex = new TeX({
packages: AllPackages.concat('require'),
inlineMath: [
['$', '$'],
['\\(', '\\)']
],
displayMath: [
['$$', '$$'],
['\\[', '\\]']
],
processEscapes: true,
processEnvironments: true
});

const mathDocument = mathjax.document(window.document, {
InputJax: tex,
OutputJax: chtml
});

_loading.resolve(mathDocument);
}

return _loading.promise;
}
}
Loading

0 comments on commit 09019c5

Please sign in to comment.