Hi Matthias, Aaron, All,

It works. I've hacked something together to add a \label{...} inside the equation environment. It is called like this:

init_printing(latex_mode="equation", label="quadratic")
display(ex2)

Now the equation can be referenced using \ref{quadratic} or \eqref{quadratic} in a notebook markdown cell.

init_printing() needs to be called to set the equation reference before every display() call. Once init_printing() is called with a label argument it will persist thereafter. This is kind of clunky but it gets the job done.

In PDF output from 'jupyter nbconvert' the numbering works but in interactive Jupyter views the equation references display as ???, which was expected.

It doesn't work in the vscode Jupyter extension because that uses KaTex, which doesn't support equation references and produces an error message instead of displaying the equation.

Glenn

On 17/01/24 07:07, Matthias Geier wrote:
Hi Glenn, all.

On Mon, Jan 15, 2024 at 11:06 PM Aaron Meurer <asmeu...@gmail.com> wrote:
On Mon, Jan 15, 2024 at 1:48 PM Glenn Ramsey <glenn.ramsey...@gmail.com> wrote:
On 8/01/24 11:57, Glenn Ramsey wrote:

[...]

A question now is if I did that and referred to that in the markdown with
something like this: $\@ref(foo)$, would that get picked up? I'm really only

You should not use $-signs, because references don't happen in math
mode, they are part of normal text.
The correct usage is \ref{foo} or \eqref{foo}, without any additional
characters.

interested in this for static presentation output (pdf, html) so it wouldn't
matter if it doesn't work in interactive modes.

I think the only way to know if it will work or not is to test it. I
suspect it will work for pdf output, but I have no idea if it will
work in the browser. It depends on whether MathJax supports \ref.

MathJax does support \ref{...}, as long as it is configured appropriately.

There are some examples in the nbsphinx docs:
https://nbsphinx.readthedocs.io/en/0.9.3/markdown-cells.html#Manual-Equation-Numbering

This also works on nbviewer (which is based on nbconvert):
https://nbviewer.org/urls/nbsphinx.readthedocs.io/en/0.9.3/markdown-cells.ipynb#Manual-Equation-Numbering

It also works on Github:
https://github.com/spatialaudio/nbsphinx/blob/0.9.3/doc/markdown-cells.ipynb

Of course, this also works for PDF output:
https://nbsphinx.readthedocs.io/_/downloads/en/0.9.3/pdf/

It does work on the old Jupyter notebook:
https://mybinder.org/v2/gh/spatialaudio/nbsphinx/0.9.3?filepath=doc/markdown-cells.ipynb

And it does work on JupyterLab:
https://mybinder.org/v2/gh/spatialaudio/nbsphinx/0.9.3?labpath=doc/markdown-cells.ipynb

cheers,
Matthias


--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/64d5d7ff-5eea-4142-86ab-34f3ac2ddcf4%40gmail.com.

Reply via email to