spatialaudio / nbsphinx

:ledger: Sphinx source parser for Jupyter notebooks
https://nbsphinx.readthedocs.io/
MIT License
441 stars 129 forks source link

How to link to a notebook from another file ? #764

Closed cottephi closed 9 months ago

cottephi commented 9 months ago

Hello everyone, I am trying to do something for which I did not find any documentation :

Note that both the file and the notebook and displayed correctly in the resulting documentation.

And I want to add a reference to the notebook in the python file's docstring.

First, I thought of doing something like that in my examples.rst file :

.. _examples:

Examples
========

Notebooks
---------

.. nbgallery::
   :caption: See some examples in notebooks :

   .. _mynb:
                    <-- tried also without the blank line, same result
   examples/notebooks/mynb.ipynb

and this in my python file :

"""
See Also:
    :ref:`mynb`
"""

But that does not work, compilation warns : /my/project/path/docs/source/auto_examples/imports/myfile.rst:27: WARNING: undefined label: 'mynb'

Any idea on how I could achieve this ?

mgeier commented 9 months ago

The nbgallery directive is based on the toctree directive, which expects a list of document names. Putting a link anchor in there is not supported, and it really doesn't make too much sense, anyway. I guess you want to link to the given document, not to the position where the link to the document will appear, right?

As for how to link to a notebook from reST, this is documented here: https://nbsphinx.readthedocs.io/en/0.9.3/a-normal-rst-file.html#links-to-notebooks-and-other-sphinx-source-files.

cottephi commented 9 months ago

I do not know how I did not manage to find this documentation page. It solved by problem. Thank you @mgeier !