jupyterlab-myst icon indicating copy to clipboard operation
jupyterlab-myst copied to clipboard

Display the label for an equation in a {math} directive

Open jmshea opened this issue 3 years ago • 2 comments

Context

JupyterBook supports equation references by adding a label in the {math} directive like

```{math}
:label: general-gaussian-cdf2
\Phi \left(\frac{x-\mu}{\sigma} \right)
```

The jupyterlab-myst extension correctly displays the equation as of 0.1.7a0, but there is no indication of the label. Being able to see the label would simplify the process of referring to such an equation later.

Proposal

My proposal is that if an equation has a label, the label should be displayed somehow. In my view, it would ideally be displayed in parentheses to the right of the equation itself. (Much like the equation number is in the rendered Jupyter Book.)

Tasks and updates

  • [ ] Determine whether jupyterlab-myst should display labels
  • [ ] Determine where labels should be displayed (to side, above, or below equation)
  • [ ] Determine whether label should be displayed by passing to MathJax or by the plugin manipulating the DOM
  • [ ] Implement code to display label
  • [ ] Test with equations of differing widths, multiple lines, etc. and labels of different widths, character sets, etc.
  • [ ] Create PR for merging with main branch

jmshea avatar Apr 28 '22 18:04 jmshea

We could definitely do this. Right now, we use KaTeX for rendering, which is more lightweight than MathJax2, though we could use MathJax3 if it proved a better fit. Both of these packages provides \tag, which we could inject into the math source before invoking the math renderer. I don' know if that would be problematic in cases where we have nested environments, e.g equation.

Alternatively, we could roll-our-own and wrap the rendered math in another layout. Food for thought.

agoose77 avatar Jun 11 '22 12:06 agoose77

This is something that we could potentially pick up again now that we have more control over the renderer. It is something that is relatively trivial to add, but I am really unsure of:

  • do we want the labels to always be visible - or maybe have a global (or notebook level) toggle for turning figure/equation/section labels on/off
  • Should we also show these for other labeled elements in myst (e.g. like paragraphs or callouts?) or should we stick to only equations/figures/tables.

Overall I quite like the idea of the editing experience helping you with linking things, showing labels, etc. that is in addition to the view-only version.

rowanc1 avatar Mar 15 '23 04:03 rowanc1