jupyter-book
jupyter-book copied to clipboard
Enable line numbers to show on code cells.
Is your feature request related to a problem? Please describe.
No
Describe the solution you'd like
When code cells are rendered, there should be a way to show line numbers. This could be done with tags. Narrating code requires precision with references to line numbers.
Describe alternatives you've considered
None.
Additional context
Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:
Inspired by https://github.com/readthedocs/sphinx_rtd_theme/issues/1168 this worked for me in both HTML and pdflatex output:
```{code-block} python
---
name: code_linenumbers
linenos: True
caption: |
This code has line numbers.
---
print("Hello")
print("world.")
```
Duplicate issue #1580
This was added in https://github.com/executablebooks/MyST-NB/pull/380, available as nb_number_source_lines globally, and also per notebook or per code cell, see also https://myst-nb.readthedocs.io/en/latest/use/formatting_outputs.html#images-and-figures
@chrisjsewell thanks for that context. Can you post/link an example of where the nb_number_source_lines setting should be set?
heya, its not released to jupyter-book just yet (only just merged that PR last week), in sphinx its just in the conf.py
Any updates pertaining to enabling line numbers to be shown on code blocks? Thanks!
This feature would allow me to mention specific code line in my course.
This feature would allow me to mention specific code line in my course.
@pierrepo See https://github.com/executablebooks/jupyter-book/issues/1254#issuecomment-1108417408. This worked just fine for my thesis
Hello @michaelosthege
Thanks for your comment. I did not think it would work out of the box... and it did :exploding_head:
So I have now to replace all:
```python
by
```{code-block} python
---
linenos: True
---
in my course. Many thanks for your help @michaelosthege :pray:
@chrisjsewell I still believe that a global code line numbering option would be useful in Jupyter Book.