-
Notifications
You must be signed in to change notification settings - Fork 0
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
Render Elegant Scipy with Jupyter Book #1
Comments
If you succeed, I'd love to include that on our Makefile and put a hosted version on our website. I'm happy to help you understand any of the custom parts of our build, but mainly we just have a few special comments in the Markdown files that we use to identify things like examples. |
Thanks @stefanv for your interest. I think the chances that we get this to work are reasonable. And the example will tell how we can evolve both Jupyter Book and Jupytext to render real and challenging books like yours. @choldgraf , the Elegant Scipy book is a great example as it is written entirely as Markdown documents which represent Jupyter notebooks using notedown, a predecessor of Jupytext. The repository seems to work very well with Jupytext, at least adding My initial attempt at turning Elegant Scipy into a Jupyter Book is at Elegant_Scipy_as_a_Jupyter_Book.md. A few steps there are not super user friendly yet (especially changing the kernel with |
@mwouts I don't understand from your comment whether it is working already? |
No, sorry it is not working yet. I need @choldgraf's feedback to see what is wrong, as I don't have much experience with Jupyter Book yet. One thing that does work already, is to open the original Elegant Scipy repo with Jupytext on Binder. Just add |
Oh wow, I get it now. That's super cool! Time to add a binder link and maybe deprecate the elegant-scipy/notebooks repository! |
@mwouts - it should be finding the |
Thanks @stefanv , @jni. Please let me know if I can help with the binder setup. I'd recommend to check every chapter, as I tested only a few of them. Note that Jupytext expects that every @choldgraf , I do think I am using the master branch. Actually the code I used is in that (bash) notebook: https://github.com/mwouts/jupyter-book-experiments/blob/master/Elegant_Scipy_as_a_Jupyter_Book.md . In an ideal world I would have expected the notebook to be runnable on Binder with the bash kernel (there's a link to Binder at the top of the notebook), but apparently the bask kernel has an issue with my 'conda activate' command. I'll see if I can fix that. Unless you see a better way than a notebook to collaborate of the experiment? 😄 Also a specific question I had for you, Chris, is whether I could avoid creating a new folder for the book content. In the case of the Elegant Scipy book, I'd like to determine the minimal addition that can turn the repo into a Jupyter Book. Can I call |
@choldgraf , the binder now runs. It was just my At the current stage we have the following issues
Still I am confident that it may soon start working well! The binder link is a great place to experiment. However, if you want to edit the notebook and contribute back your modifications, I recommend that you install |
I just gave another try to this, and I've reach a point where |
@choldgraf , thanks for your input yesterday. I was able to build the book following your deploy demo. The book is available here: https://mwouts.github.io/elegant-scipy-as-a-jp-book. And the actions that led to that are documented here: https://github.com/mwouts/jupyter-book-experiments/blob/8a6491767801c77e0f473246c0bbcdef4fb81716/Elegant_Scipy_as_a_Jupyter_Book.md The good news is that there are not too many steps there: it's only a matter of
I think that everything there (except the two config files) could go to a continuous integration file, as in Chris' deploy demo. Now, there is probably much to do yet! Especially,
|
@mwouts this is 😍😍😍😍! Thank you! I’m sorry that I haven’t had a chance to look at all the details, but at a first glance it just looks gorgeous! I’m happy to give the rest of the to-do items a whirl from here now that you’ve done the hard work! ;) |
Beautiful! Really cool @mwouts :-) A few things:
These could both be semi-automated with something like: import jupytext as jpt
from glob import glob
path_files = glob('./content/ch*.md')
for ipath in path_files:
ntbk = jpt.read(ipath)
for cell in ntbk.cells:
# Replace the callout cell with a popout tag
if '{.callout}' in cell.source:
cell.metadata.get('tags', []).append("popout")
cell.source = cell.source.replace('{.callout}', '')
# If we find what looks like a quotation syntax in the cell, make it an epigraph
if "> —" in cell.source:
if 'epigraph' not in cell.metadata.get('tags', []):
cell.metadata.get('tags', []).append('epigraph')
jpt.write(ntbk, ipath) Although it'll probably miss a few things because there aren't explicit What else is missing?! Let's make a wish-list! |
Software carpentry and I think O'Reilly both use callout. Who are in the other camp? =) I'm worried that some of our callouts might be too big to fit nicely in a sidebar...
I think that's all of them? But, yes! =)
This one is kinda huge but it would be super-amazing if the functionality from @stefanv's exercise exciser was built into Jupyter Book. To summarise: exercise solutions need to be executed in the context of the original chapter because it uses a bunch of variables defined in the main text. However, we would like to copy the exercises and move the solutions to a new chapter at the end, after they've been executed, so that looking at the solution is "hard". Currently these are marked as Also, can Jupyter Book do figure captions? If so, how? Again, for us, @stefanv rolled his own solution based on HTML comments, with possibly my favourite name for a script ever, |
@jni 👋 👋
Ummmm...maybe just me? :-) That said, I wonder if "sidebar" and "callout" are two separate things. One is more like "I want to highlight this information" and the other is more "I want to highlight this information but in a way that it doesn't break the flow of the main text". Maybe "callout" and "sidebar" are two separate things?
Mmmm, the way I'd do this is probably similar to how you did it. We might be able to build in some (probably hacky) ways to improve the experience with this (e.g., maybe a
Right now, no, but if we supported some extra cell metadata it'd be easy. Currently jupyter-book tries to only use tags for triggering certain behavior. You could imagine having some slightly more complex cell metadata (e.g. a "caption: 'mycaption'" key/value would assume that the cell outputs a PNG, and add the 'mycaption' as a div underneath it). This is the kinda stuff I'd want to run by folks in the community to figure out the right pattern etc, so this feedback is helpful! |
Well, thank you yourself for sharing the beautiful book! And @choldgraf and the Jupyter Book team have done the hard work - As for myself I've not done much, I was just curious to see how these two wonderful projects could fit together!
Great idea! What I am looking for is the following:
More generally, I think we could have a look at the Elegant Scipy Makefile and integrate into the Jupyter Book project the items that are generic enough.
Aren't captions supported by Jupyter? I think it's a natural request and I'd love to see this in Jupyter Notebook/Lab/nbconvert. I don't find much material about that, yet the Making publication ready Python Notebooks post by Julius Schulz suggest that one can use the following cell metadata:
And I see that the same metadata is also used by ipypublish.
Interesting! Maybe I can suggest another approach here: why not moving the exercises to a separate notebook, that would source the corresponding chapter before executing the exercises? I mean, maybe we could do something like this
and then continue with the exercises? |
Unfortunately, in some cases, the solution to the exercise is required for the rest of the notebook to execute. Perhaps this is a bad practice, but it's there now...
Well, this is not standard in any way currently, as far as I know, but I agree that following prior art is a very good idea. I liked that post back in the day and thought, brilliant, surely this will be stock standard jupyter very soon... 😅 How does one define generic cell metadata in jupytext? |
Oh I see this is not documented, sorry. I'll make sure the documentation includes that in the near future... Anyway:
|
I like the idea of using ipypublish as inspiration here - I'll take a deeper dive into their API and syntax! |
I'd like to see how we can use Jupyter Book to render Elegant Scipy.
That would be a nice example for mwouts/jupytext#247.
@choldgraf , do you think we could write together a short bash notebook that demoes this? I started drafting one for a Bookdown repo, but maybe this example will be simpler?
Also, we may need here an additional option to allow the execution of Python cells in Markdown documents, even if they don't have the Jupytext header.
The text was updated successfully, but these errors were encountered: