xarray-tutorial icon indicating copy to clipboard operation
xarray-tutorial copied to clipboard

Consistent format for Exercise Q&A

Open dcherian opened this issue 3 years ago • 9 comments

Is there a nice way to have a hidden "answer" cell for our exercises?

dcherian avatar Jun 21 '22 16:06 dcherian

@dcherian I actually played around with this last week and accidentally opened the PR on my fork! https://github.com/scottyhq/xarray-tutorial/pull/5

But, I think the most straightforward solution is to have a separate header markdown cell (### Soluton X) and use the 'hide-output' metadata tag on the solution cell to have a toggle button on the rendered website.

EDIT: also in jupyterlab 'hide' the cell so that a user running jupyterlab sees ellipses rather than the answer. of course if someone does 'run all cells' it will show up, but at least there is a little bit of extra work to reveal the answer for people working cell-by-cell.

scottyhq avatar Jun 21 '22 16:06 scottyhq

Nice. The rendering in Jupyterlab is unfortunate. But it is a major "mode of consumption" for this material. So perhaps we go with something that renders well in Jupyterlab.

dcherian avatar Jun 21 '22 17:06 dcherian

I think we should bumpy to jupyterlab-myst 2.0 and use the exercise directive across all tutorials as documented here https://mystmd.org/guide/exercises#hiding-directive-content !

scottyhq avatar Jun 26 '23 23:06 scottyhq

I think the CSS could be improved a bit but maybe good enough for now?

image

dcherian avatar Jun 27 '23 02:06 dcherian

This is how it looks if I use the "tip" syntax

```{tip} Exercise
```
```{tip} Solution
:class: dropdown
```
image

dcherian avatar Jun 27 '23 02:06 dcherian

OTOH I guess we can use the new syntax and gain fewer edits in the future...

Will need to install sphinx-exercise too : https://ebp-sphinx-exercise.readthedocs.io/en/latest/

dcherian avatar Jun 27 '23 02:06 dcherian

This is how it looks if I use the "tip" syntax

In the notebook, I really like that appearance, but unfortunately the jupyterbook rendering is inconsistent:

Screenshot 2023-06-26 at 8 47 38 PM

https://xarray-contrib-xarray-tutorial-preview-pr-180.surge.sh/advanced/apply_ufunc/simple_dask_apply_ufunc.html#dimensions-that-change-size

scottyhq avatar Jun 27 '23 03:06 scottyhq

Just wanted to note that jupyterlab-myst 2.0 is nicely solving the problem of a consistent appearance of notebooks in jupyterlab and as rendered by jupyter book.

But sharing the notebook via other commonly used rendering services (github, https://nbviewer.org, https://notebooksharing.space) or IDEs (VSCode) won't style things correctly. But I think it's fine to have this repository focus on jupyterlab+jupyterbook!

scottyhq avatar Jun 27 '23 05:06 scottyhq

Actually i have jupyterlab < 4, so the rendering might just be because we need jupyterlab > 4. The rendered version on the web is quite nice!

image

dcherian avatar Jun 27 '23 16:06 dcherian

closed by #270

scottyhq avatar Jun 24 '24 23:06 scottyhq