Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support numbered code-block references *without* :caption: #114

Open
rossbar opened this issue Mar 10, 2020 · 0 comments
Open

Support numbered code-block references *without* :caption: #114

rossbar opened this issue Mar 10, 2020 · 0 comments
Labels
enhancement New feature or request upstream This issue requires an upstream dependency fix

Comments

@rossbar
Copy link
Contributor

rossbar commented Mar 10, 2020

Is your feature request related to a problem? Please describe.
Not so much a problem as a limitation of sphinx for scientific publication. Setting numfig=True in the conf.py enables automatic numbering of things like figures, tables, code-blocks, etc. Unfortunately, for code-blocks this only works if the :caption: has been defined.

Describe the solution you'd like
For scientific publication, it would be very nice if it were possible to reference a code block via numref without explicitly having to define a caption: within the code-block directive. For example:

I want to reference the following code-block with a numref:
```{code-block} python
---
name: my-code
---
print("Hello World")
```
But when I use try to reference via {numref}`my-code`, it fails unless there is a caption.

Note that the desired behavior (numref without caption) works find for tables and figures.

Describe alternatives you've considered
Pre-labeling code-blocks doesn't work either:

(my-code)=
```{code-block} python
def foo():
    pass
```
Referencing the code-block like {numref}`my-code` doesn't work either

Additional context
Note that this is a limitation of sphinx, not the myst-parser. The myst-parser output is entirely consistent with rST output with sphinx (i.e. warnings and failed xrefs). Perhaps this is something that needs to be fixed upstream in sphinx, not in MyST (let me know if that's the case).

@rossbar rossbar added the enhancement New feature or request label Mar 10, 2020
@chrisjsewell chrisjsewell added the upstream This issue requires an upstream dependency fix label Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request upstream This issue requires an upstream dependency fix
Projects
None yet
Development

No branches or pull requests

2 participants