In Jupyter Notebooks you can type, for example \alpha
and hit the tab key and the \alpha
changes into α. This is a pretty cool feature. Unfortunately, it doesn't work in the jupyter-lab editor. Any reason why that doesn't work? Or do I need to set a preference somewhere?
3 Answers
if you type $\alpha$ it will be rendered as the greek letter thanks to latex
-
1I know, but that works in markdown cells. In a code cell of Jupyter Notebook you can type
\alpha
, then hit [tab] and it turns into α. Very cool, actually. My question is: this feature doesn't work in the Editor of Jupyter-lab when you are editing a Python file. I want to know if this is possible (I hope so). Dec 17, 2018 at 8:11
Although the answer of @joelostblom works fine, you can simply install the LaTeXStrings Julia package to enable the \alpha [tab] feature without needing to spawn an IPython kernel.
using Pkg
Pkg.add("LaTeXStrings")
-
-
It is not a Jupyter Lab feature, it is a Julia package. If you copy the two lines I wrote in a Julia console and wait for the installation to be done, it will install the Julia LaTeXStrings package and the IJulia kernel will pick up that it is now installed and the greek letters will work. Then you will never have to do anything again, it will work as soon as you start a Julia notebook.– LeerroSep 15, 2019 at 15:20
-
Cool! But it won't work when editing a Python file in the Jupyter Lab Editor, correct? Just want to make sure I understand. Sep 16, 2019 at 16:06
-
Indeed, my answer is for someone who uses Jupyter Lab to write in Julia Lang. For Python, the IPython kernel already takes care of the greek letters out of the box, as @joelostblom explained in his answer. It just already works for Python in Jupyter lab and for any notebooks if an IPython kernel is active. And for other kernels, my proposed solution does not work. I should edit my answer to reflect the assumption of using Julia.– LeerroSep 16, 2019 at 17:58
This feature is provided by the IPython kernel, not the Jupyter Notebook. The kernel provides TAB completion by looking up the latex (or latex-like) symbol in this dictionary (originally from Julia) and then inserts its value (the corresponding Unicode character). As such, there needs to be an active IPython kernel to provide the TAB completion (here is the PR that added the functionality to IPython in case you want to read more about it).
An IPython kernel is automatically started with the notebook and used when running cells, but this is not the case when editing a text file (which is also why there is no TAB completion for other things such as imports, etc). You can start one manually by right clicking inside a Python text file and selecting "Create console for editor". After that autocompletion works just as in the notebook, including Greek latex symbols.
-
Thank you for the explanation. So it is a feature of the IPython kernel. Couldn't the same feature be added to the Jupyter Lab Editor? I understand that this may be a lot of work, but that could technically be done, right? But for now I understand it is not there and will not be there any time soon (if ever) for technical reasons. Aug 25, 2019 at 20:46
-
@MarkBakker It is probably possible, but the question is rather if it is worthwhile since it might involve a lot of work as you pointed out. I suspect one solution would be to start an IPython kernel when opening text files that end in
.py
, but I am not familiar enough with the Jupyter codebase to know if this is a feasible solution. Aug 26, 2019 at 0:53 -
I might float a suggested improvement to the Jupyter Lab people and see what they say. It may be easier than we think (or not, we'll see). Thanks again. Aug 27, 2019 at 8:13
-
@MarkBakker Turns out this is already implemented. Just right click in an open Python text file and select "Create console for editor", after that autocompletion works just as in the notebook, including greek latex symbols ((discussion in this issue)[github.com/jupyterlab/jupyterlab/issues/4487]), I updated the answer to reflect this. Aug 27, 2019 at 15:08