pythonlatexgoogle-colaboratorymathjax

LaTeX Definitions in Google Colab


I've spent the past few weeks trying to find a way to make standard definitions I use when writing in Latex be applied to a Colab project.

It's possible to define terms within a single markdown cell a few different ways. However, I am trying to find something I could put at the top of all my projects that would load definitions across all cells. I am fine with hosting a file on github that I load or a local file of some sort, but my attempts to do this so far have been unsuccessful.

The closest I have come has been to do this has been to use nbextensions. But because Colab doesn't have the clear interface like Jupyter Notebook, you have to enable the extension manually, which I seem to do with jupyter nbextension enable load_tex_macros/main, but even though my definitions file is in the correct place, it does not load the definitions. Besides, this solution is undesirable because I'd have to reinstall things every time I open the project.

I know there has to be a workaround by creating a custom js file of some sort at the least. I have tried to read the MathJax documentation, but haven't been able to adopt what I need


Solution

  • you can have a look at this other question: How to define a LaTeX macro in a Markdown cell of a Jupyter Notebook? (and its answer).

    To be more generic: a notebook executes all the LaTeX commands in the same LaTeX environment.

    It implies that you can write

    [In one cell]: This is a Marco definition: $\def\Qc{Q^N_i}$ and use it in a formula of the same cell $\Qc=3$.

    And you can later

    [in another cell] Use it again $A=3\times \Qc$.

    It will be visible as: enter image description here