[O] new exporter, conditional options according to backend
Is it possible to write something like this with the new exporter? #+OPTIONS: (if (and (boundp 'org-export-current-backend) (eq org-export-current-backend 'e-beamer)) "H:1" "H:3") >From what I read in org-export.el the backend is stored in a plist, not sure how to get it's value when exporting. Or, maybe I need to write a filter function to be run from org-export-before-process-hook? -- Ezequiel Birman
Re: [O] new exporter, conditional options according to backend
Hello, Ezequiel Birman writes: > Is it possible to write something like this with the new exporter? > > #+OPTIONS: (if (and (boundp 'org-export-current-backend) (eq > org-export-current-backend 'e-beamer)) "H:1" "H:3") There is no `org-export-current-backend' in the new exporter. Besides, what you want is the default behaviour (see `org-e-beamer-frame-level' variable). > From what I read in org-export.el the backend is stored in a plist, not > sure how to get it's value when exporting. > > Or, maybe I need to write a filter function to be run from > org-export-before-process-hook? Filters are different from hook. A function in a hook operates on an Org buffer. A filter function operates either on a string in output syntax or on the parse tree. If, for some reason, you want to modify export options "on the fly", you could create a filter function for parse tree, and modify options plist from it: #+begin_src emacs-lisp (defun my-options-change-fun (tree backend info) (when (org-export-derived-backend-p backend 'e-beamer) (plist-put info :with-author nil)) ;; Don't forget to return tree. tree) (add-to-list 'org-export-filter-parse-tree-functions 'my-options-change-fun) #+end_src Regards, -- Nicolas Goaziou
Re: [O] new exporter, conditional options according to backend
> "Nicolas" == Nicolas Goaziou writes: > Hello, Ezequiel Birman writes: >> Is it possible to write something like this with the new >> exporter? >> >> #+OPTIONS: (if (and (boundp 'org-export-current-backend) (eq >> org-export-current-backend 'e-beamer)) "H:1" "H:3") > There is no `org-export-current-backend' in the new > exporter. Besides, what you want is the default behaviour (see > `org-e-beamer-frame-level' variable). >> From what I read in org-export.el the backend is stored in a >> plist, not sure how to get it's value when exporting. >> >> Or, maybe I need to write a filter function to be run from >> org-export-before-process-hook? > Filters are different from hook. A function in a hook operates on > an Org buffer. A filter function operates either on a string in > output syntax or on the parse tree. > If, for some reason, you want to modify export options "on the > fly", you could create a filter function for parse tree, and > modify options plist from it: > #+begin_src emacs-lisp (defun my-options-change-fun (tree backend > info) (when (org-export-derived-backend-p backend 'e-beamer) > (plist-put info :with-author nil)) ;; Don't forget to return tree. > tree) > (add-to-list 'org-export-filter-parse-tree-functions > 'my-options-change-fun) #+end_src > Regards, > -- Nicolas Goaziou Thanks for the example and the clarificatons re filters versus hooks, and for thinking of those sane defaults ahead too. -- Ezequiel Birman
Re: [O] new exporter, conditional options according to backend
Nicolas Goaziou writes: > #+begin_src emacs-lisp > (defun my-options-change-fun (tree backend info) > (when (org-export-derived-backend-p backend 'e-beamer) > (plist-put info :with-author nil)) > ;; Don't forget to return tree. > tree) CAVEAT: plist-put can return a different list, at times. I don't know enough about implementation of `plist-put' to ascertain when it would return a new list. > (add-to-list 'org-export-filter-parse-tree-functions > 'my-options-change-fun) --
Re: [O] new exporter, conditional options according to backend
Jambunathan K writes: > Nicolas Goaziou writes: > >> #+begin_src emacs-lisp >> (defun my-options-change-fun (tree backend info) >> (when (org-export-derived-backend-p backend 'e-beamer) >> (plist-put info :with-author nil)) >> ;; Don't forget to return tree. >> tree) > > CAVEAT: plist-put can return a different list, at times. > > I don't know enough about implementation of `plist-put' to ascertain > when it would return a new list. Since the OP wants to modify the values of _existing properties_ I'm quite sure the change will happen in place. Regards, -- Nicolas Goaziou
Re: [O] new exporter, conditional options according to backend
Nicolas Goaziou writes: > Jambunathan K writes: > >> Nicolas Goaziou writes: >> >>> #+begin_src emacs-lisp >>> (defun my-options-change-fun (tree backend info) >>> (when (org-export-derived-backend-p backend 'e-beamer) >>> (plist-put info :with-author nil)) >>> ;; Don't forget to return tree. >>> tree) >> >> CAVEAT: plist-put can return a different list, at times. >> >> I don't know enough about implementation of `plist-put' to ascertain >> when it would return a new list. > > Since the OP wants to modify the values of _existing properties_ I'm > quite sure the change will happen in place. Look at example in Elisp manual. New members seem to get appended. List being destructive is explainable if new members were to be added to the head. Since this is not the case, I am curious what the implementation could be ... > > > Regards, --
Re: [O] new exporter, conditional options according to backend
Hi Nicolas, Nicolas Goaziou writes: > Hello, > > Ezequiel Birman writes: > >> Is it possible to write something like this with the new exporter? >> >> #+OPTIONS: (if (and (boundp 'org-export-current-backend) (eq >> org-export-current-backend 'e-beamer)) "H:1" "H:3") > > There is no `org-export-current-backend' in the new exporter. Besides, > what you want is the default behaviour (see `org-e-beamer-frame-level' > variable). > >> From what I read in org-export.el the backend is stored in a plist, not >> sure how to get it's value when exporting. >> >> Or, maybe I need to write a filter function to be run from >> org-export-before-process-hook? > > Filters are different from hook. A function in a hook operates on an Org > buffer. A filter function operates either on a string in output syntax > or on the parse tree. > > If, for some reason, you want to modify export options "on the fly", you > could create a filter function for parse tree, and modify options plist > from it: > > #+begin_src emacs-lisp > (defun my-options-change-fun (tree backend info) > (when (org-export-derived-backend-p backend 'e-beamer) > (plist-put info :with-author nil)) > ;; Don't forget to return tree. > tree) > > (add-to-list 'org-export-filter-parse-tree-functions > 'my-options-change-fun) > #+end_src > > > Regards, Sorry for hijacking this thread. But I am also interested in backend specific options. Could you give an example of how to achieve something like this with the new exporter: #+begin_src R :results graphics :file (if (and (boundp 'org-export-current-backend) (eq org-export-current-backend 'e-latex)) "foo.pdf" "foo.png") plot(1:10) #+end_src Thanks in advance, Andreas
Re: [O] new exporter, conditional options according to backend
Hello, Andreas Leha writes: > Sorry for hijacking this thread. But I am also interested in backend > specific options. Could you give an example of how to achieve something > like this with the new exporter: > > #+begin_src R :results graphics :file (if (and (boundp > 'org-export-current-backend) (eq org-export-current-backend 'e-latex)) > "foo.pdf" "foo.png") > plot(1:10) > #+end_src You need to process the buffer being exported before Babel blocks are expanded. You could use `org-export-before-processing-hook' for that. For example, you could define a specific extension for :file values, like "foo.xxx", process the buffer and and replace "xxx" with an appropriate extension according to the current back-end (the argument of the function). Regards, -- Nicolas Goaziou
Re: [O] new exporter, conditional options according to backend
Nicolas Goaziou writes: > Hello, > > Ezequiel Birman writes: > >> Is it possible to write something like this with the new exporter? >> >> #+OPTIONS: (if (and (boundp 'org-export-current-backend) (eq >> org-export-current-backend 'e-beamer)) "H:1" "H:3") > > There is no `org-export-current-backend' in the new exporter. Besides, > what you want is the default behaviour (see `org-e-beamer-frame-level' > variable). 'backend' is in the scope of transcoding functions like inline-src-block. I am currently taking advantage of this, but it is a shortcut rather than a necessity. Is your advice "Don't do that" ? Chuck > >> From what I read in org-export.el the backend is stored in a plist, not >> sure how to get it's value when exporting. >> >> Or, maybe I need to write a filter function to be run from >> org-export-before-process-hook? > > Filters are different from hook. A function in a hook operates on an Org > buffer. A filter function operates either on a string in output syntax > or on the parse tree. > > If, for some reason, you want to modify export options "on the fly", you > could create a filter function for parse tree, and modify options plist > from it: > > #+begin_src emacs-lisp > (defun my-options-change-fun (tree backend info) > (when (org-export-derived-backend-p backend 'e-beamer) > (plist-put info :with-author nil)) > ;; Don't forget to return tree. > tree) > > (add-to-list 'org-export-filter-parse-tree-functions > 'my-options-change-fun) > #+end_src > > > Regards,
Re: [O] new exporter, conditional options according to backend
Hello, cbe...@tajo.ucsd.edu writes: > 'backend' is in the scope of transcoding functions like > inline-src-block. > > I am currently taking advantage of this, but it is a shortcut rather > than a necessity. > > Is your advice "Don't do that" ? I would rather say "Don't do that in public code". There's no guarantee this hack will always work. As you probably know, the clean way to retrieve the back-end symbol from a transcoding function is: (plist-get info :back-end) INFO being the third argument passed to the function. Regards, -- Nicolas Goaziou
Re: [O] new exporter, conditional options according to backend
Hello, Jambunathan K writes: > Nicolas Goaziou writes: > >> Jambunathan K writes: >> >>> Nicolas Goaziou writes: >>> #+begin_src emacs-lisp (defun my-options-change-fun (tree backend info) (when (org-export-derived-backend-p backend 'e-beamer) (plist-put info :with-author nil)) ;; Don't forget to return tree. tree) >>> >>> CAVEAT: plist-put can return a different list, at times. >>> >>> I don't know enough about implementation of `plist-put' to ascertain >>> when it would return a new list. >> >> Since the OP wants to modify the values of _existing properties_ I'm >> quite sure the change will happen in place. > > Look at example in Elisp manual. New members seem to get appended. > > List being destructive is explainable if new members were to be added to > the head. Since this is not the case, I am curious what the > implementation could be ... I have added a filter for export options. The OP may want to use it instead. I guess it will be cleaner that way. Besides, the previous export framework had one too. Regards, -- Nicolas Goaziou