Ask Your Question
1

export notebook output to html

asked 2016-11-15 10:41:16 -0500

louisgag gravatar image

I've spent some hours looking for and trying out many different methods to achieve this, but it seems there is no simple way to get the whole output from an evaluated to html. Should I create a feature request ?

Here is what I've tried:

  • make one single pretty_print command and then using the MathML interface extract the code: works but it is impossible to do line breaks (they appear only as vertical displacements and the text then continues from the same horizontal position), and anyway it is not always easy to have all the output in one pretty_print statement
  • print to Latex: the code generated requires some fine tuning and then I would have to convert it to html anyway
  • copy the page source from the sagemath output: there is just too much clutter coming with it and the code obtained is not really MathML
  • put the %html comment at the beggining of the cell
  • etc.

So in the end I used the simple technique of copying and pasting individually each output from my cell's print commands into my html document and inserting the MathML from each pretty_print box's context menu one by one...

Is there a simpler way to generate a block of html from the entire content of an evaluated sagemath cell ?

If it can help I can post my Sagemath worksheet. Thanks and Regards, -Louis

edit retag flag offensive close merge delete

Comments

Which kind of worksheet - is this sagenb or SageMath Cloud? Sagenb worksheets are html.

kcrisman gravatar imagekcrisman ( 2016-11-15 12:35:17 -0500 )edit

@louisgag, yes, please give a link to your worksheet

slelievre gravatar imageslelievre ( 2016-11-15 13:37:13 -0500 )edit

its a sage worksheet by running http://localhost:8080/home/admin/, I know it is html, but as I mention in the question the equations do not appear in clear format at all (there are a bunch of calls in the header that refer to local scripts). Here is the worksheet: http://louisgagnon.com/transf/airfoilCenterOfMassClean.sws (http://louisgagnon.com/transf/airfoil...) and here is what I have done to export it manually: http://louisgagnon.com/scBlog/airfoilCenter.html (http://louisgagnon.com/scBlog/airfoil...)

louisgag gravatar imagelouisgag ( 2016-11-16 09:29:07 -0500 )edit

@slelievre i've put the worksheet link in the comment above, thanks

louisgag gravatar imagelouisgag ( 2016-11-18 02:29:47 -0500 )edit

I see what you mean now. I'll put something in.

kcrisman gravatar imagekcrisman ( 2016-11-18 08:28:36 -0500 )edit

3 answers

Sort by ยป oldest newest most voted
0

answered 2016-11-15 14:55:48 -0500

The best workflow for you might be to write your source in reStructuredText format and use rst-to-ipynb.

See https://github.com/nthiery/rst-to-ipynb.

edit flag offensive delete link more
2

answered 2016-11-18 08:30:37 -0500

kcrisman gravatar image

One possibility is to use sws2rst to make a page out of it. The page should work properly as long as you are connected to the internet for things like MathJax scripts.

edit flag offensive delete link more

Comments

@kcrisman thanks for your answer. It still doesn't quite do what I want. I've installed BeautifulSoup (not 4 because my version of --sws2rst did not recognize it) and did the whole procedure outlined in the tutorial, and tried it on different worksheets and with different rendering commands: print(), show(), pretty_print(), and view() but in all cases the equations don't appear in the final html document (nor in the rst doc). I get the commands rendered and the output rather shows each equation as: <html>...</html> Am I missing something? Thanks, -Louis

louisgag gravatar imagelouisgag ( 2016-11-30 03:04:52 -0500 )edit

Ah, I wouldn't use any of those - just the regular output should render. I was talking about using the text cells (TinyMCE) and having math in there. Yeah, sws2rst may not have had that use case in mind (using print or show), I am not sure. I don't know if I remember testing any like that.

kcrisman gravatar imagekcrisman ( 2016-11-30 10:08:45 -0500 )edit

That's also too bad about beautifulsoup 4. Aargh.

kcrisman gravatar imagekcrisman ( 2016-11-30 10:08:59 -0500 )edit
1

answered 2016-12-01 03:37:05 -0500

louisgag gravatar image

Thanks to both of you for your answers. I think however that what gets me as close as possible to what I want is the following:

  • Get the html directly from the source of the notebook output in the browser
    • find the output you are interested in, you can locate it by searching for the <script type="math/tex" portions
  • Paste it in your target html file
  • And link the MathJax script in your target html file by either

    • a) adding the following to your html file (ideally in the header): <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script>
    • b) getting the MathJax library and linking the local version of the script

More info on MathJax and the local/online versions can be found here: http://docs.mathjax.org/en/latest/ins... and here: http://docs.mathjax.org/en/latest/sta...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-11-15 10:41:16 -0500

Seen: 168 times

Last updated: Dec 01 '16