0

In my init file, all the paths that I use are stored at the beginning of the file with a series of lines like this:

(setq personal-path "PATH")

Then I can use them like this:

(set-register ?s (cons 'file (concat personal-path  "somefile.org")))

Now I'm trying to use these variables with #+INCLUDE:, but it's not working.

When I do

#+INCLUDE: (concat personal-path "somefile.org::sometable")

The HTML export fails.

8
  • That's not particularly surprising: #+INCLUDE takes a path as its first parameter, not an s-expression. There are a few places where Org mode allows s-expressions and it evaluates them in certain contexts (e.g. that used to be the case certain places in capture templates, when you did a capture; although that particular facility does not exist any longer, a similar facility when defining variables in a source block header is still present and is triggered when you evaluate the source block). There is no such facility for the first parameter of #+INCLUDE, so you cannot do what you want ...
    – NickD
    Jul 25 at 3:11
  • ... not, in any case, in any straightforward way. I think the best you can do is preprocess the buffer to evaluate the s-exprsessions and replace them with the result strings. You might be able to use the org-export-before-parsing-hook for that: see Advanced Export Configuration in the Org mode manual for some information, although it's not going to be trivial.
    – NickD
    Jul 25 at 3:16
  • So I cannot put Elisp variables... But as far as I understand it Org-Mode also has its own variables. For example, for links, there is abbreviated org-link. However, they only seem to work within links.
    – crocefisso
    Jul 25 at 8:16
  • Isn't there a type of variable, even org specific, whatever it is, that I can set in the init and use within #+INCLUDE:?
    – crocefisso
    Jul 25 at 8:37
  • Not that I know of. I wondered if you could use macros but macros are expanded after the #+INCLUDEs are processed.
    – NickD
    Jul 25 at 12:31

1 Answer 1

1

It doesn't seem possible to use variables with #+INCLUDE:.

However, org-transclusion, which is a package that lets you insert a copy of some content via a file link or ID link within an Org file, can read link abbreviations.

So if you install org-transclusion, you can add this line in your init :

(setq org-link-abbrev-alist (list (cons "personal-org-path" personal-path)))

And then write the following line in your org file

#+transclude:: [[personal-org-path:somefile.org::sometable]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.