jupyterlab / jupyter-renderers

Renderers and renderer extensions for JupyterLab
BSD 3-Clause "New" or "Revised" License
489 stars 77 forks source link

Refresh mathjax and add require package #282

Closed bsdz closed 1 year ago

bsdz commented 2 years ago

This PR is primarily to add the require command so one can import the physics package only if needed.

So the following:

image

now renders as:

image

Also add some menu items to allow scaling / resetting scale and copying markdown to clipboard.

image

And here's how the 1.5 scale vs normal scale looks like:

image

Apologies in advance if I've missed something important as typescript is not my forte. Admittedly, some of these changes might need additional work to make robust. Happy for suggestions.

welcome[bot] commented 2 years ago

Thanks for submitting your first pull request! You are awesome! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please make sure you followed the pull request template, as this will help us review your contribution more quickly. welcome You can meet the other Jovyans by joining our Discourse forum. There is also a intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

github-actions[bot] commented 2 years ago

Binder :point_left: Launch a Binder on branch bsdz/jupyter-renderers/master

kzhk75 commented 2 years ago

@bsdz , thank you for refreshing the package. By using your branch, I can use some of MathJax3 in my jupyterlab.

With the refreshed package, I happen to find \braket{a} and \braket{a}{b} are not displayed in proper way like \langle a \mid a \rangle and \langle a \mid b \rangle , unfortunately. \innerproduct{a}{b} works well as \langle a \mid b \rangle

I'd like to know if such situations are just in my environment. Hopefully, I want to know how we can fix it.

bsdz commented 2 years ago

I think the issue is the mathjax core library. For example if I go to mathjax's demo page here and render the following html to compare your variations:

$\require{physics}$
<table>
<tr><th>physics</th><th>verbatim</th></tr>
<tr><td> $\braket{a}$</td><td>$\langle a \mid a \rangle$</td></tr>
<tr><td>$\braket{a}{b}$ </td><td>$\langle a \mid b \rangle$</td></tr>
<tr><td>$\innerproduct{a}{b}$</td><td>$\langle a \mid b \rangle$</td></tr>
</table>

It is rendered as:

image

tbh I have to admit I prefer the more compact version.

Edit: actually after writing this comment I notice perhaps \braket{a}{b} should be written as \braket{a|b}?

kzhk75 commented 2 years ago

Thank you for analysing my comment.

As MathJax document says

The physics extension implements much of the LaTeX physics package,..

, so the physics extension is slightly different from the original.

~These rendering problems appear in KaTeX-physics as well.~ These renderings work in KaTeX-physics ..

... perhaps \braket{a}{b} should be written as \braket{a|b}?

Yes, it is possible. I prefer \braket{a}{b} because \bra{a} is a dual space of \ket{b} as in the original document

I'll analyse MathJax code related to Dirac bra-ket notation

welcome[bot] commented 1 year ago

Congrats on your first merged pull request in this project! :tada: congrats Thank you for contributing, we are very proud of you! :heart: