CoCalc Public Filesnewcommand-in-jupyter-markdown-cell.ipynbOpen in with one click!
Author: Samuel Lelièvre
Views : 25
License: Other -- explicitly state in your code
Description: To illustrate CoCalc issue #4569: "Jupyter markdown cells: newcommand and LaTeX formulas" --

LaTeX, newcommand, Jupyter markdown cells, CoCalc

LaTeX formulas with newcommand-defined bits in Jupyter markdown cells on CoCalc


Two markdown cells with the same bit of math, first not using \newcommand, then using it.

**Cell A**

We denote by $\operatorname{span}(u, v)$ the span of two vectors $u$ and $v$.
**Cell B**

We denote by $\span(u, v)$ the span of two vectors $u$ and $v$.

Cell A

We denote by span(u,v)\operatorname{span}(u, v) the span of two vectors uu and vv.

Cell B

We denote by the span of two vectors uu and vv.


  1. The formula is text in Cell A but an image in Cell B.
  2. When viewing this Jupyter notebook in one's CoCalc project,
    • in Cell A
      • one can select text that includes the formula or part of it
      • this selection can be done character by character
      • the selected text gets highlighted in inverted colors (white on blue)
      • the highlighting applies to the selected part of the formula as well
    • in Cell B
      • selecting some text, one can include the whole formula or none of it
      • no way to select part of it, character by character
      • highlighting in inverted colors does not apply to the formula if selected
      • if "denote by span(u,v) the span" is selected, "span(u,v)" stays unhighlighted
  3. If this Jupyter notebook is made public on the CoCalc share server
    • in Cell A
      • the formula "span(u,v)" gets rendered
    • in Cell B
      • the formula "span(u,v)" is missing

Tentative explanation

Not really sure exactly what goes on but if I had to guess:

  • KaTeX renders the formula in Cell A as text but the one in Cell B as an image.
  • this explains the differences in highlighting
  • this probably also explains the non-rendering on the CoCalc share server
    • maybe the image lives in some hidden directory
    • maybe it is not made public when the Jupyter notebook is