jkitchin / ox-ipynb

org-mode exporter to Jupyter notebooks
170 stars 39 forks source link

conditional export? #46

Closed uliw closed 1 year ago

uliw commented 1 year ago

This harks back to and earlier question and based on https://github.com/jkitchin/scimax/issues/305 is likely not possible. Still, I recently started using notebooks in a class where it would be useful to have a version that the students get to see and version that the TA gets to see (i.e., with solutions and or comments wrt marking).

Drawers come to mind, but conditional drawer inclusion is not supported in the ox-ipynb. I wonder, however whether the is another way (short of using, e.g., a python script) to exclude some content?

jkitchin commented 1 year ago

Have you tried this: https://github.com/jkitchin/ox-ipynb/blob/master/ox-ipynb.el#L58?

uliw commented 1 year ago

Just did. That is pretty nifty. The Begin Solution/End Solution allso works in the running text (which was my default scenario), but I don't see how to make this play nice with the org to pdf export. Anyway, I can print the notebook to PDF, so no problem.

Using #+attr_ipynb: :remove t on top of an ipython block resulted in an error though.

thx!

jkitchin commented 1 year ago

I think I pushed a fix above for the ipynb attr issue.

To get a pdf you can do this. maybe I should add an optional argument to those processors so you can use them directly, but this is pretty easy too.

+BEGIN_SRC emacs-lisp

(let ((org-export-before-processing-hook '((lambda (_) (cl-loop for func in '(ox-ipynb-remove-hidden ox-ipynb-remove-solution ox-ipynb-remove-remove) do (funcall func)))))) (org-open-file (org-latex-export-to-pdf)))

+END_SRC

uliw commented 1 year ago

works like a charm. thx!