sagemathinc / cocalc

CoCalc: Collaborative Calculation in the Cloud
https://CoCalc.com
Other
1.17k stars 216 forks source link

Drawing figures in a Markdown file. (Embedded whiteboard?) #6997

Open mforbes opened 1 year ago

mforbes commented 1 year ago

It would be really nice if some sort of whiteboard could be embedded in markdown files so that one can easily insert sketches as figures. These should probably have some sort of size limitations so they do not get out of hand (i.e. they should convert to embeddable single-page PDF figures when converting to LaTeX and to SVG when converted to HTML).

It seems to me this might be almost trivial to implement, similarly to the way code cells now work.

Not sure of the ideal syntax yet, but perhaps something like a figure environment so that one can also add captions, make it a margin figure etc. (thinking ahead to writing JupyterBooks).

:::{figure} fig-1.*

Here is my figure caption!
:::

The following also work with JupyterBook: i.e. just apply a wildcard to the file name.

![Figure](qt4_editor_options.*)
<img src="qt4_editor_options.*"/>

Unfortunately, Jupyter Notebooks do not recognize the wildcard.

Perhaps the behaviour could be that, if fig-1.board exists, then it is used (with an editable view on CoCalc), but upon save, the contents are output into fig-1.svg, fig-1.pdf, etc. when the file is saved so that the markdown file can be used off of CoCalc. (Not sure the best place to store which formats should be saved, but probably in the .board file.)

williamstein commented 1 year ago

This is a really good idea. A neat side effect is that it would also automatically work in Jupyter notebooks.

It would likely take at least a week of full time work though (min), since the whiteboard code released to sketching would need to get refactored and made reusable. So probably not at all trivial in terms of code. But the design is very natural.

On Sat, Oct 21, 2023 at 8:04 PM Michael McNeil Forbes < @.***> wrote:

It would be really nice if some sort of whiteboard could be embedded in markdown files so that one can easily insert sketches as figures. These should probably have some sort of size limitations so they do not get out of hand (i.e. they should convert to embeddable single-page PDF figures when converting to LaTeX and to SVG when converted to HTML).

It seems to me this might be almost trivial to implement, similarly to the way code cells now work.

Not sure of the ideal syntax yet, but perhaps something like a figure https://jupyterbook.org/en/stable/content/figures.html?highlight=figure%5C#figures environment so that one can also add captions, make it a margin figure etc. (thinking ahead to writing JupyterBooks).

:::{figure} fig-1.*

Here is my figure caption! :::

Perhaps the behaviour could be that, if fig-1.board exists, then it is used (with an editable view on CoCalc), but upon save, the contents are output into fig-1.svg, fig-1.pdf, etc. when the file is saved so that the markdown file can be used off of CoCalc. (Not sure the best place to store which formats should be saved, but probably in the .board file.)

— Reply to this email directly, view it on GitHub https://github.com/sagemathinc/cocalc/issues/6997, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJXS5UTR3F73QF64CYMNOLYASENHAVCNFSM6AAAAAA6KSRCOWVHI2DSMVQWIX3LMV43ASLTON2WKOZRHE2TKNZTHA4TGNY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

mforbes commented 1 year ago

I just found out about [Joplin](), which has rudimentary functionality via a js-draw plugin. The approach they take there is just use it as an editor for svg files, but I like the idea of being able to generate multiple file formats which is constantly an issue.

I will updated the input suggestions above: they all currently work with JupyterBook, so until you get around to supporting the MyST extensions like :::{figure}, the others can be used.

Update: unfortunately, it seems like vanilla Jupyter notebooks do not support wildcards for images. I added this feature request: https://github.com/jupyter/notebook/issues/7122. Of course, it should be easy for the CoCalc interface to work.