0

I want to achieve something like this:

#+latex_header: \input{${PUT_SOME_ELISP_VALUE_HERE}night_beamer_common1.tex}

1 Answer 1

1

You can do it with a macro:

#+MACRO: foo (eval (concat "#+latex_header: \\input{" my-var "/night-beamer-common1.tex}"))

{{{foo}}}

* Intro

This is a test.

AFAICT, macros are not expanded in the value position of an option header, so you cannot say:

#+MACRO: foo (eval (concat "\\input{" my-var "/night_beamer_common1.tex}"))

#+LATEX_HEADER: {{{foo}}}

You can define the variable with #+BIND in the Org mode file itself or use a global value:

#+BIND: my-var "/foo/bar/baz"

...

If you decide to use #BIND, remember to enable it by customizing org-export-allow-bind-keywords or setting it to t in your init file.

You cannot use a file-local variable however. This does not work:

#+MACRO: foo (eval (concat "#+latex_header: \\input{" my-var "/night-beamer-common1.tex}"))

{{{foo}}}

* Intro

This is a test.

* COMMENT Local variables

# Local variables:
# my-var: "/foo/bar/baz"
# End:

I suspect it has something to do with lexical scoping - I get this backtrace:

Debugger entered--Lisp error: (void-variable my-var)
  (concat "#+latex_header: \\input{" my-var "/night-beamer-common1.tex}")
  (closure (t) (&rest _) (concat "#+latex_header: \\input{" my-var "/night-beamer-common1.tex}"))()
  apply((closure (t) (&rest _) (concat "#+latex_header: \\input{" my-var "/night-beamer-common1.tex}")) nil)
  (if (functionp template) (apply template (org-element--property :args macro nil nil)) (replace-regexp-in-string "\\$[0-9]+" #'(lambda (m) (or (nth (1- (string-to-number ...)) (org-element--property :args macro nil nil)) "")) template nil 'literal))
  (let* ((value (if (functionp template) (apply template (org-element--property :args macro nil nil)) (replace-regexp-in-string "\\$[0-9]+" #'(lambda (m) (or ... "")) template nil 'literal)))) (format "%s" (or value "")))
  (progn (let* ((value (if (functionp template) (apply template (org-element--property :args macro nil nil)) (replace-regexp-in-string "\\$[0-9]+" #'(lambda ... ...) template nil 'literal)))) (format "%s" (or value ""))))
  (if template (progn (let* ((value (if (functionp template) (apply template (org-element--property :args macro nil nil)) (replace-regexp-in-string "\\$[0-9]+" #'... template nil 'literal)))) (format "%s" (or value "")))))
  (let ((template (cdr (assoc-string (org-element--property :key macro nil nil) templates t)))) (if template (progn (let* ((value (if (functionp template) (apply template ...) (replace-regexp-in-string "\\$[0-9]+" ... template nil ...)))) (format "%s" (or value ""))))))
  org-macro-expand((macro (:standard-properties [94 103 nil nil 0 nil nil nil nil nil nil nil nil nil nil nil nil #<buffer foo.org<2>>] :key "foo" :value "{{{foo}}}" :args nil)) (("date" . "") ("title" . "") ("email" . "") ("author" . "") ("foo" closure (t) (&rest _) (concat "#+latex_header: \\input{" my-var "/night-beamer-common1.tex}")) ("input-file" . "foo.org") ("modification-time" closure ((modtime 25838 660 285864 51000) (visited-file . "/tmp/foo.org")) (arg1 &optional arg2 &rest _) (format-time-string arg1 (or (and (org-string-nw-p arg2) (org-macro--vc-modified-time visited-file)) modtime))) ("keyword" lambda (arg1 &rest _) (org-macro--find-keyword-value arg1 t)) ("n" lambda (&optional arg1 arg2 &rest _) (org-macro--counter-increment arg1 arg2)) ("property" lambda (arg1 &optional arg2 &rest _) (org-macro--get-property arg1 arg2)) ("time" lambda (arg1 &rest _) (format-time-string arg1))))
...

but I have not dug any further.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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