best practice for writing non-executable code in other (non-Python) languages?

260 views
Skip to first unread message

Denis Akhiyarov

unread,
Oct 30, 2017, 2:38:51 PM10/30/17
to Project Jupyter
What is best practice for writing non-executable code in other (non-Python) languages with Jupyter Notebooks?

For example when I use `%%writefile` magic to write Fortran code to external file in IPython kernel, then code cell appears to have "broken" syntax highlighting (assumed to be Python?).

But if I convert the code cell to markdown cell and configure Fortran code inside with "```Fortran```" block, then there is no easy to export this to external file like with the first option.

Has anyone resolved this one way or the other or maybe with completely different approach?

I cannot use f2py and fortran-magic because the Fortran code is compiled into external executable/process.

Denis Akhiyarov

unread,
Oct 31, 2017, 4:59:55 PM10/31/17
to Project Jupyter
Is it possible to extract the content of previous markdown cell in the next code cell?

Robert Schroll

unread,
Oct 31, 2017, 5:28:40 PM10/31/17
to jup...@googlegroups.com, Project Jupyter
On Oct 30 2017, at 11:38 am, Denis Akhiyarov <denis.a...@gmail.com> wrote: 
What is best practice for writing non-executable code in other (non-Python) languages with Jupyter Notebooks?

For example when I use `%%writefile` magic to write Fortran code to external file in IPython kernel, then code cell appears to have "broken" syntax highlighting (assumed to be Python?).

But if I convert the code cell to markdown cell and configure Fortran code inside with "```Fortran```" block, then there is no easy to export this to external file like with the first option.

Has anyone resolved this one way or the other or maybe with completely different approach?

It's relatively easy to write your own cell magics, and you can use a bit of javascript to apply whatever highlighting mode you want to that cell.  We used this method in ihtml to make html, css, and js cells in an IPython notebook with the appropriate highlighting: https://github.com/thedataincubator/ihtml

I won't claim this is the best solution, but it does seem to work.

Robert

Reply all
Reply to author
Forward
0 new messages