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

Enable line numbers to show on code cells. #1254

Open
jwayne2978 opened this issue Mar 5, 2021 · 9 comments
Open

Enable line numbers to show on code cells. #1254

jwayne2978 opened this issue Mar 5, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@jwayne2978
Copy link

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

@jwayne2978 jwayne2978 added the enhancement New feature or request label Mar 5, 2021
@welcome
Copy link

welcome bot commented Mar 5, 2021

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

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! 🎉

@michaelosthege
Copy link
Contributor

michaelosthege commented Apr 25, 2022

Inspired by readthedocs/sphinx_rtd_theme#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

@chrisjsewell
Copy link
Member

This was added in executablebooks/MyST-NB#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

@michaelosthege
Copy link
Contributor

@chrisjsewell thanks for that context. Can you post/link an example of where the nb_number_source_lines setting should be set?

@chrisjsewell
Copy link
Member

heya, its not released to jupyter-book just yet (only just merged that PR last week), in sphinx its just in the conf.py

@gao-hongnan
Copy link

Any updates pertaining to enabling line numbers to be shown on code blocks? Thanks!

@pierrepo
Copy link

This feature would allow me to mention specific code line in my course.

@michaelosthege
Copy link
Contributor

This feature would allow me to mention specific code line in my course.

@pierrepo See #1254 (comment). This worked just fine for my thesis

@pierrepo
Copy link

Hello @michaelosthege

Thanks for your comment. I did not think it would work out of the box... and it did 🤯

So I have now to replace all:

```python

by

```{code-block} python
---
linenos: True
---

in my course. Many thanks for your help @michaelosthege 🙏

@chrisjsewell I still believe that a global code line numbering option would be useful in Jupyter Book.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants