The original question can be subdivided into the four separate yet closely related questions:
- How is LaTeX in markdown displayed in JupyterLab?
- How is LaTeX in markdown exported (into supported file formats) in JupyterLab?
- How can I define new LaTeX macros (in order to avoid repetition) and have them properly displayed and exported in JupyterLab?
- How can I use packages from CTAN, the official package registry of TeX packages, and have them properly displayed and exported in JupyterLab?
The questions 3. and 4. are of utter importance for me because I won't be able to switch out of LaTeX unless I can define macros in JupyterLab and my papers will be less readable unless I have certain packages from CTAN. The first two questions are asked because they can greatly assist answering questions 3. and 4.
First question ("How is LaTeX in markdown displayed in JupyterLab?")
According to the official documentation,
JupyterLab is the next-generation web-based user interface for Project Jupyter.
Indeed, when I type in the console
jupyter lab
and hit enter, as a user I can see that a browser tab opens up and there I can start working on my files.
As a developer, I understand that there is a server running in the background that handles requests from the browser by interacting with tools of Project Jupyter and serving HTML, CSS, JS, WASM, JPG, and other files to my browser.
When as a user I proceed to open a Jupyter Notebook (.ipynb document) with some LaTeX code in markdown cells, instead of the source code
Let $\nu_p(n)$ denote p-adic order for prime number $p$ of non-zero integer $n$ where $\nu_p$ is a p-adic order function,
$$
\begin{cases}
\nu_p : \mathbb{Z} \setminus \{ 0 \} \to \mathbb{N}_0; \\
\nu_p = n \mapsto max\{ e \in \mathbb{N}_0. p^e \vert n \};
\end{cases}
$$
I can see the rendered output,
What I mean by "How is LaTeX in markdown displayed in JupyterLab?"
- Which tools (not necessarily of Project Jupyter) are used and how do they work together in order to display the rendered output?
- What's the role of the kernel (evcxr for Rust or IPython for Pyhton) in this process? Is the kernel involved in it?
- Are there any config files that are being read in the process regardless of the kernel?
Second question ("How is LaTeX in markdown exported (into supported file formats) in JupyterLab?")
While in a tab with that Jupyter Notebook (.ipynb document) with some LaTeX code in markdown cells, I can click "File" > "Save and Export Notebook As..." and then select one of the supported formats
Once I select one of the format, first a new tab opens up
then after a while the tab will be closed and the exported file will finally be installed
What I mean by "How is LaTeX in markdown exported (into supported file formats) in JupyterLab?"
Similarly to the first question,
- Which tools (not necessarily of Project Jupyter) are used and how do they work together in order to export the Notebook with some LaTeX in a Markdown cell?
- What's the role of the kernel (evcxr for Rust or IPython for Pyhton) in this process? Is the kernel involved in it?
- Are there any config files that are being read in the process regardless of the kernel?
Third question ("How can I define new LaTeX macros (in order to avoid repetition) and have them properly displayed and exported in JupyterLab?")
As far as I understand, JupyterLab serves pages with MathJax for displaying LaTeX in Markdown and MathJax allows to declare TeX macros. Unless the tools that perform conversion to other file formats cannot work with LaTeX (which is an approximate superset of LaTeX supported by MathJax), it should be relatively straightforward to support custom macros at least through a config file.
Fourth question ("How can I use packages from CTAN, the official package registry of TeX packages, and have them properly displayed and exported in JupyterLab?")
MathJax doesn't support \usepackage{}
out of the box. However, I suspect that it must be possible to preprocess the contents of the cell before displaying it. And then I can provide an alternative definitions (for displaying but not the exporting) for macros from CTAN packages.
Notes
I understand that I can insert pages from an existing PDF in LaTeX. However, it is inconvenient.