marimo icon indicating copy to clipboard operation
marimo copied to clipboard

pdf output with code

Open ggggggggg opened this issue 1 year ago • 5 comments

Description

I am hoping to be able to make pdf output with code, while using mo.mpl.interactive to display plots. Currently when I use the menu to do pdf output, it tells me to press Crtil+. to switch to app mode before making the pdf output. All my plots output fine, but the code is hidden.

Suggested solution

I can think of 2

  1. allow pdf output from notebook mode (I know there were correctness issues, so those would need to be fixed).
  2. allow app mode to show code, just not editable. (Is this already possible?)

Alternative

No response

Additional context

My use case is that I want a hard copy of "I did this analysis this way and got this result" that is immutable. I prefer pdf to html, as some features don't work in html output. Eg the "dataframe viewer" doesn't seem to work in html output since it no longer has access to the dataframe. I just want a copy of what was on the screen (and would have been if I scrolled) when I said to export a copy, and pdf seems best matched to that.

ggggggggg avatar Jan 13 '25 22:01 ggggggggg

The current PDF output button in marimo programmatically calls print (Cmd+P). You could try that in the edit view.

Allow app mode to show code, just not editable

This is possible with marimo run nb.py --include-code

mscolnick avatar Jan 14 '25 01:01 mscolnick

Thank you for the feedback! I did some more experimenting with pdf output, and tried some of your comments. This will be a bit of a grab bag of feedback. This is all on windows.

  1. marimo run nb.py --include-code Solution rating 6/10. brings up app view, and the code is not visible. There is a gui element in the top right that allows the code to be shown. But then there is no option to save as pdf, only as html and png.
  • Preferred usage: I switch to app mode without re-running the notebook from command line, have a gui element that allows showing code, and pdf output.
  • It's also confusing that "app mode" is different depending on how you get to it, though I do understand why you may disable switching back to edit mode when launched with marimo run.
  1. Try print directly through browser from edit mode. Solution rating 6/10. The margins are different, so text blocks that easily fit on screen and clipped. I tried charging the margins and didn't find a good setting that produced nice output.

Image

Marimo Env Output On windows. marimo env { "marimo": "0.10.12", "OS": "Windows", "OS Version": "10", "Processor": "Intel64 Family 6 Model 85 Stepping 4, GenuineIntel", "Python Version": "3.10.11", "Binaries": { "Browser": "131.0.6778.265", "Node": "--" }, "Dependencies": { "click": "8.1.7", "docutils": "0.20.1", "itsdangerous": "2.2.0", "jedi": "0.19.0", "markdown": "3.6", "narwhals": "1.22.0", "packaging": "23.1", "psutil": "5.9.5", "pygments": "2.16.1", "pymdown-extensions": "10.8.1", "pyyaml": "6.0.1", "ruff": "0.5.5", "starlette": "0.37.2", "tomlkit": "0.12.5", "typing-extensions": "4.7.1", "uvicorn": "0.30.1", "websockets": "12.0" }, "Optional Dependencies": { "altair": "5.3.0", "pandas": "2.1.0", "polars": "1.19.0", "pyarrow": "16.1.0" } }

ggggggggg avatar Jan 14 '25 20:01 ggggggggg

Based on these tests would one of the following solutions be well aligned with other Marimo priorities?

  1. When in "app view", reached by using Ctrl+. to switch to from "edit view" add a method to Show Code.
  2. When in "edit view" allow pdf output with margins such that a typical marimo cell fits on a page.

ggggggggg avatar Jan 15 '25 19:01 ggggggggg

  1. When in "edit view" allow pdf output with margins such that a typical marimo cell fits on a page.

This sounds better to me. We have some existing CSS to handle @media print {, which we can improve so Cmd+p (print) works better out of the box

mscolnick avatar Jan 15 '25 19:01 mscolnick

I like that idea, I'm hoping it comes online soon so I can let my colleagues print out copies of their finished notebooks. Thanks.

ggggggggg avatar Jan 15 '25 23:01 ggggggggg