executablebooks / sphinx-exercise

A Sphinx extension for producing exercise and solution directives.

Home Page:https://ebp-sphinx-exercise.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make it possible to duplicate exercises and/or solutions

choldgraf opened this issue · comments

I believe that @jni mentioned it is common for them to have exercises in individual chapters and additionally at the end of a book. I think that's a pretty common pattern across fields. It would be nice if authors could write one exercise / solution and then be able to display both elsewhere without creating new labels etc.

I wonder if we could just add this as a keyword to the directives, something like:

```{exercise}
:copy: somelabel
```

and it would look for an exercise node of label somelabel and, if so, copy / paste it into the new location (perhaps with a link that points to the original)

This is easily doable - but the user would have to keep track of all the exercise labels and would have to create a new directive for every exercise they want to copy in the new location. Would it make more sense to simply include all?

hmmm - I could see either one being useful, though am not sure what the most-common approach would be. Perhaps @jni has thoughts as I think the elegant SciPy book does this

I'm in the copy-all-directive camp, and agree with @najuzilu that it would be painful to have to keep track of each label. (Totally not my forte in any case. 😂) In Elegant SciPy we copy everything. Specifically:

  • the exercises and solutions are both run in their context notebook. The are marked by nested tags essentially as: <exercise> EX <solution> SOL </solution> </exercise>.
  • then we grab the stuff between the <exercise> tags and copy it to the appendix.
  • then we remove the stuff between the <solution> tags from the source chapters.

sounds good - then maybe we start with a single "copy all" directive, and if folks ask for single-exercise directives in the future, we can consider adding them then?

I would envision this looking something like

```{copy-exercises}
:include-solutions:
```

We can also introduce a copy-solutions directive which will only copy the solutions.

that seems pretty reasonable to me! What does @jni @jstac @mmcky think?

Personally I think it should be only

```{copy-solutions}
:include-exercises:
```

I see clear use case for copying only solutions, or solutions + exercises, but not so much for copying the exercises only. Right?

Good point @jni ,I think copying all solutions will be more common but I could be wrong! What does quantecon do @jstac ?

We don't have a consistent approach yet. I like the system that @jni is suggesting. It would be great to have this available.