Emacs org-mode: defining a variable in a buffer and an access variable

I would like to define a buffer width variable in an org file and use the value from this variable later, for example, determine the width of images for exporting latex.

Is there any way this can be done?

Can this be done using #+CONSTANTS: :?

Ideally, it should work as follows:

I define an image_width variable in a buffer, e.g.

 image_width=10 

and use this variable for the parameters #+ATTR_LATEX: for example, #+ATTR_LATEX: :width $image_width .

+6
source share
3 answers

Two ways (untested) if you want your constant to be buffer specific:

  • The "local variable (s)" in the last 8 lines (or so) of your Org file;

  • Use the function Org "# + MACRO:"

+2
source

Define a variable in your .emacs. Just as you define a function, you can bind a variable to a specific value. You can do setq or defvar, defconst, depending on what you want. For example:

(setq image-width 10)

Verify the eval buffer after setting the variable.

0
source

You can declare a variable using the tag #+NAME: Then use it by passing it to :var in the src block you need.

It will look something like this:

 #+NAME: instance-id | abcd | #+BEGIN_SRC sh :var id=instance-id echo $id #+END_SRC #+RESULTS: : abcd #+BEGIN_SRC python :var myvar=instance-id[0, 0] print myvar #+END_SRC #+RESULTS: : abcd 

Notice the instance-id[0, 0] in the python src block. I declared the variable as an array, because of which I need to remove the reference to a value like this.

0
source

Source: https://habr.com/ru/post/952590/


All Articles