jupyterlab / jupyterlab

JupyterLab computational environment.
https://jupyterlab.readthedocs.io/
Other
14.13k stars 3.36k forks source link

Inline latex not showing correctly within markdown when using Ipython.display #15796

Closed barathvb closed 7 months ago

barathvb commented 8 months ago

Description

When programmatically displaying markdown using IPython.display, inline latex is not being rendered correctly. I notice this behavior only in the latest 4.1.x versions. The 4.0.x versions of JupyterLab is correctly displaying inline latex within markdown.

Here are two screenshots of the same notebook. One using 4.1.1 and the other 4.0.12

markdown_4 0 12 markdown_4 1 1

Reproduce

Install 4.0.12 and run any latex inline with markdown and you will it working. Doing the same thing with 4.1.1 is producing the issue

Expected behavior

The inline latex to be displayed correctly when using Markdown in IPython.display

Context

Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here.
You may want to sanitize the paths in the output.
Command Line Output
[W 2024-02-13 10:54:07.210 ServerApp] A `_jupyter_server_extension_points` function was not found in notebook_shim. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[I 2024-02-13 10:54:07.210 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2024-02-13 10:54:07.225 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2024-02-13 10:54:07.241 ServerApp] jupyterlab | extension was successfully linked.
[I 2024-02-13 10:54:07.538 ServerApp] notebook_shim | extension was successfully linked.
[I 2024-02-13 10:54:07.586 ServerApp] notebook_shim | extension was successfully loaded.
[I 2024-02-13 10:54:07.586 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2024-02-13 10:54:07.586 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2024-02-13 10:54:07.586 LabApp] JupyterLab extension loaded from C:\Users\barat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\jupyterlab
[I 2024-02-13 10:54:07.586 LabApp] JupyterLab application directory is C:\Users\barat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\share\jupyter\lab
[I 2024-02-13 10:54:07.586 LabApp] Extension Manager is 'pypi'.
[I 2024-02-13 10:54:07.602 ServerApp] jupyterlab | extension was successfully loaded.
[I 2024-02-13 10:54:07.602 ServerApp] Serving notebooks from local directory: C:\Users\barat
[I 2024-02-13 10:54:07.602 ServerApp] Jupyter Server 2.12.5 is running at:
[I 2024-02-13 10:54:07.602 ServerApp] http://localhost:8888/lab?token=213c9f7fe59c819347b376d04df3d35b493616b8d74097d0
[I 2024-02-13 10:54:07.602 ServerApp]     http://127.0.0.1:8888/lab?token=213c9f7fe59c819347b376d04df3d35b493616b8d74097d0
[I 2024-02-13 10:54:07.602 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2024-02-13 10:54:07.648 ServerApp]

    To access the server, open this file in a browser:
        file:///C:/Users/barat/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/Roaming/jupyter/runtime/jpserver-4048-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/lab?token=213c9f7fe59c819347b376d04df3d35b493616b8d74097d0
        http://127.0.0.1:8888/lab?token=213c9f7fe59c819347b376d04df3d35b493616b8d74097d0
[I 2024-02-13 10:54:08.633 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server
[W 2024-02-13 10:54:13.084 LabApp] Could not determine jupyterlab build status without nodejs
[I 2024-02-13 10:54:18.987 ServerApp] Kernel started: 56b18c5a-1d37-4135-ae27-5bc87461130f
[I 2024-02-13 10:54:20.555 ServerApp] Connecting to kernel 56b18c5a-1d37-4135-ae27-5bc87461130f.
[I 2024-02-13 10:54:20.585 ServerApp] Connecting to kernel 56b18c5a-1d37-4135-ae27-5bc87461130f.
[I 2024-02-13 10:54:20.626 ServerApp] Connecting to kernel 56b18c5a-1d37-4135-ae27-5bc87461130f.
[I 2024-02-13 10:54:36.390 ServerApp] Kernel restarted: 56b18c5a-1d37-4135-ae27-5bc87461130f
[I 2024-02-13 10:54:36.400 ServerApp] Starting buffering for 56b18c5a-1d37-4135-ae27-5bc87461130f:37764e5c-926f-4037-b960-5ff38de487c3
[I 2024-02-13 10:54:36.406 ServerApp] Connecting to kernel 56b18c5a-1d37-4135-ae27-5bc87461130f.
[I 2024-02-13 10:54:36.406 ServerApp] Restoring connection for 56b18c5a-1d37-4135-ae27-5bc87461130f:37764e5c-926f-4037-b960-5ff38de487c3
[I 2024-02-13 10:56:18.819 ServerApp] Saving file at /Documents/Untitled.ipynb
Browser Output
Paste the output from your browser Javascript console here, if applicable.

welcome[bot] commented 8 months ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

krassowski commented 7 months ago

I can reproduce this. It sometimes works, sometimes does not. The problem stems from this line:

https://github.com/jupyterlab/jupyterlab/blob/1a98deafa7dc41607106b55936fbdefe9741faaa/packages/rendermime/src/widgets.ts#L194

Namely, the fact that the output widget may not be yet attached when rendering, thus the typesetting does not proceed.

krassowski commented 7 months ago

This works fine in 4.0.12 but fails as early as v4.1.0a1. I do not immediately see which PR introduced this issue.

krassowski commented 7 months ago

Ok, looks like a side effect of https://github.com/jupyterlab/jupyterlab/pull/14102.

It is not because this.isAttached is false - it was false in 4.0 too. It is because when onAfterAttach is called:

https://github.com/jupyterlab/jupyterlab/blob/1a98deafa7dc41607106b55936fbdefe9741faaa/packages/rendermime/src/widgets.ts#L243-L247

The node output is still not populated.

To avoid jitter we might want to make createRenderedMimetype await on the rendering promise, but this is non trivial - we would need to implement a queue to ensure outputs are added in the correct order.