Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can this be used with org-mode src-code blocks #43

Open
uliw opened this issue Feb 12, 2023 · 7 comments
Open

can this be used with org-mode src-code blocks #43

uliw opened this issue Feb 12, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@uliw
Copy link

uliw commented Feb 12, 2023

Would it be difficult to enable org-mode src-code block support similar to plantuml?

@andorsk
Copy link
Owner

andorsk commented Feb 12, 2023

I don't think it would be that difficult. https://github.com/arnm/ob-mermaid/blob/master/ob-mermaid.el is an example of this working. We can put it on the feature map.

@andorsk andorsk self-assigned this Feb 12, 2023
@andorsk andorsk added the enhancement New feature or request label Feb 12, 2023
@uliw
Copy link
Author

uliw commented Feb 12, 2023

Happy to help testing

@andorsk
Copy link
Owner

andorsk commented Feb 12, 2023

@uliw it actually might be already supported 😆

image

Can you check if this works for you and is sufficient for your use case?

@uliw
Copy link
Author

uliw commented Feb 12, 2023

it mostly works! I get the following error:

/bin/bash: line 1: ~/.local/bin/d2: No such file or directory

even so

$ ls -al  ~/.local/bin/d2
-rwxr-xr-x 1 user user 38493010 Jan 11 14:14 /home/uliw/.local/bin/d2

shows that the file is there (and calling it directly is working ok).

Setting d2 location explicitly resolved the issue.

Some practicalities:

  • depending on the input file, the png can be rather large, which completely bogs down the org buffer (probably a bug in org). Org-mode allows to set a rendering size via #+attr_org: width: 300. Is there a way to add this line in front of the image?
  • Is there a way to specify the layout engine in the src block arguments?

@uliw
Copy link
Author

uliw commented Feb 12, 2023

The image size problem can be circumvented by setting this in the startup file

(setq org-image-actual-width (list 550))

Which will apply the above value unless another value is set for given image

@andorsk
Copy link
Owner

andorsk commented Feb 12, 2023

Hey @uliw , thanks1 re: the

it mostly works! I get the following error:

/bin/bash: line 1: ~/.local/bin/d2: No such file or directory

even so

$ ls -al  ~/.local/bin/d2
-rwxr-xr-x 1 user user 38493010 Jan 11 14:14 /home/uliw/.local/bin/d2

shows that the file is there (and calling it directly is working ok).

Setting d2 location explicitly resolved the issue.

Some practicalities:

  • depending on the input file, the png can be rather large, which completely bogs down the org buffer (probably a bug in org). Org-mode allows to set a rendering size via #+attr_org: width: 300. Is there a way to add this line in front of the image?
  • Is there a way to specify the layout engine in the src block arguments?

yea...hmm...maybe the "~" is not resolving correctly?

Re: the width, yea...there are options we can add. I need to check the d2 apis to see if there is a way to do it via the cli. If so, we can add another arg, :width which would resolve that.

@paskn
Copy link

paskn commented Apr 30, 2023

Hi!
There's https://github.com/xcapaldi/ob-d2 that helps rendering d2 in org-mode.

Here's a hack I use to control size of an image while exporting to LaTeX that might help you automate #+attr_org:

Put this somewhere at the beginning of the file:

#+NAME: attr_wrap
#+BEGIN_SRC sh :var data="" :var width="\\textwidth" height="200" :results output :exports none
  echo "#+ATTR_LATEX: :width $width :height $height"
  echo "$data"
#+END_SRC

Example of usage:

#+BEGIN_SRC d2 :file complex.png :post attr_wrap(width=200, height=500, data=*this*) :results drawer
clouds: {
  aws: {
    load_balancer -> api
    api -> db
  }
  gcloud: {
    auth -> db
  }

  gcloud -> aws
}
#+END_SRC

#+RESULTS:
:results:
#+ATTR_LATEX: :width 200 :height 500
[[file:complex.png]]
:end:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants